return (value == null) ? null : new Cookie(name, value);
}
}
<<<<<<< HEAD
=======
public void operaAction(String using, String... params) {
exec.action(using, params);
}
public Set getOperaActionList() {
return exec.getActionList();
}
/**
* @deprecated Don't use sleep!
*/
private static void sleep(long timeInMillis) {
try {
Thread.sleep(timeInMillis);
} catch (InterruptedException e) {
// ignore
}
}
public WebElement findElementByTagName(String using) {
if(using.contains(":")) {//has prefix
String[] tagInfo = using.split(":");
return findSingleElement("(function() { var elements = document.getElementsByTagName('" + tagInfo[1] + "'), element = null;" +
"for( var i = 0; i < elements.length; i++ ) {" +
"if( elements[i].prefix == '" + tagInfo[0] + "' ) {" +
"element = elements[i];" +
"}" +
"}" +
"return element; })()", "tag name");
}
return findSingleElement("document.getElementsByTagName('" + using +"')[0];", "tag name");
}
public List findElementsByTagName(String using) {
if(using.contains(":")) {//has prefix
String[] tagInfo = using.split(":");
return findMultipleElements("(function() { var elements = document.getElementsByTagName('" + tagInfo[1] + "'), output = [];" +
"for( var i = 0; i < elements.length; i++ ) {" +
"if( elements[i].prefix == '" + tagInfo[0] + "' ) {" +
"output.push(elements[i]);" +
"}" +
"}" +
"return output; })()", "tag name");
}
return findMultipleElements("document.getElementsByTagName('"+ using + "');\n", "tag name");
}
public WebElement findElementByCssSelector(String using) {
return findSingleElement("document.querySelector('" + using +"');", "selector");
}
public List findElementsByCssSelector(String using) {
return findMultipleElements("document.querySelectorAll('"+ using + "'), returnValue = [], i=0;for(;returnValue[i]=results[i];i++); return returnValue;", "selector");
}
private final List findMultipleElements(String script, String type) {
Integer id = debugger.getObject(script);
if (id == null) {
throw new NoSuchElementException("Cannot find element(s) with " + type);
}
return processElements(id);
}
private final WebElement findSingleElement(String script, String type) {
Integer id = debugger.getObject(script);
if (id != null) {
return new OperaWebElement(this, id);
}
throw new NoSuchElementException("Cannot find element with " + type);
}
/*
public String saveScreenshot(String fileName, int timeout, String... hashes) {
return screenWatcher(fileName, timeout, true, hashes);
}
public ScreenShotReply saveScreenshot(Canvas canvas, long timeout, boolean includeImage, String... hashes) {
* FIXME: This _needs_ be cleaned up. All things related to
* `timeout` should, ideally, be removed and handled elsewhere.
//
// * No reason to wait if we have idle control. Builds without
// * OperaIdle enabled will fail if timeout is 1 or less.
//
if(services.isOperaIdleAvailable()) {
timeout = 1;
} else if (!services.isOperaIdleAvailable() && timeout <= 1) {
timeout = 10;
}
return exec.screenWatcher(canvas, timeout, includeImage, hashes);
}
private String screenWatcher(String fileName, int timeout, boolean saveFile, String... hashes) {
Canvas canvas = new Canvas();
canvas.setX(0);
canvas.setY(0);
String[] dimensions = debugger.executeJavascript("return (window.innerWidth + \",\" + window.innerHeight);").split(",");
canvas.setH(Integer.valueOf(dimensions[1]));
canvas.setW(Integer.valueOf(dimensions[0]));
canvas.setViewPortRelative(true);
ScreenShotReply screenshot = saveScreenshot(canvas, timeout, saveFile, hashes);
if(saveFile && screenshot.getPng() != null) {
FileOutputStream stream;
try {
stream = new FileOutputStream(fileName);
stream.write(screenshot.getPng());
stream.close();
} catch (Exception e) {
throw new WebDriverException("Failed to write file: " + e.getMessage());
}
}
return screenshot.getMd5();
}
*/
public ScreenShotReply saveScreenshot(long timeout, String... hashes)
{
/*
if(services.isOperaIdleAvailable()) {
timeout = 1;
} else if (!services.isOperaIdleAvailable() && timeout <= 1) {
timeout = 10;
}
*/
return operaRunner.saveScreenshot(timeout, hashes);
}
public boolean isOperaIdleAvailable()
{
return services.isOperaIdleAvailable();
}
public Object executeScript(String script, Object... args) {
Object object = debugger.scriptExecutor(script, args);
//we probably have an element OR list
if(object instanceof ScriptResult) {
ScriptResult result = (ScriptResult) object;
Integer objectId = result.getObjectId();
if(objectId == null)
return null;
if(result.getClassName().endsWith("Element"))
return new OperaWebElement(this, objectId);
if(result.getClassName().equals("NodeList"))
return processElements(objectId);
if(result.getClassName().equals("Array") || result.getClassName().equals("Object"))
return debugger.examineScriptResult(objectId);
}
return object;
}
public boolean isJavascriptEnabled() {
// FIXME we always assume it is true
// TODO it should not be possible to register esdbg if js is disabled?
return true;
}
@Deprecated
public void cleanUp() {
services.close();
}
public void executeActions(OperaAction action) {
List actions = action.getActions();
for (UserInteraction userInteraction : actions) {
userInteraction.execute(this);
}
waitForLoadToComplete();
}
/**
* @deprecated This should not be used!
*/
@Deprecated
public boolean isConnected() {
return services.isConnected();
}
public void key(String key) {
keyDown(key);
keyUp(key);
if(key.equalsIgnoreCase("enter")) {
sleep(OperaIntervals.EXEC_SLEEP.getValue());
waitForLoadToComplete();
}
}
public void keyDown(String key) {
exec.key(key, false);
}
public void keyUp(String key) {
exec.key(key, true);
}
public void releaseKeys() {
exec.releaseKeys();
}
public void type(String using) {
exec.type(using);
}
public void mouseEvent(int x, int y, int value) {
exec.mouseAction(x, y, value, 1);
}
public void addConsoleListener(IConsoleListener listener) {
services.addConsoleListener(listener);
}
public void binaryStopped(int code) {
services.onBinaryStopped(code);
}
/**
* Cache of OperaDriver version.
*/
private static String operaDriverVersion = null;
/**
* Gets the OperaDriver version. Once the version number has been
* loaded from an external flat file, it will be cached and returned
* from cache on future calls.
* @return
*
* @return OperaDriver version number as a String
* @throws IOException if the version file cannot be found
*/
public String getOperaDriverVersion() throws IOException {
if (operaDriverVersion == null) {
InputStream stream = OperaDriver.class.getResourceAsStream("/com/opera/core/systems/VERSION");
StringBuilder stringBuilder = new StringBuilder();
Scanner scanner = new Scanner(stream);
try {
while (scanner.hasNext()) {
stringBuilder.append(scanner.nextLine());
}
operaDriverVersion = stringBuilder.toString();
} catch (Exception e) {
throw new FatalException("Could not load the version information:"
+ e.getMessage());
} finally {
scanner.close();
}
}
return operaDriverVersion;
}
protected IEcmaScriptDebugger getScriptDebugger() {
return debugger;
}
protected IOperaExec getExecService() {
return exec;
}
protected IWindowManager getWindowManager() {
return windowManager;
}
protected ScopeServices getScopeServices() {
return services;
}
>>>>>>> 0a9e1e975a02efec859ecdd6230570a0de0d6a85
}
|