Search code examples
javaseleniumjvmgeckodriversystem-properties

How to initiate multiple versions of Geckodriver through System.setProperty()


I don't know if I'm overseeing something, but is it possible to use multiple geckodriver versions in the same JVM?

The problem is with

System.setProperty("webdriver.gecko.driver", "path of the geckodriver1");
driver1 = new FirefoxDriver();

System.setProperty("webdriver.gecko.driver", "path of the geckodriver2");
driver2 = new FirefoxDriver();

where I would define a system property. For a single instance this is no problem and working fine, but how can I define a FirefoxDriver with another geckodriver. Processes would run parallel so global settings would interfere with each other.

I know, that you can start multiple Firefox Session with the same driver, but I need to support different Firefox versions and am therefore looking for a solution with multiple geckodrivers as well.

Thanks in advice.


Solution

  • System Properties

    A program can use the System Properties objects to maintain its configuration throughout it's lifespan. Selenium's client itself uses the Properties object to maintain its own configuration. The System class maintains a Properties object that describes the configuration of the current working environment. System properties include information about the current user, the current version of the Java runtime, and the character used to separate components of a file path name.

    Hence, you won't be able to use multiple GeckoDriver versions within a single program.


    Demonstration

    A demonstration to extract the some of the most important system properties:

    • Code Block:

      package Java_Experiments;
      
      public class system_getProperty {
      
          public static void main(String[] args) {
      
              System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
              System.out.println(System.getProperty("webdriver.chrome.driver"));
              System.out.println(System.getProperty("subliminal.message", "Selenium WebDriver!"));
              System.out.println("Java Runtime Environment version: "+System.getProperty("java.version"));
              System.out.println("Java Runtime Environment vendor: "+System.getProperty("java.vendor"));
              System.out.println("Java vendor URL: "+System.getProperty("java.vendor.url"));
              System.out.println("Java installation directory: "+System.getProperty("java.home"));
          }
      }
      
    • Console Output:

      C:\Utility\BrowserDrivers\chromedriver.exe
      Selenium WebDriver!
      Java Runtime Environment version: 1.8.0_172
      Java Runtime Environment vendor: Oracle Corporation
      Java vendor URL: http://java.oracle.com/
      Java installation directory: C:\Program Files\Java\jdk1.8.0_172\jre