在我的 pom
脚本中,我有:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
MVNrepository 上的存储库描述列出了几个编译依赖项,包括 Selenium-Chrome-Driver、Selenium-Firefox-Driver 等。我可以成功运行 Firefox-Driver 脚本,但是当我尝试运行相同的脚本时使用对象的脚本
ChromeDriver 驱动程序 = new ChromeDriver();
我收到以下错误:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
无需下载 Firefox 驱动程序即可使用(这就是 pom
脚本的要点); Chrome 驱动程序有什么不同吗?下图显示它是从 Maven 脚本编译的。
测试脚本:
import org.junit.Test;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.assertTrue;
public class MyFirstTest {
@Test
public void googleTest() {
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
assertTrue(driver.getTitle().equals("Google"));
driver.quit();
}
}
最佳答案
是的,它与 Firefox 不同,差异在 a page referenced by exception 上有解释。 :
The ChromeDriver consists of three separate pieces. There is the browser itself ("chrome"), the language bindings provided by the Selenium project ("the driver") and an executable downloaded from the Chromium project which acts as a bridge between "chrome" and the "driver". This executable is called "chromedriver", but we'll try and refer to it as the "server" in this page to reduce confusion.
因此,为了实例化 ChromeDriver,您需要
关于java - Maven 存储库中的 ChromeDriver 未在测试脚本中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39377593/