忽略IntelliJ中启动的GebConfig.groovy文件的Geb测试 [英] Geb test ignoring GebConfig.groovy file launched in IntelliJ

查看:95
本文介绍了忽略IntelliJ中启动的GebConfig.groovy文件的Geb测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IntelliJ IDEA中运行. GebConfig.groovy在/src/test/resources中.

我正在使用Chrome驱动程序.

当我键入 System.setProperty("webdriver.chrome.driver", "my/path") 在我的规范文件中,然后右键单击并选择运行",该测试就会生效,这意味着它会打开Chrome并加载页面.

当我不在spec文件中执行此操作,而是将其保留在GebConfig.groovy文件中时,我收到错误消息必须设置驱动程序可执行文件的页面".

有一个空隙,所以我不能复制粘贴.我将在这里输入尽可能多的内容: GebConfig.groovy:

import org.openqa.selenium.chrome.ChromeDriver

...

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

spec文件非常简单,就像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: 
          ....
     }
 }

解决方案

要解决此问题,如果要将路径保留在geb配置中,则可以像下面那样在环境部分之外设置路径:

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()}
    }
}

就我个人而言,我将避免将驱动程序路径添加到geb config中,并在intelliJ中创建用于本地运行的运行配置.

右键单击规范文件>单击创建'nameOfMySpec'".

现在将驱动程序路径添加到VM参数:

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

同样值得考虑的是一个可以通过Jenkins等调用的shell脚本:

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

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: 
          ....
     }
 }

解决方案

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

这篇关于忽略IntelliJ中启动的GebConfig.groovy文件的Geb测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆