我正在使用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.4I'm using CasperJS 1.1 and I want to simulate clicking on a file field, but I'm getting an error when I run the test (the project is using 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 providedThe error doesn't make sense to me, because my previous assertion that the input field exists is actually true. Here is the test file:
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()What might be the problem?
Versions:
casperjs --version 1.1.0-DEV phantomjs -v 1.9.1 MacOSX 10.8.4最满意答案
使用以下行,看起来好像您实际上正在检查字段的值是否为null ,当字段不存在时,该值似乎为true。
test.assertField("input#gallery_file_0", null, "File field exists")相反,你应该使用:
test.assertExists("input#gallery_file_0", "File field exists");With the following line, it looks as though you are actually checking if the value of the field is null, which appears to be true when the field doesn't exist.
test.assertField("input#gallery_file_0", null, "File field exists")Instead, you should probably use:
test.assertExists("input#gallery_file_0", "File field exists");更多推荐
发布评论