Coffeescript 如何等待casper测试中的元素存在?
好的,那个测试通过得很好。我想改进的是@wait call,这样做似乎更明智@waitFor:Coffeescript 如何等待casper测试中的元素存在?,coffeescript,phantomjs,casperjs,Coffeescript,Phantomjs,Casperjs,好的,那个测试通过得很好。我想改进的是@wait call,这样做似乎更明智@waitFor: casper.test.begin "Can open the homepage", (test) -> casper.options.viewportSize = {width: 1024, height: 768} casper.start("http://localhost:4000/", -> @wait(1000, -> test.assertH
casper.test.begin "Can open the homepage", (test) ->
casper.options.viewportSize = {width: 1024, height: 768}
casper.start("http://localhost:4000/", ->
@wait(1000, ->
test.assertHttpStatus 200
test.assertTitle("XYZ Corp")
test.assertExists('DIV.links')
test.assertElementCount('DIV.links', 1)
test.assertExists('IMG#companyLogo')
@capture('./test/screencaps/homepage.png')
)
).run ->
test.done()
然而,这总是超时。document
对象存在,它可以运行querySelectorAll
函数,但我从未得到任何结果。DIV.links
对象必须出现在页面上(我可以在屏幕截图中看到),因为测试在第一种情况下通过。但在第二种情况下,条件总是错误的<代码>等待文档已关闭
附加问题:我可以调试casper测试吗 4天,没有答案,我自己解决了:
@waitFor(
->
document.querySelectorAll('DIV.links').length > 0
->
test.assertHttpStatus 200
test.assertTitle("XYZ Corp")
.then( ->
@open("theUrl")
@waitUntilVisible("DIV.alpha",
->
test.assertExists("DIV.alpha") # doesnt hurt to check
test.assertExists("DIV#beta")
@capture('./test/screencaps/waitUntilVisible.png')
->
test.fail('failed to find div.alpha')
3000
)
)