【问题标题】:Selenium with Java, IntelliJ and Gradle - The path to the driver executable must be set by the webdriver.gecko.driver system propertySelenium 与 Java、IntelliJ 和 Gradle - 驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置
【发布时间】:2018-11-14 14:25:12
【问题描述】:

我正在尝试运行我的测试(黄瓜、java、intelliJ),但我得到了这个异常线程:

java.lang.IllegalStateException: The path to the driver executable must be 
set by the webdriver.gecko.driver system property; for more information, see 
https://github.com/mozilla/geckodriver. The latest version can be downloaded 
from https://github.com/mozilla/geckodriver/releases

我正在使用 Selenium 3.141.5 和 Mozilla 63.0.1。

我试着用这本书来学习:“The Cucumber for Java Book” 有些解释与当前版本无关,因此我遇到了一些麻烦...... 但我希望你能帮助我

这是我的 build.gradle:

plugins {
    id 'java'
}

group 'cucumber_cash_withdrawal'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile 'io.cucumber:cucumber-java:2.4.0'
    testCompile 'io.cucumber:cucumber-junit:2.4.0'
    testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
    implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
    implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.5'
}

configurations {
    cucumberRuntime {
        extendsFrom testRuntime
    }
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']
        }
    }
}

apply plugin: 'java'

task runApp(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'cash_withdrawal.AtmServer'
}

【问题讨论】:

  • 你把 geckodriver 放在哪里了?地点在哪里?
  • C:\Users\..\Documents\geckodriver-v0.23.0-win64\geckodriver.exe 位于系统变量PATH中。

标签: java selenium gradle cucumber


【解决方案1】:

System.setProperty("webdriver.gecko.driver", pathToYourFirefoxExecutable);

【讨论】:

  • 在实例化驱动程序之前。除此之外,真的没关系。
  • 好的,谢谢。我试了一下,还是不行:(
猜你喜欢
  • 2017-02-04
  • 2016-12-05
  • 2017-09-11
  • 1970-01-01
  • 2017-12-21
  • 2017-03-16
  • 1970-01-01
  • 2017-09-07
  • 2020-03-14
相关资源
最近更新 更多