Welcome to EliteQing's Blog

Java Code Examples for PhantomJSDriverService

Example 1
Project: thucydides   File: PhantomJSCapabilityEnhancer.java View source code Vote up 6 votes
public void enhanceCapabilities(DesiredCapabilities capabilities) {
    if (environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH) != null) {
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH));
    }

    ArrayList<String> cliArgs = Lists.newArrayList();
    setSecurityOptions(cliArgs);
    setLoggingOptions(cliArgs);
    if (StringUtils.isNotEmpty(ThucydidesSystemProperty.THUCYDIDES_PROXY_HTTP.from(environmentVariables))) {
        setProxyOptions(cliArgs);
    }
    if (StringUtils.isNotEmpty(ThucydidesSystemProperty.WEBDRIVER_REMOTE_URL.from(environmentVariables))) {
        setRemoteOptions(cliArgs);
    }
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs.toArray(new String[]{}));
}
Example 2
Project: seauto   File: AbstractConfigurableDriverProvider.java View source code Vote up 6 votes
/**
 * Default implementation throws UnsupportedOperationException
 */
protected WebDriver getPhantomJsWebDriver()
{
  String pathToBin = getOsSpecificBinaryPathFromProp(PHANTOM_JS_BIN_PROP, "phantomjs");

  DesiredCapabilities capabilities = getPhantomJsCapabilities();
  capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathToBin);

  return new PhantomJSDriver(capabilities);

}

Example 3
Project: serenity-core   File: PhantomJSCapabilityEnhancer.java View source code Vote up 6 votes
public void enhanceCapabilities(DesiredCapabilities capabilities) {
    if (environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH) != null) {
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH));
    }

    ArrayList<String> cliArgs = Lists.newArrayList();
    setSecurityOptions(cliArgs);
    setLoggingOptions(cliArgs);

    if (StringUtils.isNotEmpty(ThucydidesSystemProperty.THUCYDIDES_PROXY_HTTP.from(environmentVariables))) {
        setProxyOptions(cliArgs);
    }
    if (StringUtils.isNotEmpty(ThucydidesSystemProperty.WEBDRIVER_REMOTE_URL.from(environmentVariables))) {
        setRemoteOptions(cliArgs);
    }
    if (StringUtils.isNotEmpty(ThucydidesSystemProperty.PHANTOMJS_SSL_PROTOCOL.from(environmentVariables))) {
        String sslSupport = ThucydidesSystemProperty.PHANTOMJS_SSL_PROTOCOL.from(environmentVariables);
        if (sslSupport.equals("sslv2") ||
                sslSupport.equals("sslv3") ||
                sslSupport.equals("tlsv1") ||
                sslSupport.equals("any")) {
            cliArgs.add("--ssl-protocol=" + sslSupport);
        }
        else {
            cliArgs.add("--ssl-protocol=any");
        }
    }
    else {
        cliArgs.add("--ssl-protocol=any");
    }

    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs.toArray(new String[]{}));
}
Example 4
Project: ya.blogo   File: PhantomJSRule.java View source code Vote up 6 votes
@Override
public void before() {
    File phantomjs = Phanbedder.unpack();
    DesiredCapabilities dcaps = new DesiredCapabilities();
    dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
    driver = new PhantomJSDriver(dcaps);
}

Example 5
Project: dextranet   File: TesteFuncionalBase.java View source code Vote up 6 votes
@BeforeClass
public static void setup() {
	server.enableAuthentication(true, false);
	server.enableJetty(8080);
	TesteIntegracaoBase.setup();
	
	String executable = "";
	if (isWindows()) {
		executable = "target/phantomjs/phantomjs.exe";
	} else {
		executable = "target/phantomjs/phantomjs";
	}
	
	DesiredCapabilities dCaps = new DesiredCapabilities();
	dCaps.setJavascriptEnabled(true);
	dCaps.setCapability("takesScreenshot", false);
	dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, executable);
	driver = new PhantomJSDriver(dCaps);
	driver.manage().window().setSize(new Dimension(1600, 900));
}
Example 6
Project: seleniumQuery   File: PhantomJSDriverBuilderTest.java View source code Vote up 6 votes
@Test
public void withCapabilities() {
    // given
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX+"userAgent", "JustAnotherAgent");
    // when
    $.driver().usePhantomJS().withCapabilities(capabilities);
    // then
    $.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
    assertThat($("#agent").html(), containsString("JustAnotherAgent"));
}
Example 7
Project: XBDD   File: XbddDriver.java View source code Vote up 6 votes
private static WebDriver getPhantomJsDriver() {
	final DesiredCapabilities caps = DesiredCapabilities.phantomjs();

	caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
			new String[] { "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=false" });

	final PhantomJSDriver phantomJSDriver = new PhantomJSDriver(caps);
	phantomJSDriver.manage().window().setSize(new Dimension(1280, 800));
	return phantomJSDriver;
}
Example 8
Project: nitrogen   File: NitrogenPhantomJsDriver.java View source code Vote up 6 votes
private static DesiredCapabilities initBrowserCapabilities() {
    DesiredCapabilities browserCapabilities = new DesiredCapabilities();

    browserCapabilities.setJavascriptEnabled(true);
    if (StringUtils.isNotEmpty(PHANTOM_JS_PATH_PROP)) {
        System.out.printf("\n\nSetting Phantom JS path to %s\n\n%n", PHANTOM_JS_PATH_PROP);
        browserCapabilities.setCapability(
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                PHANTOM_JS_PATH_PROP);
    }
    browserCapabilities.setCapability("takesScreenshot", true);
    browserCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, buildPhantomJsCommandLineArguments());
    browserCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[]{
            formatArgument(LOG_LEVEL_ARG, ERROR)
    });

    return browserCapabilities;
}
Example 9
Project: crawljax   File: WebDriverBrowserBuilder.java View source code Vote up 6 votes
private EmbeddedBrowser newPhantomJSDriver(ImmutableSortedSet<String> filterAttributes,
        long crawlWaitReload, long crawlWaitEvent) {

	DesiredCapabilities caps = new DesiredCapabilities();
	caps.setCapability("takesScreenshot", true);
	caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[]{"--webdriver-loglevel=WARN"});
	final ProxyConfiguration proxyConf = configuration
			.getProxyConfiguration();
	if (proxyConf != null && proxyConf.getType() != ProxyType.NOTHING) {
		final String proxyAddrCap = "--proxy=" + proxyConf.getHostname()
				+ ":" + proxyConf.getPort();
		final String proxyTypeCap = "--proxy-type=http";
		final String[] args = new String[] { proxyAddrCap, proxyTypeCap };
		caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args);
	}
	
	PhantomJSDriver phantomJsDriver = new PhantomJSDriver(caps);

	return WebDriverBackedEmbeddedBrowser.withDriver(phantomJsDriver, filterAttributes,
	        crawlWaitEvent, crawlWaitReload);
}
Example 10
Project: handytrowel   File: HTMLFetcher.java View source code Vote up 6 votes
public String getPageSource(final String url) throws TimeoutException {

        // Make the Selenium WebDriver logs be quiet
        phantomJsLogger.setLevel(Level.OFF);

        DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs();
        // What other CLI args there are: http://phantomjs.org/api/command-line.html
        // Where the cache goes on Mac OS X: ~/Library/Application\ Support/Ofi\ Labs/PhantomJS/
        // Other cache locations: https://groups.google.com/forum/#!topic/phantomjs/8GYaXKmowj0
        desiredCapabilities.setCapability(
            PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
            new String[] {"--ignore-ssl-errors=yes", "--load-images=no",
                          "--disk-cache=true", "--max-disk-cache-size=size=51200"
                         });
        final WebDriver driver = new PhantomJSDriver(desiredCapabilities);

        // doesn't work, keep as reference.
        //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        try {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    driver.get(url);
                }
            });
            t.start();
            try {
                t.join(timeoutMillis);
            } catch (InterruptedException e) {
            }
            if (t.isAlive()) {
                System.out.println("Timeout for HTTP GET to: " + url);
                t.interrupt();
                throw new TimeoutException();
            }
            String pageSource = driver.getPageSource();
            return pageSource;
        } finally {
            driver.quit();
        }
    }
Example 11
Project: adf-selenium   File: PhantomJSDriverResource.java View source code Vote up 6 votes
@Override
protected RemoteWebDriver createDriver(String language) {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", language);
    PhantomJSDriver retval = new PhantomJSDriver(caps);
    return retval;
}
Example 12
Project: Web-snapshot   File: SnapshotCreatorImpl.java View source code Vote up 6 votes
/**
 *
 * @return
 */
private RemoteWebDriver getWebDriver(int windowWidth, int windowHeight, String webDriver) {
    RemoteWebDriver driver;
    if (webDriver.equals(FIREFOX_BROWSER_NAME)) {
        driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxBinaryPath)), new FirefoxProfile());
    } else {
        DesiredCapabilities caps = DesiredCapabilities.phantomjs();
        caps.setCapability(
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                phantomJsBinaryPath);
        driver = new PhantomJSDriver(caps);
    }
    driver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
    return driver;
}
Example 13
Project: burp-csj   File: SetupCrawljax.java View source code Vote up 6 votes
private EmbeddedBrowser newPhantomBrowser() {
    String phantompath = CrawlPanel.phatomjslocation.getText();
    File file = new File(phantompath);
    DesiredCapabilities capability = new DesiredCapabilities();
    capability.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, file.getAbsolutePath());
    if (CrawlPanel.manualproxy.isSelected()) {
        String host = CrawlPanel.HostProxy.getText();
        Integer port = Integer.parseInt(CrawlPanel.PortProxy.getText());
        String PROXY = host + ":" + port;
        org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
        proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
        capability.setCapability(CapabilityType.PROXY, proxy);
    }
    capability.setCapability("takesScreenshot", false);
    String[] args = {"--ignore-ssl-errors=yes"};
    capability.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args);
    capability.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0");
    //System.out.println("Capability:" +capability);
    WebDriver drivertest = null;
    try {
        drivertest = new PhantomJSDriver(capability);
    } catch (Throwable e) {
        JOptionPane.showMessageDialog(null, "PhantomJS Location not specified");
        CrawlPanel.Browser.setSelectedItem("Firefox");
    }
    
    if (CrawlPanel.burpcookie.isSelected()) {
        setCookies(drivertest, "PhantomBrowser");
    }
    
    return WebDriverBackedEmbeddedBrowser.withDriver(drivertest);
}
Example 14
Project: Tanaguru   File: PhantomJsFactory.java View source code Vote up 6 votes
/**
 * 
 * @param config
 * @return A FirefoxDriver.
 */
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);
    if (System.getProperty(PHANTOMJS_PATH_PROPERTY) != null) {
        path = System.getProperty(PHANTOMJS_PATH_PROPERTY);
    }
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                    path);
    return new PhantomJSDriver(caps);
}
Example 15
Project: selenese-runner-java   File: PhantomJSDriverFactory.java View source code Vote up 6 votes
@Override
public WebDriver newInstance(DriverOptions driverOptions) {
    DesiredCapabilities caps = setupProxy(DesiredCapabilities.phantomjs(), driverOptions);
    if (driverOptions.has(PHANTOMJS)) {
        File binary = new File(driverOptions.get(PHANTOMJS));
        if (!binary.canExecute())
            throw new IllegalArgumentException("Missing PhantomJS binary: " + binary);
        caps.setCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary.getPath());
    }
    caps.merge(driverOptions.getCapabilities());
    if (driverOptions.has(CLI_ARGS)) {
        Object cliArgs = caps.getCapability(PHANTOMJS_CLI_ARGS);
        if (cliArgs == null) {
            cliArgs = ArrayUtils.EMPTY_STRING_ARRAY;
        } else {
            if (cliArgs instanceof String)
                cliArgs = new String[] { (String) cliArgs };
            else if (!(cliArgs instanceof String[]))
                throw new IllegalArgumentException("Invalid " + PHANTOMJS_CLI_ARGS + ": " + cliArgs);
        }
        cliArgs = ArrayUtils.addAll((String[]) cliArgs, driverOptions.getCliArgs());
        caps.setCapability(PHANTOMJS_CLI_ARGS, cliArgs);
    }
    PhantomJSDriverService service = CustomPhantomJSDriverServiceFactory.createDefaultService(caps);
    PhantomJSDriver driver = new PhantomJSDriver(service, caps);
    setInitialWindowSize(driver, driverOptions);
    return driver;
}
Example 16
Project: jmeter-plugins   File: PhantomJSDriverConfig.java View source code Vote up 6 votes
protected Capabilities createCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, createProxy());
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            getPhantomJsExecutablePath());
    return capabilities;
}
Example 17
Project: arquillian-extension-drone   File: PhantomJSDriverFactory.java View source code Vote up 6 votes
@Override
public PhantomJSDriver createInstance(WebDriverConfiguration configuration) {

    // resolve capabilities
    DesiredCapabilities capabilities = new DesiredCapabilities(configuration.getCapabilities());

    String executablePath = (String) capabilities.getCapability(PHANTOMJS_EXECUTABLE_PATH);

    if (Validate.empty(executablePath)) {
        executablePath = SecurityActions.getProperty(PHANTOMJS_EXECUTABLE_PATH);
    }

    if (Validate.empty(executablePath)) {
        capabilities.setCapability(PHANTOMJS_EXECUTABLE_PATH, new File("target/drone-phantomjs").getAbsolutePath());
    }

    try {
        return SecurityActions.newInstance(configuration.getImplementationClass(), new Class<?>[] { PhantomJSDriverService.class, Capabilities.class },
            new Object[] { ResolvingPhantomJSDriverService.createDefaultService(capabilities), capabilities }, PhantomJSDriver.class);
    } catch (IOException e) {
        throw new IllegalStateException("Unable to create an instance of " + configuration.getImplementationClass() + ".", e);
    }
}
Example 18
Project: What-Did-You-Download   File: SeleniumBase.java View source code Vote up 5 votes
private static DesiredCapabilities generateDesiredCapabilities(BrowserType capabilityType) {
    DesiredCapabilities capabilities;

    switch (capabilityType) {
        case IE:
            capabilities = DesiredCapabilities.internetExplorer();
            capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
            capabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, true);
            capabilities.setCapability("requireWindowFocus", true);
            break;
        case SAFARI:
            capabilities = DesiredCapabilities.safari();
            capabilities.setCapability("safari.cleanSession", true);
            break;
        case OPERA:
            capabilities = DesiredCapabilities.opera();
            capabilities.setCapability("opera.arguments", "-nowin -nomail");
            break;
        case GHOSTDRIVER:
            capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability("takesScreenshot", true);
            if (System.getProperties().getProperty("os.arch").toLowerCase().equals("x86_64") || System.getProperties().getProperty("os.arch").toLowerCase().equals("amd64")) {
                if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/windows/phantomjs/64bit/1.9.2/phantomjs.exe");
                } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/osx/phantomjs/64bit/1.9.2/phantomjs");
                } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/linux/phantomjs/64bit/1.9.2/phantomjs");
                }
            } else {
                if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/windows/phantomjs/32bit/1.9.2/phantomjs.exe");
                } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/osx/phantomjs/32bit/1.9.2/phantomjs");
                } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/linux/phantomjs/32bit/1.9.2/phantomjs");
                }
            }
            break;
        case CHROME:
            capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("chrome.switches", Arrays.asList("--no-default-browser-check"));
            HashMap<String, String> chromePreferences = new HashMap<String, String>();
            chromePreferences.put("profile.password_manager_enabled", "false");
            capabilities.setCapability("chrome.prefs", chromePreferences);
            break;case FIREFOX:default:FirefoxProfile firefoxProfile =newFirefoxProfile();
            firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force",false);
            firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
            firefoxProfile.setPreference("browser.download.dir","/tmp/selenium-talk");
            firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/zip");
            capabilities =DesiredCapabilities.firefox();
            capabilities.setCapability("firefox_profile", firefoxProfile);}return capabilities;}
Example 19
Project: senbot   File: TestEnvironment.java View source code Vote up 5 votes
/**
     * Delegation method to construct the WebDriver
     */
    private WebDriver constructWebDriver() {
        log.debug("constructWebDriver called on TestEnvironment: " + this.toPrettyString());

        SeleniumManager seleniumManager = SenBotContext.getSenBotContext().getSeleniumManager();

        WebDriver driver = null;
        if (seleniumManager.getSeleniumHub() != null) {

            log.debug("Remote WebDriver should be created to run on a selenium grid for environment: " + this.toPrettyString());
            
            if(getLocale() != null) {
        		throw new IllegalArgumentException("The remote driver does not support the setting of a locale");
        	}

            DesiredCapabilities capability = DesiredCapabilities.firefox();
            if (TestEnvironment.FF.equals(browser)) {
                capability = DesiredCapabilities.firefox();
            } else if (TestEnvironment.CH.equals(browser)) {
                capability = DesiredCapabilities.chrome();
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability("chrome.switches", Arrays.asList("--disable-logging", "--disable-extensions"));
            } else if (TestEnvironment.OP.equals(browser)) {
                capability = DesiredCapabilities.opera();
            } else if (TestEnvironment.IE.equals(browser)) {
                capability = DesiredCapabilities.internetExplorer();
            } else if (TestEnvironment.SF.equals(browser)) {
                capability = DesiredCapabilities.safari();
            } else if (BrowserType.PHANTOMJS.equals(browser)) {
            	capability = DesiredCapabilities.phantomjs();
            } else {
                throw new IllegalArgumentException("Browser value is not correct: " + browser);
            }
            
//            capability.setCapability("selenium-version", "2.33.0");
            capability.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
            capability.setVersion(browserVersion);
            capability.setPlatform(os);

            // Set BrowserStack specific environment only if browserstack is used - see also: https://www.browserstack.com/automate/java
            if( seleniumManager.getSeleniumHub().toString().indexOf("browserstack") >= 0) {
            	capability.setCapability("browserstack.debug", "true");
            }

            RemoteWebDriver remoteWebDriver = new RemoteWebDriver(seleniumManager.getSeleniumHub(), capability);
			driver = new Augmenter().augment(remoteWebDriver);
           
            
        } else {

            log.debug("Local WebDriver should be created to run on this local machine for environment: " + this.toPrettyString());
            
            if (TestEnvironment.FF.equals(browser)) {
            	FirefoxProfile p = new FirefoxProfile();
            	p.setAssumeUntrustedCertificateIssuer(false); 
            	if(getLocale() != null) {
            		p.setPreference("intl.accept_languages", getLocale().toString());
            	}
            	driver = new FirefoxDriver(p);
            } else if (TestEnvironment.CH.equals(browser)) {
            	ChromeOptions options = new ChromeOptions();
            	
            	
                StringBuilder switcheStringBuilder = new StringBuilder();
                if(getLocale() != null) {  
                	options.addArguments("--lang="+ getLocale().getLanguage());}
                options.addArguments("--silent");//                LoggingPreferences logs = new LoggingPreferences();//                logs.enable(LogType.DRIVER, Level.FINE);//                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                options.addArguments("--"+CapabilityType.LOGGING_PREFS +"={driver:'FINE'}");//                capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);//                capabilities.setCapability("chrome.switches", switcheStringBuilder.toString());
                
                driver =newChromeDriver(options);}elseif(TestEnvironment.OP.equals(browser)){if(getLocale()!=null){thrownewIllegalArgumentException("Opera does not support the setting of a locale at this stage");}
                driver =newOperaDriver();}elseif(TestEnvironment.IE.equals(browser)){if(getLocale()!=null){thrownewIllegalArgumentException("IE does not support the setting of a locale at this stage");}
                driver =newInternetExplorerDriver();}elseif(TestEnvironment.SF.equals(browser)){if(getLocale()!=null){thrownewIllegalArgumentException("Safari does not support the setting of a locale at this stage");}
                driver =newSafariDriver();}elseif(BrowserType.PHANTOMJS.equals(browser)){if(getLocale()!=null){thrownewIllegalArgumentException("PhantomJS does not support the setting of a locale at this stage");}try{//service_log_path='/var/log/phantomjs/ghostdriver.logDesiredCapabilities phantomJsCapabilities =DesiredCapabilities.phantomjs();
            		phantomJsCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"target/logs/phantomjs.log"); 
            		driver =newPhantomJSDriver(phantomJsCapabilities);}catch(Exception e){thrownewRuntimeException(e);}}else{thrownewIllegalArgumentException("Browser value is not correct: "+ browser);}}if(seleniumManager.getImplicitTimeout()!=null){int timeout = seleniumManager.getImplicitTimeout();if(driver instanceofInternetExplorerDriver){// IE is said to be much slower the the other browsers
                timeout = timeout *2;}

            driver.manage().timeouts().implicitlyWait(timeout,TimeUnit.SECONDS);}

        driver.manage().window().setSize(newDimension(seleniumManager.getDefaultWindowWidth(), seleniumManager.getDefaultWindowHeight()));return driver;}
posted @ 2016-06-24 02:04  EliteQing  阅读(693)  评论(0编辑  收藏  举报