Tests on specific Firefox versions

The Firefox binary lets you run tests on your favorite Firefox versions. In order to do that, perform the following steps:

  1. Install multiple versions of Firefox on your PC (say, FF 26 and FF 28). Make sure that the Mozilla Firefox versions are installed at different path locations using custom installation.
  2. Add the following imports in your test code:
    import java.io.File;
    import org.openqa.selenium.firefox.FirefoxBinary;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
  3. Locate the secondary Firefox executable path in the Firefox binary.
  4. Create a Firefox profile and initialize WebDriver as shown in the following code snippet:
    FirefoxBinary binary = new FirefoxBinary(new File("C://Program Files//Mozilla Firefox26//firefox.exe"));
    FirefoxProfile profile = new FirefoxProfile();
    WebDriver driver = new FirefoxDriver(binary, profile);
  5. For Python bindings, use a similar scenario and add the following code snippet:
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    driver = webdriver.Firefox (firefox_binary=FirefoxBinary("C://Program Files//Mozilla Firefox26//firefox.exe"))

Tests from the custom Firefox profile

In general, custom profiles are used in order to get rid of control over existing cookies that contain history, bookmarks, passwords, personal information, and so on.

Firefox Profile Manager is used to create or remove Firefox profiles. To create a Firefox profile, perform the following steps:

  1. Open the Run command window (using Windows Key + R), type firefox.exe –p and click on OK.

    Note

    Mozilla Firefox must be closed before opening the Firefox Profile Manager. If the Profile Manager window does not open, Firefox must be running in the background. Close all instances of Firefox, restart the computer, and then try again to solve the issue.

    Tests from the custom Firefox profile
  2. Create a Firefox profile (for example, myProjectProfile) by clicking on the Create Profile button from the profile manager.
  3. Add the following snippet in your test code to run tests from the new,customized Firefox profile:
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfilemyprofile = profile.getProfile("myProjectProfile");
    WebDriver driver = new FirefoxDriver(myprofile);

In Linux, Firefox native events are disabled by default as they may launch more than one browser in parallel in a test. To enable such default Firefox-disabled features, the native events insist on being set to true, as shown in the following code:

FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.132.99