Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How do I change the browser that a JUnit test in Eclipse runs on?

Speedy993
Speedy993 Posts: 40

I recorded a web session using the Parasoft Recorder in Chrome and it runs well using Chrome in Eclipse but I would like to run it in Microsoft Edge. Looking at the Parasoft Preferences, I have the Selenium WebDriver location specified for Chrome and it is not required for Edge. Showing the Command Line in the Selenic Configurations, shows jar files (3.141.59) for Safari, Opera, IE, Firefox, Edge, and Chrome. However I don't see any place to change which browser is used to run the JUnit test.
Also, is it possible to change the version of ChromeDriver associated with a JUnit test after it has been created. I have a few tests that were created using Parasoft Recorder in an older version of Chrome. In there a way to update it to run in a new version of Chrome, or Edge?
Thanks!

Best Answer

  • benken_parasoft
    benken_parasoft Posts: 1,086 ✭✭✭
    edited July 13 Answer ✓

    I have the Selenium WebDriver location specified for Chrome and it is not required for Edge.

    It is not required for Edge Legacy. However, the current Chromium-based Edge requires the path to an "msedgedriver" executable. In the launch configuration for your Selenium test you need to add the JVM argument -Dwebdriver.edge.driver={path_to_msedgedriver_exe}. In a future Selenic release, I believe the preferences will be updated to allow you to specify the path to msedgedriver instead of having to manually set a JVM argument in the launch configuration for your Selenium test.

    I don't see any place to change which browser is used to run the JUnit test.

    This is controlled by the Selenium test itself. Look for this line:

    driver = new ChromeDriver();
    

    You can change that to something else like "new EdgeDriver()" or "new FirefoxDriver()".

    is it possible to change the version of ChromeDriver associated with a JUnit test after it has been created

    The version of ChromeDriver has to match the version of Google Chrome that is installed on the local machine where playback occurs. If you update Google Chrome then you typically need to download a new, matching version of ChromeDriver. The same is true for the WebDriver for Microsoft Edge.

    In there a way to update it to run in a new version of Chrome, or Edge?

    The locators that are created in the Selenium test should work in general, regardless of what version and/or browser you intend to use for playback.

Answers

  • benken_parasoft
    benken_parasoft Posts: 1,086 ✭✭✭
    edited July 13

    You can also consider modifying the code in your Selenium test to instantiate either ChromeDriver or EdgeDriver based on some condition, like a Java system property.

    For example:

    String browserName = System.getProperty("browserName");
    if (browserName.equalsIgnoreCase("chrome")) {
        driver = new ChromeDriver();
    } else if (browserName.equalsIgnoreCase("edge")) {
        driver = new EdgeDriver();
    } else if (browserName.equalsIgnoreCase("firefox")) {
        driver = new FirefoxDriver();
    } else if (browserName.equalsIgnoreCase("safari")) {
        driver = new SafariDriver();
    } // etc.
    

    In the launch configuration for your Selenium test you can add a JVM argument like -DbrowserName=edge

    You configure JVM arguments in the launch configuration's "Arguments" tab in the "VM arguments" text field.