【问题标题】:Grails with Geb/Spock : Grails doesn't take my baseUrlGrails with Geb/Spock : Grails 不接受我的 baseUrl
【发布时间】:2013-06-07 08:47:53
【问题描述】:

我正在使用 Grails 2.2.1 和最新的 Geb 版本。我的 Spec 测试文件位于 功能/com.geb.mytest/

我的 GebConfig 与我的 Specs 在同一个包中..

import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxProfile

driver = {
    FirefoxProfile firefoxProfile = new FirefoxProfile()
    new FirefoxDriver(firefoxProfile)
}

reportsDir = "target/test-reports"
baseUrl =  'http://myserver.com'

waiting {
    timeout = 5
    retryInterval = 0.5

    presets {
        slow {
            timeout = 20
            retryInterval = 1
        }
        quick {
            timeout = 1.5
            retryInterval = 0.3
        }
    }
}

environments {
}

当我运行 grails test-app -functional 时,我的 baseUrl 没有被考虑在内......相反,我有一个 localhost url..

有没有办法避免将 baseUrl 作为参数放在 grails test-app 命令中?

有什么想法吗? 提前致谢

【问题讨论】:

  • 试试 browser.config.baseUrl =

标签: grails spock geb


【解决方案1】:

尝试在为您拥有的每个测试类扩展的类中设置 baseUrl:

class BaseUrlTest extends GroovyTestCase {

    def baseURL

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        baseURL = 'your url here'
    }

}

那么你的测试类看起来像这样

class myTests extends BaseUrlTest {
    void testSomething() {}
}

【讨论】:

  • 感谢回复。事实上我正在扩展 GebReportingSpec 并且它没有 setUp() 方法。所以它没有用..
  • 在这种情况下,创建自定义环境并设置 grailsS​​erverUrl 以满足您的需求。只有这样,您才需要使用自定义测试环境运行测试。
  • GebReportingSpec 有 setup() 而不是 setUp():github.com/geb/geb/blob/master/module/geb-spock/src/main/groovy/…
  • 在 Spock 中是def setup() { ... },并且超级方法(如果有的话)会被自动调用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-29
  • 1970-01-01
  • 2012-05-06
相关资源
最近更新 更多