List of usage examples for org.openqa.selenium.firefox FirefoxOptions addArguments
public FirefoxOptions addArguments(List<String> arguments)
From source file:javax.portlet.tck.driver.TCKSimpleTestDriver.java
License:Apache License
/** * @throws java.lang.Exception/* w w w .j a va 2 s .c o m*/ */ @BeforeClass public static void setUpBeforeClass() throws Exception { loginUrl = System.getProperty("test.server.login.url"); host = System.getProperty("test.server.host"); port = System.getProperty("test.server.port"); username = System.getProperty("test.server.username"); usernameId = System.getProperty("test.server.username.id"); password = System.getProperty("test.server.password"); passwordId = System.getProperty("test.server.password.id"); browser = System.getProperty("test.browser"); testContextBase = System.getProperty("test.context.base"); String str = System.getProperty("test.url.strategy"); useGeneratedUrl = str.equalsIgnoreCase("generateURLs"); str = System.getProperty("test.debug"); debug = str.equalsIgnoreCase("true"); str = System.getProperty("test.timeout"); dryrun = new Boolean(System.getProperty("test.dryrun")); timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) : 3; String wd = System.getProperty("test.browser.webDriver"); String binary = System.getProperty("test.browser.binary"); boolean browserDefaultHeadless = browser.equalsIgnoreCase("chrome") || browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("htmlunit") || browser.equalsIgnoreCase("phantomjs"); String headlessProperty = System.getProperty("test.browser.headless"); boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0)) && browserDefaultHeadless); System.out.println("before class."); System.out.println(" Debug =" + debug); System.out.println(" Dryrun =" + dryrun); System.out.println(" Timeout =" + timeout); System.out.println(" Login URL =" + loginUrl); System.out.println(" Host =" + host); System.out.println(" Port =" + port); System.out.println(" Context =" + testContextBase); System.out.println(" Generate URL =" + useGeneratedUrl); System.out.println(" Username =" + username); System.out.println(" UsernameId =" + usernameId); System.out.println(" Password =" + password); System.out.println(" PasswordId =" + passwordId); System.out.println(" Browser =" + browser); System.out.println(" Driver =" + wd); System.out.println(" binary =" + binary); System.out.println(" headless =" + headless); if (browser.equalsIgnoreCase("firefox")) { System.setProperty("webdriver.gecko.driver", wd); FirefoxOptions options = new FirefoxOptions(); options.setLegacy(true); options.setAcceptInsecureCerts(true); if ((binary != null) && (binary.length() != 0)) { options.setBinary(binary); } if (headless) { options.setHeadless(true); } driver = new FirefoxDriver(options); } else if (browser.equalsIgnoreCase("internetExplorer")) { System.setProperty("webdriver.ie.driver", wd); driver = new InternetExplorerDriver(); } else if (browser.equalsIgnoreCase("chrome")) { System.setProperty("webdriver.chrome.driver", wd); ChromeOptions options = new ChromeOptions(); if ((binary != null) && (binary.length() > 0)) { options.setBinary(binary); } if (headless) { options.addArguments("--headless"); } options.addArguments("--disable-infobars"); options.setAcceptInsecureCerts(true); driver = new ChromeDriver(options); } else if (browser.equalsIgnoreCase("phantomjs")) { DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setJavascriptEnabled(true); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary); driver = new PhantomJSDriver(capabilities); } else if (browser.equalsIgnoreCase("htmlUnit")) { driver = new HtmlUnitDriver(true); } else if (browser.equalsIgnoreCase("safari")) { driver = new SafariDriver(); } else { throw new Exception("Unsupported browser: " + browser); } if (!dryrun) { login(); } }
From source file:org.apache.nutch.protocol.selenium.HttpWebClient.java
License:Apache License
public static WebDriver createFirefoxWebDriver(String firefoxDriverPath, boolean enableHeadlessMode) { System.setProperty("webdriver.gecko.driver", firefoxDriverPath); FirefoxOptions firefoxOptions = new FirefoxOptions(); if (enableHeadlessMode) { firefoxOptions.addArguments("--headless"); }// w w w. j a v a 2s . c o m WebDriver driver = new FirefoxDriver(firefoxOptions); return driver; }
From source file:org.apache.portals.pluto.test.utilities.SimpleTestDriver.java
License:Apache License
/** * @throws java.lang.Exception/*from www. j a va2s .c o m*/ */ @BeforeClass public static void setUpBeforeClass() throws Exception { if (driver == null) { loginUrl = System.getProperty("test.server.login.url"); host = System.getProperty("test.server.host"); port = System.getProperty("test.server.port"); username = System.getProperty("test.server.username"); usernameId = System.getProperty("test.server.username.id"); password = System.getProperty("test.server.password"); passwordId = System.getProperty("test.server.password.id"); browser = System.getProperty("test.browser"); testContextBase = System.getProperty("test.context.base"); StringBuilder sb = new StringBuilder(); sb.append("http://"); sb.append(host); if (port != null && !port.isEmpty()) { sb.append(":"); sb.append(port); } sb.append("/"); sb.append(testContextBase); baseUrl = sb.toString(); String str = System.getProperty("test.url.strategy"); useGeneratedUrl = str.equalsIgnoreCase("generateURLs"); str = System.getProperty("test.debug"); debug = str.equalsIgnoreCase("true"); str = System.getProperty("test.timeout"); dryrun = Boolean.valueOf(System.getProperty("test.dryrun")); timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) : 3; String wd = System.getProperty("test.browser.webDriver"); String binary = System.getProperty("test.browser.binary"); String headlessProperty = System.getProperty("test.browser.headless"); boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0) || Boolean.valueOf(headlessProperty))); String maximizedProperty = System.getProperty("test.browser.maximized"); boolean maximized = Boolean.valueOf(maximizedProperty); System.out.println("before class."); System.out.println(" Debug =" + debug); System.out.println(" Dryrun =" + dryrun); System.out.println(" Timeout =" + timeout); System.out.println(" Login URL =" + loginUrl); System.out.println(" Host =" + host); System.out.println(" Port =" + port); System.out.println(" Context =" + testContextBase); System.out.println(" Generate URL =" + useGeneratedUrl); System.out.println(" Username =" + username); System.out.println(" UsernameId =" + usernameId); System.out.println(" Password =" + password); System.out.println(" PasswordId =" + passwordId); System.out.println(" Browser =" + browser); System.out.println(" Driver =" + wd); System.out.println(" binary =" + binary); System.out.println(" headless =" + headless); System.out.println(" maximized =" + maximized); if (browser.equalsIgnoreCase("firefox")) { System.setProperty("webdriver.gecko.driver", wd); FirefoxOptions options = new FirefoxOptions(); options.setLegacy(true); options.setAcceptInsecureCerts(true); if ((binary != null) && (binary.length() != 0)) { options.setBinary(binary); } if (headless) { options.setHeadless(true); } driver = new FirefoxDriver(options); } else if (browser.equalsIgnoreCase("internetExplorer")) { System.setProperty("webdriver.ie.driver", wd); driver = new InternetExplorerDriver(); } else if (browser.equalsIgnoreCase("chrome")) { System.setProperty("webdriver.chrome.driver", wd); ChromeOptions options = new ChromeOptions(); if ((binary != null) && (binary.length() > 0)) { options.setBinary(binary); } if (headless) { options.addArguments("--headless"); } options.addArguments("--disable-infobars"); options.setAcceptInsecureCerts(true); if (maximized) { // The webDriver.manage().window().maximize() feature does not work correctly in headless mode, so set the // window size to 1920x1200 (resolution of a 15.4 inch screen). options.addArguments("--window-size=1920,1200"); } driver = new ChromeDriver(options); } else if (browser.equalsIgnoreCase("phantomjs")) { DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setJavascriptEnabled(true); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary); driver = new PhantomJSDriver(capabilities); } else if (browser.equalsIgnoreCase("htmlUnit")) { LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); Logger.getLogger("com.gargoylesoftware").setLevel(Level.SEVERE); Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.SEVERE); driver = new HtmlUnitDriver() { @Override protected WebClient getWebClient() { WebClient webClient = super.getWebClient(); WebClientOptions options = webClient.getOptions(); options.setThrowExceptionOnFailingStatusCode(false); options.setThrowExceptionOnScriptError(false); options.setPrintContentOnFailingStatusCode(false); webClient.setCssErrorHandler(new SilentCssErrorHandler()); return webClient; } }; } else if (browser.equalsIgnoreCase("safari")) { driver = new SafariDriver(); } else { throw new Exception("Unsupported browser: " + browser); } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { driver.quit(); } })); if (maximized) { driver.manage().window().maximize(); } if (!dryrun) { login(); } } }
From source file:org.musetest.selenium.providers.GeckoDriverProvider.java
License:Open Source License
@Override public WebDriver getDriver(SeleniumBrowserCapabilities capabilities, MuseExecutionContext context) { if (getOs() != null && !(OperatingSystem.get().equals(getOs()))) return null; // this provider is not for the current OS if (!capabilities.getName().equals(BrowserType.FIREFOX)) return null; File path = getDriverLocation(context); if (path == null) { context.raiseEvent(MessageEventType.create( "GeckoDriverProvider would try to satisfy request for Firefox browser, but it was not configured with a path to the driver")); return null; }/*from w w w . java2 s. c om*/ if (!(path.exists())) { context.raiseEvent(MessageEventType.create( "GeckoDriverProvider would try to satisfy request for Firefox browser, but the configured path does not exist: " + path.getAbsolutePath())); return null; } synchronized (GeckoDriverProvider.class) { System.setProperty("webdriver.gecko.driver", path.getAbsolutePath()); DesiredCapabilities selenium_capabilities = DesiredCapabilities.firefox(); if (capabilities.getVersion() != null && capabilities.getVersion().length() > 0) selenium_capabilities.setVersion(capabilities.getVersion()); if (capabilities.getPlatform() != null && capabilities.getPlatform().length() > 0) selenium_capabilities.setPlatform(Platform.fromString(capabilities.getPlatform())); selenium_capabilities.setCapability("marionette", true); FirefoxOptions options = new FirefoxOptions(selenium_capabilities); if (getArguments() != null) options.addArguments(getArguments()); return new FirefoxDriver(options); } }