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

First off, you should seriously consider rewriting this code using the Page model as explained here. It will make life a lot easier for you. Though if all you want is to get the code working, try something like this...

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 に答える