1

全部!我想在我的测试中上传文件。在Geb-book上写下它是如何制作的,但它对我不起作用。

我有领域:

<input id="bla-bl-bla" type="file" name="foo-foo-foo">

和按钮:

<input type="submit" value="Загрузить файл" name="bar-bar-bar">

我尝试:

    def "choose banner format"() {
    when: "choose fake format"
        $("select", name: Const.namespaceId + "createBanner:j_id83:j_id91")
    and: "wait load"
        waitFor(25, 2) { $("input", name : Const.namespaceId + "createBanner:upload:j_id256")}
    then: "can upload file"
        $("input", id : "name") << name_banner
        String file_1 = "/full/path/to/file"
        String uploadfile = "foo-foo-foo"
        $("input").uploadfile  =  banner
        $("input", name : "bar-bar-bar").click()
        def createActLink = $("input", name : "save")
        createActLink.click()
        sleep 20000
}

但我有错误:

Expected a condition, but found an assignment. Did you intend to write '==' ?

Geb:0.9.0-RC-1 Groovy:2.1.1 浏览器:FF 19

谢谢!

4

1 回答 1

1

首先,您应该认真考虑使用 Page 模型重写此代码,如此所述。它会让你的生活更轻松。虽然如果您只想让代码正常工作,请尝试这样的事情......

def "choose banner format"() {

    given:
        String file_1 = "/full/path/to/file"
        String uploadfile = "foo-foo-foo"
    when: 
        //if j_id83 and j_id91 are integers, caste them to strings!
        $("select", name: Const.namespaceId.toString() + "createBanner:j_id83:j_id91")
        waitFor(25, 2) { $("input", name : Const.namespaceId + "createBanner:upload:j_id256")}
        $("input", id : "name") << name_banner
        $("input").uploadfile  =  banner
        $("input", name : "bar-bar-bar").click()
        waitFor{ $("input", name : "save") }
        def createActLink = $("input", name : "save")
        createActLink.click()
    then:
        waitFor{
          // choose an element to refresh on page after input is clicked   
        } 
}
于 2015-07-13T11:31:44.317 回答