Frage

I am using gradle to download the selenium chrome driver from maven

webtestsCompile 'org.seleniumhq.selenium:selenium-chrome-driver:2.32.0'

I am trying to use this directly and I see that I get this error :

  Caused by:
    java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list

I have looked up a couple of questions from stack-overflow and other places it requires me to set the value of the property webdriver.chrome.driver to the location where I have downloaded with some-thing like this :

System.setProperty("webdriver.chrome.driver", "path to chrome-driver");

I am wondering what is the best way to go about this ?

EDIT 1:

I verified the java.class.path a snippet of this path looks like this :

/home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar

This looks like the selenium-chrome-driver is present in the java.class.path.

Edit 2 :

I would want the chrome driver to work irrespective of the operating system that I am using, currently I am on a ubuntu box but a lot of this will get tested on a windows box. When I hard coded the value of the webdriver.chrome.driver to the value in EDIT 1, I am facing the following issue :

 java.lang.IllegalStateException: The driver is not executable: /home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar

Edit 3 :

Task within which I am running the test suite --

task webs(type: Test, dependsOn: updateNodeModules) {
testClassesDir = sourceSets.webtests.output.classesDir
classpath = sourceSets.webtests.runtimeClasspath

def javaHomeBin = new File(System.getProperty("java.home"), "bin");
def javaExec = new File(javaHomeBin, "java").getAbsolutePath();

systemProperties['jar.path'] = jar.archivePath

if(project.hasProperty('url')){
  println" url passed as variable is $url"
  systemProperties["selenium.webdriver.url"] = "$url"
 }
 systemProperties["selenium.webbrowser.type"] = "firefox"
 if(project.hasProperty('browser')){
 println "the browser passed is $browser"
 systemProperties["selenium.webbrowser.type"] = "$browser"
 }


include '**/UserEditControllerWebTest.class'

doFirst {
println " iterator is $it"
  def chrome=configurations.testRuntime.find { 
        it.name.contains("selenium-chrome-driver")
    }.path
    println " chrome driver path is $chrome"
    systemProperties["webdriver.chrome.driver"]= "$chrome"
  }

}

War es hilfreich?

Lösung

Assuming that you need to set this system property for your tests, you can do something like:

test.doFirst {
    systemProperty "webdriver.chrome.driver", 
        classpath.find { 
            it.name.contains("selenium-chrome-driver")
        }.path
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top