List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:org.xwiki.test.ui.RegisterTest.java
License:Open Source License
@Before public void setUp() { registerPage = getRegisterPage();//from www .j a v a2 s. c o m deleteUser("JohnSmith"); switchUser(); registerPage.gotoPage(); // Switch LiveValidation on or off as needed. int x = 0; while (registerPage.liveValidationEnabled() != useLiveValidation()) { AdministrationSectionPage sectionPage = new AdministrationSectionPage("Registration"); getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(sectionPage.getURL())); getUtil().assertOnPage(sectionPage.getURL()); sectionPage.getForm().setFieldValue(By.name("XWiki.Registration_0_liveValidation_enabled"), Boolean.valueOf(useLiveValidation()).toString()); sectionPage.clickSave(); if (x > 2) { throw new WebDriverException("Unable to set useLiveValidation to " + useLiveValidation()); } x++; registerPage.gotoPage(); } registerPage.fillInJohnSmithValues(); }
From source file:org.zaproxy.zap.extension.jxbrowserlinux64.selenium.JxBrowserProvider.java
License:Apache License
private RemoteWebDriver getRemoteWebDriver(final int requesterId, final String proxyAddress, final int proxyPort) { if (View.isInitialised()) { try {//from ww w . j a va2 s. c om GetWebDriverRunnable wb = new GetWebDriverRunnable(requesterId, proxyAddress, proxyPort); EventQueue.invokeAndWait(wb); return wb.getWebDriver(); } catch (InvocationTargetException | InterruptedException e) { throw new WebDriverException(e); } } synchronized (this) { return getRemoteWebDriverImpl(requesterId, proxyAddress, proxyPort); } }
From source file:org.zaproxy.zap.extension.jxbrowserlinux64.selenium.JxBrowserProvider.java
License:Apache License
private RemoteWebDriver getRemoteWebDriverImpl(final int requesterId, String proxyAddress, int proxyPort) { try {/*from w w w.jav a 2 s. c o m*/ ZapBrowserFrame zbf = this.getZapBrowserFrame(requesterId); File dataDir = Files.createTempDirectory("zap-jxbrowser").toFile(); dataDir.deleteOnExit(); BrowserContextParams contextParams = new BrowserContextParams(dataDir.getAbsolutePath()); if (proxyAddress != null && !proxyAddress.isEmpty()) { String hostPort = proxyAddress + ":" + proxyPort; String proxyRules = "http=" + hostPort + ";https=" + hostPort; contextParams.setProxyConfig(new CustomProxyConfig(proxyRules)); } BrowserPreferences.setChromiumSwitches("--remote-debugging-port=" + chromePort); Browser browser = new Browser(new BrowserContext(contextParams)); final BrowserPanel browserPanel = zbf.addNewBrowserPanel(isNotAutomated(requesterId), browser); if (!ensureExecutable(webdriver)) { throw new IllegalStateException("Failed to ensure WebDriver is executable."); } final ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(webdriver.toFile()).usingAnyFreePort().build(); service.start(); DesiredCapabilities capabilities = new DesiredCapabilities(); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("debuggerAddress", "localhost:" + chromePort); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return new RemoteWebDriver(service.getUrl(), capabilities) { @Override public void close() { super.close(); cleanUpBrowser(requesterId, browserPanel); // XXX should stop here too? // service.stop(); } @Override public void quit() { super.quit(); cleanUpBrowser(requesterId, browserPanel); boolean interrupted = Thread.interrupted(); service.stop(); if (interrupted) { Thread.currentThread().interrupt(); } } }; } catch (Exception e) { throw new WebDriverException(e); } }
From source file:org.zaproxy.zap.extension.jxbrowserlinux64.selenium.JxBrowserProvider.java
License:Apache License
protected int getFreePort() { try (ServerSocket socket = new ServerSocket(0, 400, InetAddress.getByName("localhost"))) { return socket.getLocalPort(); } catch (Exception e) { throw new WebDriverException(e); }/*from www. j a v a 2 s . c o m*/ }
From source file:org.zaproxy.zap.extension.jxbrowsermacos.selenium.MacOsJxBrowserProvider.java
License:Apache License
@Override protected int getFreePort() { // Reuse the same port, as the JxBrowser/Chrome process tends to live longer on macOS. if (chromePort == null) { try (ServerSocket socket = new ServerSocket(0, 400, InetAddress.getByName("localhost"))) { chromePort = socket.getLocalPort(); } catch (Exception e) { throw new WebDriverException(e); }// ww w.j a v a 2 s.co m } return chromePort; }
From source file:phantomjs.PhantomJSDriver.java
License:Apache License
/** * In case this instance was required to handle the life-cycle of the PhantomJS process, that starts here. * Otherwise this is a "transparent" method. * * @param desiredCapabilities/*from w ww . j a v a 2 s.c om*/ * @param requiredCapabilities * @throws WebDriverException */ @Override protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities) throws WebDriverException { // Will launch a PhantomJS WebDriver process ONLY if this driver is not already using an external one if (!useExternalPhantomJS) { // Read PhantomJS executable and JS Driver path from the capabilities String executablePath = (String) desiredCapabilities.getCapability(CAPABILITY_PHANTOMSJS_EXEC_PATH); String driverPath = (String) desiredCapabilities.getCapability(CAPABILITY_PHANTOMJS_DRIVER_PATH); // Throw WebDriverException in case any of the previous two was not provided if (executablePath == null || driverPath == null || !new File(executablePath).exists() || !new File(driverPath).exists()) { throw new WebDriverException( "PhantomJSDriver: Path to PhantomJS Executable or Driver not provided/invalid"); } // Read the Proxy configuration Proxy proxy = (Proxy) desiredCapabilities.getCapability(CapabilityType.PROXY); // Prepare the parameters to pass to the PhantomJS executable on the command line String proxyParams = ""; if (proxy != null) { switch (proxy.getProxyType()) { case MANUAL: if (!proxy.getHttpProxy().isEmpty()) { //< HTTP proxy log(getSessionId(), "Reading Proxy Configuration", "Manual, HTTP", When.BEFORE); proxyParams = String.format("--proxy-type=http --proxy=%s", proxy.getHttpProxy()); } else if (!proxy.getSocksProxy().isEmpty()) { //< SOCKS5 proxy log(getSessionId(), "Reading Proxy Configuration", "Manual, SOCKS5", When.BEFORE); proxyParams = String.format("--proxy-type=socks5 --proxy=%s --proxy-auth=%s:%s", proxy.getSocksProxy(), proxy.getSocksUsername(), proxy.getSocksPassword()); } else { // TODO Other type of proxy not supported yet by PhantomJS log(getSessionId(), "Reading Proxy Configuration", "Manual, NOT SUPPORTED", When.BEFORE); } break; case PAC: // TODO Not supported yet by PhantomJS log(getSessionId(), "Reading Proxy Configuration", "PAC, NOT SUPPORTED", When.BEFORE); break; case SYSTEM: log(getSessionId(), "Reading Proxy Configuration", "SYSTEM", When.BEFORE); proxyParams = "--proxy-type=system"; break; case AUTODETECT: // TODO Not supported yet by PhantomJS log(getSessionId(), "Reading Proxy Configuration", "AUTODETECT, NOT SUPPORTED", When.BEFORE); break; case DIRECT: log(getSessionId(), "Reading Proxy Configuration", "DIRECT", When.BEFORE); proxyParams = "--proxy-type=none"; default: log(getSessionId(), "Reading Proxy Configuration", "NONE", When.BEFORE); proxyParams = ""; break; } } // Find a free port to launch PhantomJS WebDriver on String phantomJSPortStr = Integer.toString(PortProber.findFreePort()); log(getSessionId(), "Looking for a free port for PhantomJS WebDriver", phantomJSPortStr, When.AFTER); log(getSessionId(), "About to launch PhantomJS WebDriver", null, When.BEFORE); try { // Launch PhantomJS and wait for first output on console before proceeding phantomJSProcess = Runtime.getRuntime().exec(new String[] { executablePath, //< path to PhantomJS executable proxyParams, //< command line parameters for Proxy configuration driverPath, //< path to the PhantomJS Driver phantomJSPortStr //< port on which the Driver should listen on }); final BufferedReader reader = new BufferedReader( new InputStreamReader(phantomJSProcess.getInputStream())); while (reader.readLine() == null) { /* wait here for some output: once it prints, it's ready to work */ } useExternalPhantomJS = false; // PhantomJS is ready to serve. // Setting the HTTP Command Executor that this RemoteWebDriver will use setCommandExecutor(new HttpCommandExecutor(new URL("http://localhost:" + phantomJSPortStr))); } catch (IOException ioe) { // Log exception & Cleanup log(getSessionId(), null, ioe, When.EXCEPTION); stopClient(); throw new WebDriverException("PhantomJSDriver: " + ioe.getMessage(), ioe); } log(getSessionId(), "PhantomJS WebDriver ready", null, When.AFTER); } // We are ready to let the RemoteDriver do its job from here super.startSession(desiredCapabilities, requiredCapabilities); }
From source file:ru.stqa.selenium.decorated.DecoratedWebDriver.java
License:Apache License
@Override public Object executeScript(String script, Object... args) { WebDriver driver = getOriginal();// w ww . ja va 2 s . c o m if (driver instanceof JavascriptExecutor) { return wrapObject(((JavascriptExecutor) driver).executeScript(script, args)); } else { throw new WebDriverException("Wrapped webdriver does not support JavascriptExecutor: " + driver); } }
From source file:ru.stqa.selenium.decorated.DecoratedWebDriver.java
License:Apache License
@Override public Object executeAsyncScript(String script, Object... args) { WebDriver driver = getOriginal();//from ww w . j a v a2s. c o m if (driver instanceof JavascriptExecutor) { return wrapObject(((JavascriptExecutor) driver).executeAsyncScript(script, args)); } else { throw new WebDriverException("Wrapped webdriver does not support JavascriptExecutor: " + driver); } }
From source file:ru.stqa.selenium.factory.FakeAlertiveWebDriver.java
License:Apache License
@Override public Set<String> getWindowHandles() { if (isActive) { throw new UnhandledAlertException("alert"); } else {/*w w w.j a v a2 s . c o m*/ throw new WebDriverException("closed"); } }
From source file:ru.stqa.selenium.factory.FakeWebDriver.java
License:Apache License
@Override public Set<String> getWindowHandles() { if (isActive) { return new HashSet<String>(Arrays.asList("12345")); } else {/*from w w w. j a va2 s . c o m*/ throw new WebDriverException("closed"); } }