繁体   English   中英

在Maven中设置了selenium-java依赖项,但Selenium要求提供驱动程序的路径

[英]selenium-java dependency set in Maven, but Selenium asks for the path to the driver

我在Maven中设置了selenium-java依赖项:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.7.1</version>
</dependency>

但是,当我运行简单测试时-我得到一个例外,即未设置The path to the driver executable must be set by the webdriver.chrome.driver system propertyThe path to the driver executable must be set by the webdriver.chrome.driver system property

设置Maven依赖关系对Selenium来说还不够吗? 我缺少Selenium无法读取Maven依赖项的信息吗?

设置Maven依赖关系对Selenium来说还不够吗?

不,您需要使用类似以下命令告诉它在哪里可以找到Web驱动程序:

System.setProperty("webdriver.chrome.driver", complete_path_to_your_chrome_driver_executable_here);

应该解决这个问题。

您可以直接在pom.xml中进行类似的配置,方法是在包含路径的属性部分中定义一个属性,并在maven-surefire-plugin的配置部分中使用systemPropertyVariables。

例如:

在pom.xml的Properties部分中创建

<webriver.path>path_to_your_driver_executable</webriver.path>

然后在您的maven-surefire-plugin的configuration部分中添加systemPropertyVariables部分

<systemPropertyVariables>
   <webdriver.chrome.driver>${webriver.path}</webdriver.chrome.driver>
   [...]
</systemPropertyVariables>

暂无
暂无

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

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