如何通过System.setProperty()初始化多个版本的Geckodriver [英] How to initiate multiple versions of Geckodriver through System.setProperty()
问题描述
我不知道自己是否在监督什么,但是是否可以在同一个JVM中使用多个geckodriver版本?
I don't know if I'm overseeing something, but is it possible to use multiple geckodriver versions in the same JVM?
问题出在
System.setProperty("webdriver.gecko.driver", "path of the geckodriver1");
driver1 = new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "path of the geckodriver2");
driver2 = new FirefoxDriver();
我将在其中定义系统属性.对于单个实例,这没有问题并且可以正常工作,但是如何使用另一个geckodriver定义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.
我知道,您可以使用相同的驱动程序启动多个Firefox会话,但是我需要支持不同的Firefox版本,因此也在寻找具有多个geckodrivers的解决方案.
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.
感谢您的咨询.
推荐答案
系统属性
程序可以使用系统属性对象来在整个生命周期中保持其配置. 硒的
System Properties
A program can use the System Properties objects to maintain its configuration throughout it's lifespan. Selenium's java 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.
因此,您将无法在单个程序中使用多个 GeckoDriver 版本.
Hence, you won't be able to use multiple GeckoDriver versions within a single program.
展示一些最重要的系统属性的演示:
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
这篇关于如何通过System.setProperty()初始化多个版本的Geckodriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!