我对GEB感到非常新鲜,我正在尝试使用spock和硒创建一个非常简单的测试用例。
该应用程序是使用OJET的单页应用程序
HTML代码
<div class="oj-hybrid-padding">
<div id="dashboardTitleDiv">
<h1>Dashboard Content Area</h1>
</div>
.....
</div>
GEB页面
class ISSDashboardPage extends Page {
static url = "?root=dashboard"
static at = { $("div#dashboardTitleDiv>h1").text() == "Dashboard Content Area" }
}
Groovy测试
class NavigateToWorkspaceSpec extends GebSpec {
def "can navigate to Workspace"() {
when: to ISSDashboardPage
then: waitFor(25){at ISSDashboardPage}
}
}
由于某种原因,我不明白,“ at”页面上的选择器不起作用。这是我得到的错误:
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 10.763 sec <<< FAILURE! - in NavigateToWorkspaceSpec
can navigate to Workspace(NavigateToWorkspaceSpec) Time elapsed: 10.39 sec <<< FAILURE!
org.codehaus.groovy.runtime.powerassert.PowerAssertionError:
$("div#dashboardTitleDiv>h1").text() == "Dashboard Content Area"
| | |
[] null false
at NavigateToWorkspaceSpec.can navigate to Workspace(NavigateToWorkspaceSpec.groovy:8)
Results :
Failed tests:
NavigateToWorkspaceSpec.can navigate to Workspace:8->GebSpec.methodMissing:56 $("div#dashboardTitleDiv>h1").text() == "Dashboard Content Area"
| | |
[] null false
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
如果选择器只是“ $(h1).text(),它将找到第一个” h1“元素的文本
$("h1").text() == "Dashboard Content Area"
| | |
| | false
| Inside Sales
谁能发现哪里出了问题? 我注意到页面的一部分尚未呈现(实际上我看不到我期望看到的)。但是我希望测试中的waitFor至少会浪费25秒,直到该选择器被解决。
非常感谢您。
最好的问候
答案 0 :(得分:1)
确定
at
检查器未被缓存,waitFor
。 (但是,25秒真的很长。您的页面真的很慢吗?)static at = { dynamicH1.text() == "Dashboard Content Area" }
static content = {
dynamicH1(required: false, wait: 25, cache: false) { $("div#dashboardTitleDiv>h1") }
}