/** * Generates a phantomJs webdriver. * * @return * A phantomJs webdriver * @throws TechnicalException * if an error occured when Webdriver setExecutable to true. */ private WebDriver generatePhantomJsDriver() throws TechnicalException { final String pathWebdriver = DriverFactory.getPath(Driver.PHANTOMJS); if (!new File(pathWebdriver).setExecutable(true)) { throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE)); } logger.info("Generating Phantomjs driver ({}) ...", pathWebdriver); final DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "fr-FR"); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathWebdriver); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); capabilities.setJavascriptEnabled(true); setLoggingLevel(capabilities); // Proxy configuration String proxy = ""; if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { proxy = Context.getProxy().getHttpProxy(); } capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--proxy=" + proxy, "--web-security=no", "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--webdriver-loglevel=NONE" }); return new PhantomJSDriver(capabilities); }
/** * Generates a htmlunit webdriver. * * @return * A htmlunit webdriver */ private WebDriver generateHtmlUnitDriver() { logger.info("Generating HtmlUnit driver..."); final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit(); capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); capabilities.setJavascriptEnabled(true); setLoggingLevel(capabilities); // Proxy configuration if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { capabilities.setCapability(CapabilityType.PROXY, Context.getProxy()); } return new HtmlUnitDriver(capabilities); }
private WebDriver initIEDriver(String appURL) { System.out.println("Launching IE browser.."); DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setJavascriptEnabled(true); ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); ieCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING,true); ieCapabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.DISMISS); //Accept unexpected alerts ieCapabilities.setCapability("requireWindowFocus", true); ieCapabilities.setCapability("enablePersistentHover", false); ieCapabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); WebDriver driver=new InternetExplorerDriver(ieCapabilities); driver.manage().deleteAllCookies(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); for(String winHandle : driver.getWindowHandles()){ driver = driver.switchTo().window(winHandle); } driver.get(appURL); return new WebDriverProxy().protect(driver); }
@Autowired private void setConfiguration(Configuration configuration) { getSettings().setDriverName("chrome"); getSettings().getRestartDriverCount(); //set value other than default configuration.addCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); }
@Test @NeedRestartDriver public void chrome_config_test() { openPage("main.html", BasePage.class); WebDriver webDriver = ((FramesTransparentWebDriver) SeleniumHolder.getWebDriver()).getWrappedDriver(); Assert.assertTrue(webDriver instanceof ChromeDriver); Assert.assertEquals(((RemoteWebDriver) webDriver).getCapabilities().getCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR), UnexpectedAlertBehaviour.IGNORE.toString()); }
/** * Generates an ie webdriver. Unable to use it with a proxy. Causes a crash. * * @return * An ie webdriver * @throws TechnicalException * if an error occured when Webdriver setExecutable to true. */ private WebDriver generateIEDriver() throws TechnicalException { final String pathWebdriver = DriverFactory.getPath(Driver.IE); if (!new File(pathWebdriver).setExecutable(true)) { throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE)); } logger.info("Generating IE driver ({}) ...", pathWebdriver); System.setProperty(Driver.IE.getDriverName(), pathWebdriver); final DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true); capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true); capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true); capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability("disable-popup-blocking", true); capabilities.setJavascriptEnabled(true); setLoggingLevel(capabilities); // Proxy configuration if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { capabilities.setCapability(CapabilityType.PROXY, Context.getProxy()); } return new InternetExplorerDriver(capabilities); }
/** * Generates a chrome webdriver. * * @param headlessMode * Enable headless mode ? * @return * A chrome webdriver * @throws TechnicalException * if an error occured when Webdriver setExecutable to true. */ private WebDriver generateGoogleChromeDriver(boolean headlessMode) throws TechnicalException { final String pathWebdriver = DriverFactory.getPath(Driver.CHROME); if (!new File(pathWebdriver).setExecutable(true)) { throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE)); } logger.info("Generating Chrome driver ({}) ...", pathWebdriver); System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver); final ChromeOptions chromeOptions = new ChromeOptions(); final DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); setLoggingLevel(capabilities); if (Context.isHeadless()) { chromeOptions.addArguments("--headless"); } // Proxy configuration if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { capabilities.setCapability(CapabilityType.PROXY, Context.getProxy()); } setChromeOptions(capabilities, chromeOptions); String withWhitelistedIps = Context.getWebdriversProperties("withWhitelistedIps"); if (withWhitelistedIps != null && !"".equals(withWhitelistedIps)) { ChromeDriverService service = new ChromeDriverService.Builder().withWhitelistedIps(withWhitelistedIps).withVerbose(false).build(); return new ChromeDriver(service, capabilities); } else { return new ChromeDriver(capabilities); } }
/** * Generates a firefox webdriver. * * @return * A firefox webdriver * @throws TechnicalException * if an error occured when Webdriver setExecutable to true. */ private WebDriver generateFirefoxDriver() throws TechnicalException { final String pathWebdriver = DriverFactory.getPath(Driver.FIREFOX); if (!new File(pathWebdriver).setExecutable(true)) { throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE)); } logger.info("Generating Firefox driver ({}) ...", pathWebdriver); System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver); final FirefoxOptions firefoxOptions = new FirefoxOptions(); final FirefoxBinary firefoxBinary = new FirefoxBinary(); final DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); setLoggingLevel(capabilities); // Proxy configuration if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { capabilities.setCapability(CapabilityType.PROXY, Context.getProxy()); } if (Context.isHeadless()) { firefoxBinary.addCommandLineOptions("--headless"); firefoxOptions.setBinary(firefoxBinary); } firefoxOptions.setLogLevel(Level.OFF); capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, firefoxOptions); return new FirefoxDriver(capabilities); }
private static DesiredCapabilities getIECapabilities(BrowserModel browser, Locale lang) { LOG.warn("Language for IE is still not supported! Language found: [" + lang.getLanguage() + "]"); DesiredCapabilities dc = DesiredCapabilities.internetExplorer(); dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); switch(browser){ default: throw new IllegalStateException("Unsupported IE browser version " + browser.getCode()); case IE: //no specific version required LOG.warn("Unspecified IE browser version"); break; case IE9: dc.setVersion("9"); break; case IE10: dc.setVersion("10"); break; case IE11: dc.setVersion("11"); break; case EDGE14: dc.setVersion("10"); break; case EDGE15: dc.setVersion("11"); break; } return dc; }
private static DesiredCapabilities getChromeCapabilities(Locale lang) { ChromeOptions options = getCommonChromeOptions(lang); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return capabilities; }
private static DesiredCapabilities getChromeHeadlessCapabilities(Locale lang) { ChromeOptions options = getCommonChromeOptions(lang); options.addArguments("--headless"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return capabilities; }
private static DesiredCapabilities getPhantomCapabilities(Locale lang) { DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); String value = lang.getLanguage().toLowerCase(); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", value); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); return capabilities; }