简体   繁体   English

如何通过 System.setProperty() 启动多个版本的 Geckodriver

[英]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?我不知道我是否在监督某些事情,但是是否可以在同一个 JVM 中使用多个 geckodriver 版本?

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.对于单个实例,这没有问题并且工作正常,但是如何使用另一个 geckodriver 定义 FirefoxDriver。 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.我知道,您可以使用相同的驱动程序启动多个 Firefox 会话,但我需要支持不同的 Firefox 版本,因此我也在寻找具有多个 geckodrivers 的解决方案。

Thanks in advice.谢谢指教。

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. Selenium客户端本身使用Properties对象来维护自己的配置。 The System class maintains a Properties object that describes the configuration of the current working environment. System类维护一个Properties对象,该对象描述当前工作环境的配置。 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.系统属性包括有关当前用户、Java 运行时的当前版本以及用于分隔文件路径名组成部分的字符的信息。

Hence, you won't be able to use multiple GeckoDriver versions within a single program.因此,您将无法在单个程序中使用多个GeckoDriver版本。


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM