List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:org.agileware.test.web.AbstractDelegatingWebDriver.java
License:Open Source License
/** * @see org.openqa.selenium.JavascriptExecutor#executeAsyncScript(java.lang.String, * java.lang.Object[])/*from w w w .j av a 2s . c o m*/ */ public Object executeAsyncScript(String script, Object... args) throws WebDriverException { try { return ((JavascriptExecutor) delegate).executeAsyncScript(script, args); } catch (ClassCastException cce) { throw new WebDriverException( "Delegate implementation `" + delegate.getClass() + "` does not support this feature"); } }
From source file:org.agileware.test.web.AbstractDelegatingWebDriver.java
License:Open Source License
/** * @see org.openqa.selenium.JavascriptExecutor#executeScript(java.lang.String, * java.lang.Object[])/*from www .ja v a2 s.com*/ */ public Object executeScript(String script, Object... args) throws WebDriverException { try { return ((JavascriptExecutor) delegate).executeScript(script, args); } catch (ClassCastException cce) { throw new WebDriverException( "Delegate implementation `" + delegate.getClass() + "` does not support this feature"); } }
From source file:org.agileware.test.web.AbstractDelegatingWebDriver.java
License:Open Source License
/** * @see org.openqa.selenium.TakesScreenshot#getScreenshotAs(org.openqa.selenium.OutputType) *///from w w w . j a v a 2 s . c om public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException { try { return ((TakesScreenshot) delegate).getScreenshotAs(target); } catch (ClassCastException cce) { throw new WebDriverException( "Delegate implementation `" + delegate.getClass() + "` does not support this feature"); } }
From source file:org.aludratest.service.gui.web.selenium.selenium2.AludraSeleniumHttpCommandExecutor.java
License:Apache License
/** Constructs a new HttpCommandExecutor for the given remote server. * /*from w w w . j a v a 2 s. c om*/ * @param addressOfRemoteServer Remove server, or <code>null</code> to fall back to the System property * <code>webdriver.remote.server</code>, or to <code>http://localhost:4444/wd/hub</code> if system property is not * set. */ public AludraSeleniumHttpCommandExecutor(URL addressOfRemoteServer) { try { remoteServer = addressOfRemoteServer == null ? new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/wd/hub")) : addressOfRemoteServer; } catch (MalformedURLException e) { throw new WebDriverException(e); } commandCodec = new JsonHttpCommandCodec(); responseCodec = new JsonHttpResponseCodec(); synchronized (AludraSeleniumHttpCommandExecutor.class) { if (httpClientFactory == null) { httpClientFactory = new HttpClientFactory(); } } if (addressOfRemoteServer != null && addressOfRemoteServer.getUserInfo() != null) { // Use HTTP Basic auth UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( addressOfRemoteServer.getUserInfo()); client = httpClientFactory.createHttpClient(credentials); } else { client = httpClientFactory.getHttpClient(); } // Some machines claim "localhost.localdomain" is the same as "localhost". // This assumption is not always true. String host = remoteServer.getHost().replace(".localdomain", ""); targetHost = new HttpHost(host, remoteServer.getPort(), remoteServer.getProtocol()); }
From source file:org.aludratest.service.gui.web.selenium.selenium2.AludraSeleniumHttpCommandExecutor.java
License:Apache License
private HttpResponse followRedirects(HttpClient client, HttpContext context, HttpResponse response, int redirectCount) { if (!isRedirect(response)) { return response; }/* ww w .j av a2s. co m*/ try { // Make sure that the previous connection is freed. HttpEntity httpEntity = response.getEntity(); if (httpEntity != null) { EntityUtils.consume(httpEntity); } } catch (IOException e) { throw new WebDriverException(e); } if (redirectCount > MAX_REDIRECTS) { throw new WebDriverException("Maximum number of redirects exceeded. Aborting"); } String location = response.getFirstHeader("location").getValue(); URI uri; try { uri = buildUri(context, location); HttpGet get = new HttpGet(uri); get.setHeader("Accept", "application/json; charset=utf-8"); HttpResponse newResponse = client.execute(targetHost, get, context); return followRedirects(client, context, newResponse, redirectCount + 1); } catch (URISyntaxException e) { throw new WebDriverException(e); } catch (ClientProtocolException e) { throw new WebDriverException(e); } catch (IOException e) { throw new WebDriverException(e); } }
From source file:org.aludratest.service.gui.web.selenium.selenium2.Selenium2Driver.java
License:Apache License
/** @param browserArguments Arguments to pass to the browser to launch. These may or may not be ignored, depending on the driver * implementation./* w ww . j av a2s . co m*/ * * @return a freshly created instance of the related WebDriver class */ public WebDriver newLocalDriver(String[] browserArguments) { Constructor<?> cstr = null; try { cstr = driverClass.getConstructor(DesiredCapabilities.class); } catch (SecurityException e) { throw new WebDriverException(e); } catch (NoSuchMethodException e) { try { cstr = driverClass.getConstructor(Capabilities.class); } catch (SecurityException e1) { throw new WebDriverException(e1); } catch (NoSuchMethodException e1) { throw new WebDriverException(e1); } } // currently, browser arguments for LOCAL driver only supported for PhantomJS DesiredCapabilities caps = new DesiredCapabilities(capabilities); String[] args = (String[]) caps.getCapability("phantomjs.cli.args"); if (args != null && browserArguments != null && browserArguments.length > 0) { String[] newArgs = new String[browserArguments.length + args.length]; System.arraycopy(args, 0, newArgs, 0, args.length); System.arraycopy(browserArguments, 0, newArgs, args.length, browserArguments.length); caps.setCapability("phantomjs.cli.args", newArgs); } try { return (WebDriver) cstr.newInstance(caps); } catch (IllegalArgumentException e) { throw new WebDriverException(e); } catch (InstantiationException e) { throw new WebDriverException(e); } catch (IllegalAccessException e) { throw new WebDriverException(e); } catch (InvocationTargetException e) { throw new WebDriverException(e); } }
From source file:org.apache.nutch.protocol.webdriver.driver.NutchDriverService.java
License:Apache License
public static DriverService createDriverService(int port) { try {/*from ww w. ja v a 2 s .co m*/ return new NutchDriverService(findDefaultExecutable(), port, null, null); } catch (IOException e) { throw new WebDriverException(e); } }
From source file:org.apache.nutch.protocol.webdriver.driver.NutchFirefoxDriver.java
License:Apache License
private static FirefoxProfile getProfile(Capabilities cap) { FirefoxProfile profile = null;//from w w w . j a va 2 s . c o m Object raw = null; if (cap != null && cap.getCapability(PROFILE) != null) { raw = cap.getCapability(PROFILE); } if (raw != null) { if (raw instanceof FirefoxProfile) { profile = (FirefoxProfile) raw; } else if (raw instanceof String) { try { profile = FirefoxProfile.fromJson((String) raw); } catch (IOException e) { throw new WebDriverException(e); } } } if (profile == null) { profile = new FirefoxProfile(); } return profile; }
From source file:org.apache.nutch.protocol.webdriver.driver.NutchFirefoxDriver.java
License:Apache License
static Capabilities populateProfile(FirefoxProfile profile, Capabilities capabilities) { if (capabilities == null) { return capabilities; }/*from w ww . j a va 2 s . co m*/ Object rawOptions = capabilities.getCapability(FIREFOX_OPTIONS); if (rawOptions == null) { rawOptions = capabilities.getCapability(OLD_FIREFOX_OPTIONS); } if (rawOptions != null && !(rawOptions instanceof FirefoxOptions)) { throw new WebDriverException("Firefox option was set, but is not a FirefoxOption: " + rawOptions); } FirefoxOptions options = (FirefoxOptions) rawOptions; if (options == null) { options = new FirefoxOptions(); } options.setProfile(profile); DesiredCapabilities toReturn = capabilities instanceof DesiredCapabilities ? (DesiredCapabilities) capabilities : new DesiredCapabilities(capabilities); toReturn.setCapability(OLD_FIREFOX_OPTIONS, options); toReturn.setCapability(FIREFOX_OPTIONS, options); return toReturn; }
From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java
License:Apache License
private RemoteWebDriver createWebDriver() { RemoteWebDriverFactory driverFactory = getInstalledWebDrivers().get(getBrowserName()); if (driverFactory == null) throw new WebDriverException("No WebDrivers available for " + getBrowserName() + ", try one of " + getInstalledWebDrivers().keySet()); String testname = getMethodName(); RemoteWebDriver driver = driverFactory.create(testname); init(driver);/* w ww.j a va 2 s. co m*/ return driver; }