我正在使用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
答案 0 :(得分:0)
使用以下行,看起来好像是在检查字段的值是否为null
,当字段不存在时,该值似乎为真。
test.assertField("input#gallery_file_0", null, "File field exists")
相反,您应该使用:
test.assertExists("input#gallery_file_0", "File field exists");