org.openqa.selenium.firefox.FirefoxOptions#setCapability ( )源码实例Demo

下面列出了org.openqa.selenium.firefox.FirefoxOptions#setCapability ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void usingAProxyToTrackNetworkTrafficStep2() {
    BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
    browserMobProxy.start();
    Proxy seleniumProxyConfiguration = ClientUtil.createSeleniumProxy(browserMobProxy);

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability(CapabilityType.PROXY, seleniumProxyConfiguration);
    driver = new FirefoxDriver(firefoxOptions);
    browserMobProxy.newHar();
    driver.get("https://www.google.co.uk");

    Har httpArchive = browserMobProxy.getHar();

    assertThat(getHTTPStatusCode("https://www.google.co.uk/", httpArchive))
            .isEqualTo(200);
}
 
源代码2 项目: restful-booker-platform   文件: DriverFactory.java
private WebDriver prepareRemoteDriver(){
    if(System.getenv("SAUCE_USERNAME") == null){
        throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs account name to the environmental variable 'sauce_username'");
    }

    if(System.getenv("SAUCE_ACCESS_KEY") == null){
        throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs access key to the environmental variable 'sauce_access_key'");
    }

    String URL = "http://" + System.getenv("SAUCE_USERNAME") + ":" + System.getenv("SAUCE_ACCESS_KEY") + "@ondemand.saucelabs.com:80/wd/hub";

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability("screenResolution", "1440x900");

    try {
        return new RemoteWebDriver(new URL(URL), firefoxOptions);
    } catch (MalformedURLException e) {
        throw new RuntimeException("WARN: An error occurred attempting to create a remote driver connection. See the following error: " + e);
    }
}
 
源代码3 项目: JYTB   文件: BotWorker.java
/**
     * Sets the webdriver to FireFox. We set our optimal parameters here
     * to ensure our proxy is set correctly.
     */
    private void setFirefoxDriver() {
        FirefoxOptions options = new FirefoxOptions();
        FirefoxProfile profile = new FirefoxProfile();
        FirefoxBinary binary = new FirefoxBinary(this.driverLocation);
        LoggingPreferences logPrefs = new LoggingPreferences();
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
        // hide firefox logs from console
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/tmp/rust_");

        profile.setPreference("media.volume_scale", "0.0");
        profile.setPreference("general.useragent.override", userAgent.randomUA());
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.http_port", this.proxies.getCurrentProxyModel().getPort());
        profile.setPreference("network.proxy.ssl", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.ssl_port", this.proxies.getCurrentProxyModel().getPort());

        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
        options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        options.setProfile(profile);
        options.setHeadless(true);
        options.setBinary(binary);
//        options.setProxy(this.proxies.getCurrentProxy());
        options.setCapability("proxy", this.proxies.getCurrentProxy());
        this.webDriver = new FirefoxDriver(options);

        Log.WINFO(this.workerName, this.workerColor, "Firefox Driver Set");
    }
 
@Test
public void usingAProxyToTrackNetworkTrafficStep1() {
    BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
    browserMobProxy.start();
    Proxy seleniumProxyConfiguration = ClientUtil.createSeleniumProxy(browserMobProxy);

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability(CapabilityType.PROXY, seleniumProxyConfiguration);
    driver = new FirefoxDriver(firefoxOptions);
    browserMobProxy.newHar();
    driver.get("https://www.google.co.uk");
}
 
@Override
protected FirefoxDriver createBrowser() {
    FirefoxOptions desiredCapabilities = new FirefoxOptions(createCapabilities());
    desiredCapabilities.setCapability(FirefoxDriver.PROFILE, createProfile());
    return new FirefoxDriver(new GeckoDriverService.Builder().usingFirefoxBinary(new FirefoxBinary()).build(),
            desiredCapabilities);
}
 
源代码6 项目: teasy   文件: FireFoxCaps.java
private FirefoxOptions getFirefoxOptions() {
    FirefoxOptions options = new FirefoxOptions();
    options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, this.alertBehaviour);
    options.setCapability(FirefoxDriver.MARIONETTE, false);
    options.setCapability(FirefoxDriver.PROFILE, createFirefoxProfile());
    options.setCapability("platform", platform);
    options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    setLoggingPrefs(options);
    return options;
}
 
源代码7 项目: teasy   文件: GeckoCaps.java
private FirefoxOptions getGeckoOptions() {
    FirefoxOptions options = new FirefoxOptions();
    options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, this.alertBehaviour);
    options.setCapability(FirefoxDriver.MARIONETTE, true);
    options.setCapability("platform", platform);
    options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    setLoggingPrefs(options);
    return options;
}
 
源代码8 项目: NoraUi   文件: DriverFactory.java
/**
 * 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));
    }
    log.info("Generating Firefox driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver);

    final FirefoxOptions firefoxOptions = new FirefoxOptions();
    final FirefoxBinary firefoxBinary = new FirefoxBinary();

    firefoxOptions.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    firefoxOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

    setLoggingLevel(firefoxOptions);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        firefoxOptions.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    if (Context.isHeadless()) {
        firefoxBinary.addCommandLineOptions("--headless");
        firefoxOptions.setBinary(firefoxBinary);
    }
    firefoxOptions.setLogLevel(FirefoxDriverLogLevel.FATAL);

    return new FirefoxDriver(firefoxOptions);
}
 
源代码9 项目: restful-booker-platform   文件: DriverFactory.java
private WebDriver prepareRemoteDriver(){
    if(System.getenv("SAUCE_USERNAME") == null){
        throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs account name to the environmental variable 'sauce_username'");
    }

    if(System.getenv("SAUCE_ACCESS_KEY") == null){
        throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs access key to the environmental variable 'sauce_access_key'");
    }

    String URL = "http://" + System.getenv("SAUCE_USERNAME") + ":" + System.getenv("SAUCE_ACCESS_KEY") + "@ondemand.saucelabs.com:80/wd/hub";

    FirefoxOptions firefoxOptions = new FirefoxOptions();

    firefoxOptions.setCapability("platformName", "Windows 10");
    firefoxOptions.setCapability("browserVersion", "65.0");

    MutableCapabilities sauceCaps = new MutableCapabilities();
    sauceCaps.setCapability("username", System.getenv("SAUCE_USERNAME"));
    sauceCaps.setCapability("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
    sauceCaps.setCapability("seleniumVersion", "3.141.59");
    sauceCaps.setCapability("name", "Restful-booker-platform");
    firefoxOptions.setCapability("sauce:options", sauceCaps);

    try {
        return new RemoteWebDriver(new URL(URL), firefoxOptions);
    } catch (MalformedURLException e) {
        throw new RuntimeException("WARN: An error occurred attempting to create a remote driver connection. See the following error: " + e);
    }
}
 
源代码10 项目: demo-java   文件: JUnit5W3CFirefoxTest.java
/**
 * @BeforeEach is a JUnit 5 annotation that defines specific prerequisite test method behaviors.
In the example below we:
- Define Environment Variables for Sauce Credentials ("SAUCE_USERNAME" and "SAUCE_ACCESS_KEY")
- Define Firefox Options such as W3C protocol
- Define the "sauce:options" capabilities, indicated by the "sauceOpts" MutableCapability object
- Define the WebDriver capabilities, indicated by the "caps" DesiredCapabilities object
- Define the service URL for communicating with SauceLabs.com indicated by "sauceURL" string
- Set the URL to sauceURl
- Set the driver instance to a RemoteWebDriver
- Pass "url" and "caps" as parameters of the RemoteWebDriver
For more information visit the docs: https://junit.org/junit5/docs/5.0.2/api/org/junit/jupiter/api/BeforeEach.html
 */

@BeforeEach
public void setup(TestInfo testInfo) throws MalformedURLException {
    String username = System.getenv("SAUCE_USERNAME");
    String accessKey = System.getenv("SAUCE_ACCESS_KEY");
    String methodName = testInfo.getDisplayName();

    /** FirefoxOptions allows us to set browser-specific behavior such as profile settings, headless capabilities, insecure tls certs,
     and in this example--the W3C protocol
     For more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxOptions.html */

    FirefoxOptions foxOpts = new FirefoxOptions();
    foxOpts.setCapability("w3c", true);

    /** The MutableCapabilities class  came into existence with Selenium 3.6.0 and acts as the parent class for
     all browser implementations--including the FirefoxOptions class extension.
     Fore more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/MutableCapabilities.html */

    MutableCapabilities sauceOpts = new MutableCapabilities();
    sauceOpts.setCapability("name", methodName);
    sauceOpts.setCapability("build", "Java-W3C-Examples");
    sauceOpts.setCapability("seleniumVersion", "3.141.59");
    sauceOpts.setCapability("username", username);
    sauceOpts.setCapability("accessKey", accessKey);
    sauceOpts.setCapability("tags", testInfo.getTags());


    /** Below we see the use of our other capability objects, 'foxOpts' and 'sauceOpts',
     defined in 'moz:firefoxOptions' and sauce:options respectively.
     */
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("moz:firefoxOptions",  foxOpts);
    caps.setCapability("sauce:options", sauceOpts);
    caps.setCapability("browserName", "firefox");
    caps.setCapability("browserVersion", "latest");
    caps.setCapability("platformName", "windows 10");

    /** Finally, we pass our DesiredCapabilities object 'caps' as a parameter of our RemoteWebDriver instance */
    String sauceUrl = "https://ondemand.saucelabs.com:443/wd/hub";
    URL url = new URL(sauceUrl);
    driver = new RemoteWebDriver(url, caps);
}
 
源代码11 项目: demo-java   文件: TestNGW3CFirefoxTest.java
/**
 * @BeforeMethod is a TestNG annotation that defines specific prerequisite test method behaviors.
In the example below we:
- Define Environment Variables for Sauce Credentials ("SAUCE_USERNAME" and "SAUCE_ACCESS_KEY")
- Define Firefox Options such as W3C protocol
- Define the "sauce:options" capabilities, indicated by the "sauceOpts" MutableCapability object
- Define the WebDriver capabilities, indicated by the "caps" DesiredCapabilities object
- Define the service URL for communicating with SauceLabs.com indicated by "sauceURL" string
- Set the URL to sauceURl
- Set the driver instance to a RemoteWebDriver
- Pass "url" and "caps" as parameters of the RemoteWebDriver
For more information visit the docs: http://static.javadoc.io/org.testng/testng/6.9.4/org/testng/annotations/BeforeMethod.html
 */
@BeforeMethod
public void setup(Method method) throws MalformedURLException {
    String username = System.getenv("SAUCE_USERNAME");
    String accessKey = System.getenv("SAUCE_ACCESS_KEY");
    String methodName = method.getName();

    /** FirefoxOptions allows us to set browser-specific behavior such as profile settings, headless capabilities, insecure tls certs,
     and in this example--the W3C protocol
     For more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxOptions.html */

    FirefoxOptions foxOpts = new FirefoxOptions();
    foxOpts.setCapability("w3c", true);

    /** The MutableCapabilities class  came into existence with Selenium 3.6.0 and acts as the parent class for
     all browser implementations--including the FirefoxOptions class extension.
     Fore more information see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/MutableCapabilities.html */

    MutableCapabilities sauceOpts = new MutableCapabilities();
    sauceOpts.setCapability("name", methodName);
    sauceOpts.setCapability("build", "Java-W3C-Examples");
    sauceOpts.setCapability("seleniumVersion", "3.141.59");
    sauceOpts.setCapability("username", username);
    sauceOpts.setCapability("accessKey", accessKey);
    sauceOpts.setCapability("tags", "w3c-chrome-tests");

    /** Below we see the use of our other capability objects, 'foxOpts' and 'sauceOpts',
     defined in 'moz:firefoxOptions' and sauce:options respectively.
     */
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("moz:firefoxOptions",  foxOpts);
    caps.setCapability("sauce:options", sauceOpts);
    caps.setCapability("browserName", "firefox");
    caps.setCapability("browserVersion", "latest");
    caps.setCapability("platformName", "windows 10");

    /** Finally, we pass our DesiredCapabilities object 'caps' as a parameter of our RemoteWebDriver instance */
    String sauceUrl = "https://ondemand.saucelabs.com:443/wd/hub";
    URL url = new URL(sauceUrl);
    driver = new RemoteWebDriver(url, caps);
}