Java Code Examples for org.openqa.selenium.firefox.FirefoxOptions#setCapability()

The following examples show how to use org.openqa.selenium.firefox.FirefoxOptions#setCapability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyBasedIT.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 6 votes vote down vote up
@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);
}
 
Example 2
Source File: DriverFactory.java    From restful-booker-platform with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: BotWorker.java    From JYTB with GNU General Public License v3.0 5 votes vote down vote up
/**
     * 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");
    }
 
Example 4
Source File: ProxyBasedIT.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
@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");
}
 
Example 5
Source File: FirefoxDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: FireFoxCaps.java    From teasy with MIT License 5 votes vote down vote up
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;
}
 
Example 7
Source File: GeckoCaps.java    From teasy with MIT License 5 votes vote down vote up
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;
}
 
Example 8
Source File: DriverFactory.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: DriverFactory.java    From restful-booker-platform with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: JUnit5W3CFirefoxTest.java    From demo-java with MIT License 4 votes vote down vote up
/**
 * @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);
}
 
Example 11
Source File: TestNGW3CFirefoxTest.java    From demo-java with MIT License 4 votes vote down vote up
/**
 * @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);
}