Selenium测试有时会抛出异常

时间:2016-04-15 12:37:34

标签: selenium grails spock geb

我在grails中运行硒测试时遇到一个奇怪的问题。我正在使用geb和spock。我的测试有时运行正常,有时候没有。我不能重现错误。

例外情况说,检查员失败了。但该元素已加载到页面上。有人遇到过类似的问题吗?

我不知道从哪里开始搜索错误。

示例代码:用于规范

@Stepwise
class CheckMenuLinks extends Admin {

def "Go to Dashboard"() {
    when:
    at VersionPage
    then:
    mainNavigation.clickMenu("overview","Dashboard")
    waitTestEnd()
}


def "Go to Box Overview / Transactions"() {
    when:
    at DashboardPage
    mainNavigation.clickMenu("overview","Transactions")
    waitTestEnd()
    then:
    at TransactionsPage


}

def "Go to Box Overview / Health"() {
    when:
    at TransactionsPage
    mainNavigation.clickMenu("overview","Health")
    waitTestEnd()
    then:
    at HealthPage


}

}

此规范只是点击我菜单的每个链接并检查页面是否已加载。

页面示例:

class DashboardPage extends LayoutBasePage{
static at = { pageMarker }

static content = {
    pageMarker(wait: true) { $('#pageDashboard') }

}

}

每个页面在body标签中都有一个ID。奇怪的问题是,页面正确加载,id存在于body标签中,但测试失败。但有时候。并不总是在同一个步骤,总是另一步。

例外:

geb.waiting.WaitTimeoutException: condition did not pass in 20.0 seconds (failed with exception)
at geb.waiting.Wait.waitFor(Wait.groovy:138)
at geb.Page.verifyThisPageAtOnly(Page.groovy:226)
at geb.Page.verifyAt(Page.groovy:182)
at geb.Browser.doAt(Browser.groovy:454)
at geb.Browser.at(Browser.groovy:336)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at specs.scenario.create.BoxUser.Add New User(BoxUser.groovy:46)
Caused by: geb.waiting.WaitTimeoutException: condition did not pass in 20.0 seconds (failed with exception)
at geb.waiting.Wait.waitFor(Wait.groovy:138)
at geb.content.PageContentTemplate.create(PageContentTemplate.groovy:74)
at geb.content.PageContentTemplate.get(PageContentTemplate.groovy:54)
at geb.content.DefaultPageContentSupport.getContent(DefaultPageContentSupport.groovy:42)
at geb.content.PageContentSupport.propertyMissing(PageContentSupport.groovy:39)
at geb.Page.propertyMissing(Page.groovy:99)
at groovy.lang.Closure.getPropertyTryThese(Closure.java:321)
at groovy.lang.Closure.getPropertyDelegateFirst(Closure.java:311)
at groovy.lang.Closure.getProperty(Closure.java:296)
at pages.configuration.boxusers.UserProfilePage._clinit__closure1(UserProfilePage.groovy:7)
at pages.configuration.boxusers.UserProfilePage._clinit__closure1(UserProfilePage.groovy)
at geb.waiting.Wait.waitFor(Wait.groovy:117)
at geb.Page.verifyThisPageAtOnly(Page.groovy:226)
at geb.Page.verifyAt(Page.groovy:182)
at geb.Browser.doAt(Browser.groovy:454)
at geb.Browser.at(Browser.groovy:336)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at specs.scenario.create.BoxUser.Add New User(BoxUser.groovy:46)
Caused by: org.codehaus.groovy.runtime.powerassert.PowerAssertionError: $('#pageSetupUser')

0 个答案:

没有答案