List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:com.opera.core.systems.preferences.OperaFilePreferences.java
License:Apache License
/** * Call this to cause the current preferences representation to be written to disk. This method * is called by {@link FilePreference#setValue(Object)} and it is thus not necessary to call this * method separately unless you wish to perform a forced write of the cache to disk. *//*from ww w . ja v a 2s . c om*/ public void write() { try { Wini ini = new Wini(preferenceFile); for (OperaPreference p : this) { ini.put(p.getSection(), p.getKey(), ((AbstractPreference) p).getValue(true)); } ini.store(preferenceFile); } catch (IOException e) { throw new WebDriverException("Unable to write to preference file: " + e.getMessage()); } }
From source file:com.opera.core.systems.preferences.OperaScopePreferences.java
License:Apache License
public void set(OperaPreference preference) { // Update locally stored value if given value is different from cache's. We don't care about // whether the preference passed into this method is a different type, e.g. GenericPreference, // since we have all preferences stored locally. for (OperaPreference p : this) { if (p.getSection().equalsIgnoreCase(preference.getSection()) && p.getKey().equalsIgnoreCase(preference.getKey())) { if (!p.getValue().equals(preference.getValue())) { p.setValue(preference.getValue()); }/* w w w. ja v a 2 s .co m*/ return; } } throw new WebDriverException("Unknown preference: [section: '" + preference.getSection() + "', key: '" + preference.getKey() + "']"); }
From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java
License:Apache License
/** * This method will try to locate the launcher on any system. If the OPERA_LAUNCHER environment * variable is set but invalid, it will throw an exception. If that is not the case, it will * attempt to extract the launcher from the resources of the launcher JAR that is bundled with * OperaDriver./*from w w w.j a v a 2 s . co m*/ * * @return the path to the launcher * @throws org.openqa.selenium.WebDriverException * if launcher is not found */ private static String launcherPath() { String path = System.getenv("OPERA_LAUNCHER"); if (!OperaPaths.isPathValid(path)) { if (path != null && !path.isEmpty()) { throw new OperaRunnerException("Path from OPERA_LAUNCHER does not exist: " + path); } try { String userHome = System.getProperty("user.home"); path = extractLauncher(new File(userHome + File.separator + ".launcher")); } catch (OperaRunnerException e) { throw new WebDriverException("Unable to extract bundled launcher: " + e.getMessage()); } } return path; }
From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java
License:Apache License
/** * Extracts the launcher from the launcher JAR bundled with OperaDriver into the directory * specified. If the launcher in that location is outdated, it will be updated/replaced. * * @param launcherPath directory where you wish to put the launcher * @return path to the launcher executable *///from w w w .j a v a 2 s. c om private static String extractLauncher(File launcherPath) { String launcherName = getLauncherNameForOS(); File targetLauncher = new File(launcherPath.getAbsolutePath() + File.separatorChar + launcherName); // Whether we need to copy a new launcher across, either because it doesn't currently exist, or // because its hash differs from our launcher. boolean copy; // Get the launcher resource from JAR. URL sourceLauncher = OperaLaunchers.class.getClassLoader().getResource("launchers/" + launcherName); // Does launcher exist among our resources? if (sourceLauncher == null) { throw new OperaRunnerException("Unknown file: " + sourceLauncher); } // Copy the launcher if it doesn't exist or if the current launcher on the system doesn't match // the one bundled with OperaDriver (launcher needs to be upgraded). if (targetLauncher.exists()) { try { copy = !Arrays.equals(md5(targetLauncher), md5(sourceLauncher.openStream())); if (copy) { logger.fine("Old launcher detected, upgrading"); } } catch (NoSuchAlgorithmException e) { throw new OperaRunnerException("Algorithm is not available in your environment: " + e); } catch (IOException e) { throw new OperaRunnerException("Unable to open stream or file: " + e); } } else { logger.fine("No launcher found, copying"); copy = true; } if (copy) { InputStream is = null; OutputStream os = null; try { if (!targetLauncher.exists()) { launcherPath.mkdirs(); Files.touch(targetLauncher); } is = sourceLauncher.openStream(); os = new FileOutputStream(targetLauncher); ByteStreams.copy(is, os); targetLauncher.setLastModified(targetLauncher.lastModified()); } catch (IOException e) { throw new WebDriverException("Cannot write file to disk: " + e.getMessage()); } finally { if (is != null) { Closeables.closeQuietly(is); } if (os != null) { Closeables.closeQuietly(os); } } logger.fine("New launcher copied to " + targetLauncher.getAbsolutePath()); } if (copy) { makeLauncherExecutable(targetLauncher); } return targetLauncher.getAbsolutePath(); }
From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java
License:Apache License
/** * Get the launcher's binary file name based on what flavour of operating system and what kind of * architecture the user is using./*from w w w . j a v a 2s. co m*/ * * @return the launcher's binary file name */ protected static String getLauncherNameForOS() { boolean is64 = "64".equals(System.getProperty("sun.arch.data.model")); Platform currentPlatform = Platform.getCurrent(); switch (currentPlatform) { case LINUX: case UNIX: return (is64 ? "launcher-linux-x86_64" : "launcher-linux-i686"); case MAC: return "launcher-mac"; case WINDOWS: case VISTA: case XP: return "launcher-win32-i86pc.exe"; default: throw new WebDriverException( "Could not find a platform that supports bundled launchers, please set it manually"); } }
From source file:com.opera.core.systems.scope.AbstractEcmascriptService.java
License:Apache License
protected Object parseNumber(String value) { Number number;//from www . j av a 2 s . c o m try { number = NumberFormat.getInstance().parse(value); if (number instanceof Long) { return number.longValue(); } else { return number.doubleValue(); } } catch (ParseException e) { throw new WebDriverException("The result from the script can not be parsed"); } }
From source file:com.opera.core.systems.scope.AbstractService.java
License:Apache License
private static final GeneratedMessage.Builder<?> buildMessage(GeneratedMessage.Builder<?> builder, byte[] message) { try {//from w ww . j av a 2s. com return builder.mergeFrom(message); } catch (InvalidProtocolBufferException ex) { throw new WebDriverException( "Could not build " + builder.getDescriptorForType().getFullName() + ": " + ex.getMessage()); } }
From source file:com.opera.core.systems.scope.handlers.PbActionHandler.java
License:Apache License
@Override public void saveScreenshot(File pngFile) { if (pngFile == null) { throw new IllegalArgumentException("Method parameter pngFile must not be null"); }/*from w ww .j a v a 2 s. co m*/ File dir = pngFile.getParentFile(); if (!dir.exists() && !dir.mkdirs()) { throw new WebDriverException("Could not create directory " + dir.getAbsolutePath()); } Canvas canvas = new Canvas(); canvas.setX(0); canvas.setY(0); String[] dimensions = scriptDebugger .executeJavascript("return (window.innerWidth + \",\" + window.innerHeight);").split(","); canvas.setHeight(Integer.valueOf(dimensions[1])); canvas.setWidth(Integer.valueOf(dimensions[0])); canvas.setViewPortRelative(true); ScreenShotReply reply = services.getExec().screenWatcher(canvas, 1l, true); FileOutputStream stream; try { stream = new FileOutputStream(pngFile.getAbsolutePath()); stream.write(reply.getPng()); stream.close(); } catch (FileNotFoundException e) { // ignore } catch (IOException e) { // TODO log } }
From source file:com.opera.core.systems.scope.services.ums.EcmaScriptDebugger.java
License:Apache License
public void init() { Configuration.Builder configuration = Configuration.newBuilder(); configuration.setStopAtScript(false); configuration.setStopAtAbort(false); configuration.setStopAtException(false); configuration.setStopAtError(false); configuration.setStopAtDebuggerStatement(false); configuration.setStopAtGc(false);/*ww w. j av a 2 s. c om*/ executeCommand(ESDebuggerCommand.SET_CONFIGURATION, configuration); if (!updateRuntime()) { throw new WebDriverException("Could not find a runtime for script injection"); } // FIXME workaround for internal dialog // The dialog is finally removed but just keeping this here // until every platform upgrades to core 2.7+ executeJavascript("return 1;", true); }
From source file:com.opera.core.systems.scope.services.ums.EcmaScriptDebugger.java
License:Apache License
public Object scriptExecutor(String script, Object... params) { List<WebElement> elements = new ArrayList<WebElement>(); String toSend = buildEvalString(elements, script, params); EvalData.Builder evalBuilder = buildEval(toSend, getRuntimeId()); for (WebElement webElement : elements) { Variable variable = buildVariable(webElement.toString(), ((OperaWebElement) webElement).getObjectId()); evalBuilder.addVariableList(variable); }//from w ww . j ava 2 s .c o m Response response = executeCommand(ESDebuggerCommand.EVAL, evalBuilder); if (response == null) { throw new WebDriverException("Internal error while executing script"); } EvalResult result = parseEvalData(response); Object parsed = parseEvalReply(result); if (parsed instanceof ObjectValue) { ObjectValue data = (ObjectValue) parsed; return new ScriptResult(data.getObjectID(), data.getName()); } else { return parsed; } }