0

我正在使用 CasperJS 1.1,我想模拟单击文件字段,但是在运行测试时出现错误(该项目使用 AngularJS fwiw):

# Create gallery page
PASS File field exists
FAIL Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0
#    type: uncaughtError
#    file: spec/javascripts/casperjs/create_gallery.coffee:1323
#    error: Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0
#           CasperError: Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0
#               at mouseEvent (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:1323)
#               at click (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:428)
#               at spec/javascripts/casperjs/create_gallery.coffee:7
#               at runStep (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:1523)
#               at checkStep (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:368)
#    stack: not provided

这个错误对我来说没有意义,因为我之前关于输入字段存在的断言实际上是正确的。这是测试文件:

casper.test.begin "Create gallery page", 1, (test) ->

  casper.start "http://localhost:3000/galleries/new", ->

    @then ->
      test.assertField("input#gallery_file_0", null, "File field exists")
      @click("input#gallery_file_0")


  casper.run()

可能是什么问题?

版本:

casperjs --version
1.1.0-DEV

phantomjs -v
1.9.1

MacOSX 10.8.4
4

1 回答 1

0

使用以下行,看起来您实际上是在检查字段的值是否为null,当字段不存在时,这似乎是正确的。

test.assertField("input#gallery_file_0", null, "File field exists")

相反,您可能应该使用:

test.assertExists("input#gallery_file_0", "File field exists");
于 2013-09-11T15:07:02.583 回答