【问题标题】:Can we add drivers in selenium as maven depandancies我们可以在 selenium 中添加驱动程序作为 maven 依赖项吗
【发布时间】:2018-11-07 00:52:36
【问题描述】:

我们可以在 POM 中添加 gecko 驱动程序,即驱动程序或 chrome 驱动程序作为 depandancy 吗?我试图搜索但无法在https://mvnrepository.com/artifact 上对其进行罚款。有什么理由不将它们放在 Maven 存储库中?

【问题讨论】:

标签: maven selenium selenium-webdriver


【解决方案1】:

正如少数 cmets 所述,该驱动程序是可执行的二进制文件。 Maven 无法帮助您,因为它只是一个依赖存储库。目前要在 Firefox 上运行 selenium,我们需要编写:

System.setProperty("webdriver.gecko.driver", "driverpath/.exe");
WebDriver driver = new FirefoxDriver();

但是,我们有新的解决方案可以让我们摆脱第一行代码,并且您不再需要下载 dirver 二进制文件。它称为 WebDriverManager,它是一个可以使用 Maven pom 文件添加的依赖项。 这将在运行时使用最新版本号调用驱动程序。 你现在需要写的是:

WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();

并且需要在pom文件中添加这个依赖

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>2.2.1</version>
</dependency>

有关这方面的更多信息,请转到 Github 链接以检查驱动程序的所有其余部分,例如 chrome 、ie 等。WebDriverManagerLink

【讨论】:

    【解决方案2】:

    Check out this link for more clarification//在它会为 chrome 解决的行下面使用

        WebDriverManager.chromedriver().browserVersion("77.0.3865.40").setup();
    WebDriver driver = new ChromeDriver();
            
            driver.get("URL");
    

    //你还需要在POM文件中添加下面的依赖`

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>2.2.1</version>
    </dependency>`
    

    【讨论】:

      猜你喜欢
      • 2013-01-01
      • 2018-10-30
      • 1970-01-01
      • 2020-06-02
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多