Geb test ignoring GebConfig.groovy file launched in IntelliJ

为君一笑 提交于 2019-12-13 04:11:29

问题


Running in IntelliJ IDEA. GebConfig.groovy is in /src/test/resources.

I am using the Chrome driver.

When I type System.setProperty("webdriver.chrome.driver", "my/path") inside my spec file, and I right click and select run, the test works, meaning it opens Chrome and loads the page.

When I don't do that in the spec file, but just leave it in the GebConfig.groovy file, I get the error message "the page to the driver executable must be set".

There's an air-gap, so I can't copy-paste; I'll type as much as I can here: GebConfig.groovy:

import org.openqa.selenium.chrome.ChromeDriver

...

environments {
    chrome {
        System.setProperty("webdriver.chrome.driver", "my/path")
        driver = {new ChromeDriver()}
    }
}

The spec file is really simple, like the example on GitHub

import LoginPage
import geb.spock.GebReportSpec

class LoginSpec extends GebReportSpec
{

    // Works when I put this here, but I should not have to do this!
    System.setProperty("webdriver.chrome.driver", "my/path")

     def "user can log in" () {
        when: "log in as me"
            def loginPage = to LoginPage
            loginPage.login("me")
        then: 
          ....
     }
 }

回答1:


To fix your problem if you want to keep the path in the geb config, setting the path outside of the environment section like so should work:

import org.openqa.selenium.chrome.ChromeDriver

System.setProperty("webdriver.chrome.driver", "my/path")

//You can also set the driver up here as a default and running with an environment set will override it
driver = {new ChromeDriver()}


environments {
    chrome {
        driver = {new ChromeDriver()}
    }
}

Personally I would avoid adding the driver path to the geb config and create a run configuration in intelliJ for running locally.

Right click the spec file > Click "Create 'nameOfMySpec'".

Now add your driver path to the VM parameters:

-Dgeb.env=chrome -Dwebdriver.chrome.driver=my/path

It's also worth considering a shell script that could then also be called via Jenkins etc:

mvn test -Dgeb.env=chrome -Dwebdriver.chrome.driver=my/path


来源:https://stackoverflow.com/questions/52743048/geb-test-ignoring-gebconfig-groovy-file-launched-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!