List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:org.nuxeo.functionaltests.ScreenshotTaker.java
License:Apache License
public File dumpPageSource(WebDriver driver, String filename) { if (driver == null) { return null; }/*from w ww . j av a 2 s . c o m*/ FileWriter writer = null; try { String location = System.getProperty("basedir") + File.separator + "target"; File outputFolder = new File(location); if (!outputFolder.exists() || !outputFolder.isDirectory()) { outputFolder = null; } if (outputFolder != null && !StringUtils.isBlank(targetDirName)) { outputFolder = new File(outputFolder, targetDirName); outputFolder.mkdir(); } File tmpFile = File.createTempFile(filename, ".html", outputFolder); log.trace(String.format("Created page source file named '%s'", tmpFile.getPath())); writer = new FileWriter(tmpFile); writer.write(driver.getPageSource()); return tmpFile; } catch (IOException e) { throw new WebDriverException(e); } finally { IOUtils.closeQuietly(writer); } }
From source file:org.nvonop.selenium.framework.Browser.java
License:Open Source License
/** * This method initialises the ThreadLocal WebDriver object according to the * supplied parameters to enable tests to run on a users local machine. *///w w w . j av a 2 s .c o m private void setLocalWebdriver() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setJavascriptEnabled(true); capabilities.setCapability("handlesAlerts", true); switch (getBrowserId(browser)) { case 0: capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false"))); driver.set(new InternetExplorerDriver(capabilities)); break; case 1: driver.set(new FirefoxDriver(capabilities)); break; case 2: driver.set(new SafariDriver(capabilities)); break; case 3: driver.set(new ChromeDriver(capabilities)); break; default: throw new WebDriverException("Browser not found: " + browser); } }
From source file:org.nvonop.selenium.framework.Browser.java
License:Open Source License
/** * This method initialises the ThreadLocal WebDriver object according to the * supplied parameters to enable tests to run remotely on a grid of test * machines.// w w w . ja va 2 s.co m */ private void setRemoteWebdriver() { switch (getBrowserId(browser)) { case 0: capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false"))); break; case 1: capabilities = DesiredCapabilities.firefox(); break; case 2: capabilities = DesiredCapabilities.safari(); break; case 3: capabilities = DesiredCapabilities.chrome(); break; default: throw new WebDriverException("Browser not found: " + browser); } capabilities.setCapability("javascriptEnabled", true); capabilities.setCapability("platform", platform); capabilities.setCapability("version", version); capabilities.merge(extraCapabilities); try { this.driver.set(new RemoteWebDriver(new URL("http://" + System.getProperty("GRID_HOST") + ":" + System.getProperty("GRID_PORT") + "/wd/hub"), capabilities)); } catch (MalformedURLException e) { LOGGER.log(Level.INFO, "MalformedURLException in setRemoteWebdriver() method", e); } }
From source file:org.nvonop.selenium.framework.Browser.java
License:Open Source License
/** * This method initialises the ThreadLocal WebDriver object according to the * supplied parameters to enable tests to run on Sauce Labs cloud * infrastructure.//from w w w . j a v a2s . com */ private void setSauceWebdriver() { switch (getBrowserId(browser)) { case 0: capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false"))); break; case 1: capabilities = DesiredCapabilities.firefox(); break; case 2: capabilities = DesiredCapabilities.safari(); break; case 3: capabilities = DesiredCapabilities.chrome(); break; case 4: capabilities = DesiredCapabilities.iphone(); capabilities.setCapability("deviceName", "iPhone Simulator"); capabilities.setCapability("device-orientation", "portrait"); break; case 5: capabilities = DesiredCapabilities.iphone(); capabilities.setCapability("deviceName", "iPad Simulator"); capabilities.setCapability("device-orientation", "portrait"); break; case 6: capabilities = DesiredCapabilities.android(); capabilities.setCapability("deviceName", "Android Emulator"); capabilities.setCapability("device-orientation", "portrait"); break; default: throw new WebDriverException("Browser not found: " + browser); } capabilities.merge(extraCapabilities); capabilities.setCapability("javascriptEnabled", true); capabilities.setCapability("platform", platform); capabilities.setCapability("version", version); try { this.driver.set(new RemoteWebDriver(new URL(System.getProperty("SAUCE_KEY")), capabilities)); } catch (MalformedURLException e) { LOGGER.log(Level.INFO, "MalformedURLException in setSauceWebdriver() method", e); } }
From source file:org.nvonop.selenium.framework.Browser.java
License:Open Source License
/** * This method provides a way of initialising a ThreadLocal WebDriver object * in a consistent way regardless of where the test will run. The following * system properties must be set to "true" or "false" for this method to * function correctly: LOCAL_DRIVER, REMOTE_DRIVER, SAUCE_DRIVER. Setting * one of the properties to "true" will ensure the ThreadLocal WebDriver * object is initialised appropriately./* w w w . java 2 s.c o m*/ */ private void setWebDriver() { if (Boolean.valueOf(System.getProperty("LOCAL_DRIVER"))) { setLocalWebdriver(); } else if (Boolean.valueOf(System.getProperty("REMOTE_DRIVER"))) { setRemoteWebdriver(); } else if (Boolean.valueOf(System.getProperty("SAUCE_DRIVER"))) { setSauceWebdriver(); } else { throw new WebDriverException("Type of driver not specified!!!"); } this.driver.get().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); if (browser.equalsIgnoreCase("internet explorer") | browser.equalsIgnoreCase("firefox") | browser.equalsIgnoreCase("chrome") | browser.equalsIgnoreCase("safari")) { //we only want to maximise the browser window for desktop browser, not devices. this.driver.get().manage().window().maximize(); } }
From source file:org.nvonop.selenium.framework.Browser.java
License:Open Source License
/** * This method provides a way of specifying browser capabilities manually * * @param key//from ww w.j a v a 2 s . com * @param value * @return boolean */ public boolean setBrowserCapability(String key, String value) { if (Boolean.valueOf(System.getProperty("LOCAL_DRIVER"))) { return false; } else if (Boolean.valueOf(System.getProperty("REMOTE_DRIVER"))) { extraCapabilities.setCapability(key, value); return true; } else if (Boolean.valueOf(System.getProperty("SAUCE_DRIVER"))) { extraCapabilities.setCapability(key, value); return true; } else { throw new WebDriverException("Type of driver not specified!!!"); } }
From source file:org.nvonop.selenium.framework.utilities.BaseTest.java
License:Open Source License
/** * This method initialises the ThreadLocal WebDriver object according to the * supplied parameters to enable tests to run on a users local machine. * * @param browser This can be set to "chrome", "internet explorer" or "firefox" * @param version This should be set to reflect the browser required. It is only * used when matching capabilities for a RemoteWebDriver object * however./*from w ww .ja v a 2s.c o m*/ * @param platform This should be set to whatever platform the test is required * to run on e.g. "WINDOWS", "MAC", "LINUX". It is only used when * matching capabilities for a RemoteWebDriver object however. */ public void setLocalWebdriver(String browser, String version, String platform) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setJavascriptEnabled(true); capabilities.setCapability("handlesAlerts", true); switch (getBrowserId(browser)) { case 0: capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false"))); driver.set(new InternetExplorerDriver(capabilities)); break; case 1: driver.set(new FirefoxDriver(capabilities)); break; case 2: driver.set(new SafariDriver(capabilities)); break; case 3: driver.set(new ChromeDriver(capabilities)); break; default: throw new WebDriverException("Browser not found: " + browser); } }
From source file:org.nvonop.selenium.framework.utilities.BaseTest.java
License:Open Source License
/** * This method initialises the ThreadLocal WebDriver object according to the * supplied parameters to enable tests to run on Sauce Labs cloud * infrastructure.// w ww. j a va2 s. c o m * * @param browser This can be set to "chrome", "internet explorer" or "firefox" * @param version This should be set to reflect the browser required. It is only * used when matching capabilities for a RemoteWebDriver object * however. * @param platform This should be set to whatever platform the test is required * to run on e.g. "WINDOWS", "MAC", "LINUX". It is only used when * matching capabilities for a RemoteWebDriver object however. */ public void setSauceWebdriver(String browser, String version, String platform) { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (getBrowserId(browser)) { case 0: capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false"))); break; case 1: capabilities = DesiredCapabilities.firefox(); break; case 2: capabilities = DesiredCapabilities.safari(); break; case 3: capabilities = DesiredCapabilities.chrome(); break; default: throw new WebDriverException("Browser not found: " + browser); } capabilities.setCapability("javascriptEnabled", true); capabilities.setCapability("version", version); capabilities.setCapability("platform", platform); try { this.driver.set(new RemoteWebDriver(new URL(System.getProperty("SAUCE_KEY")), capabilities)); } catch (MalformedURLException e) { LOGGER.log(Level.INFO, "MalformedURLException in setSauceWebdriver() method", e); } }
From source file:org.nvonop.selenium.framework.utilities.BaseTest.java
License:Open Source License
/** * This method initialises the ThreadLocal WebDriver object according to the * supplied parameters to enable tests to run remotely on a grid of test * machines.//from w ww . j a v a 2 s.c om * * @param browser This can be set to "chrome", "internet explorer" or "firefox" * @param version This should be set to reflect the browser required. It is only * used when matching capabilities for a RemoteWebDriver object * however. * @param platform This should be set to whatever platform the test is required * to run on e.g. "WINDOWS", "MAC", "LINUX". It is only used when * matching capabilities for a RemoteWebDriver object however. */ public void setRemoteWebdriver(String browser, String version, String platform) { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (getBrowserId(browser)) { case 0: capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability("version", version); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false"))); break; case 1: capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("version", version); break; case 2: capabilities = DesiredCapabilities.safari(); capabilities.setCapability("version", version); break; case 3: capabilities = DesiredCapabilities.chrome(); break; default: throw new WebDriverException("Browser not found: " + browser); } capabilities.setCapability("javascriptEnabled", true); capabilities.setCapability("platform", platform); try { this.driver.set(new RemoteWebDriver(new URL("http://" + System.getProperty("GRID_HOST") + ":" + System.getProperty("GRID_PORT") + "/wd/hub"), capabilities)); } catch (MalformedURLException e) { LOGGER.log(Level.INFO, "MalformedURLException in setRemoteWebdriver() method", e); } }
From source file:org.nvonop.selenium.framework.utilities.BaseTest.java
License:Open Source License
/** * This method provides a way of initialising a ThreadLocal WebDriver object * in a consistent way regardless of where the test will run. The following * system properties must be set to "true" or "false" for this method to * function correctly: LOCAL_DRIVER, REMOTE_DRIVER, SAUCE_DRIVER. Setting * one of the properties to "true" will ensure the ThreadLocal WebDriver * object is initialised appropriately.// w w w . ja v a 2 s . c om * * @param browser This can be set to "chrome", "internet explorer" or "firefox" * @param version This should be set to reflect the browser required. It is only * used when matching capabilities for a RemoteWebDriver object * however. * @param platform This should be set to whatever platform the test is required * to run on e.g. "WINDOWS", "MAC", "LINUX". It is only used when * matching capabilities for a RemoteWebDriver object however. */ public void setWebDriver(String browser, String version, String platform) { if (Boolean.valueOf(System.getProperty("LOCAL_DRIVER"))) { setLocalWebdriver(browser, version, platform); } else if (Boolean.valueOf(System.getProperty("REMOTE_DRIVER"))) { setRemoteWebdriver(browser, version, platform); } else if (Boolean.valueOf(System.getProperty("SAUCE_DRIVER"))) { setSauceWebdriver(browser, version, platform); } else { throw new WebDriverException("Type of driver not specified!!!"); } this.driver.get().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); this.driver.get().manage().window().maximize(); }