WithNewWindow() returns Geb 中的 MultipleCompilationErrorsException

WithNewWindow() returns MultipleCompilationErrorsException in Geb

我在 geb 功能测试中遇到奇怪的错误。

 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Spec expression: 1: expecting '}', found 'assert' @ line 1, column 71.
    } ) { at(JobOfferDetailPage) assert des

我的测试是这样的。我单击 link,它会打开一个新的 window,其中包含工作机会的详细信息。比我想使用页面模式在新页面上断言一些文本。

测试:

withNewWindow( { quickShowOption.click() } ) { //TODO fix me
                    at(JobOfferDetailPage)
                    assert description.text() == 'some text'
                    assert requirements.text() == 'some text'
                    assert advatages.text() == 'some text.'
                    assert categories.text() == 'some text'
                    assert locality.text() == 'some text'
                }

页数:

class JobOfferDetailPage extends Page {
    static at = {$('#contactLabel').text() == 'Contact'}

    static content = {
        description {$('#jobOfferDescription')}
        requirements {$('#jobOfferRequirements')}
        advatages {$('#jobOfferAdvantages')}
        jobOfferType {$('#jobOfferType')}
        categories {$('#categories')}
        locality {$('#locality')}
        startDate {$('#startDate')}
        requiredLanguages {$('#requiredLanguages')}
    }
}

我的条件成立后出现编译错误。如果我在断言文本中打错字,测试通常会失败,但如果通过,则会因这个奇怪的错误而失败。


谢谢@Erdi。

我使用 spock、geb 版本“0.13.1”和 selenium 版本“2.51.0”。

如果有人相信 this comment in one of Geb's own tests,这不是我前段时间写的,这确实看起来像是 Spock 中的某种错误。有趣的是,我刚刚将该语句移至 expect 块,只要传递给 newWindow() 的第二个闭包中的最后一个语句计算结果为真,它就会工作。这让我认为这是旧版本 Spock and/or Groovy 的问题。您使用的是上述工具的哪个版本?

一种可能的解决方法是将您的语句从 expect/then 移动到不断言的语句(givenwhen),如测试所示我链接到。