CasperJS单击无法显示模式窗口
CasperJS click fails to show modal window
我正在尝试编写一个非常简单的CasperJS脚本来测试网站上的登录按钮。点击事件后,网站顶部会打开一个模式窗口,以便您可以填写登录字段。
使用该网站,这效果很好。使用casperjs test my-script-file --engine=slimerjs
也可以很好地工作。如果没有slimerjs,代码就会失败。
如何定义按钮:
<button class="btn btn-strong-submit" data-action="join">Join</button>
我的测试:
casper.test.begin('testing', 3, function suite(test)
{
casper.start();
casper.thenOpen("http://the-website-to-test-url", function()
{
casper.wait(5000, function(){
casper.thenClick("button.btn.btn-strong-submit");
});
});
casper.then(function () {
casper.wait(3000);
casper.capture("screen.png");
});
casper.then(function(){
casper.assertVisible("div.join_container");
});
casper.run(function()
{
test.done();
})
});
在网站上,单击按钮将转到 http://the-website-to-test-url.com/#join 因为网站的工作方式是等待点击并捕获正在使用jQuery,然后找到[data-action],表单#[data-action],然后以这种方式构建URL。
但是CasperJS似乎不理解点击,然后在后台从jQuery捕获。有什么想法吗?
终端输出更新:
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: http://www.MYURL.com/, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.MYURL.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://www.MYURL.com/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 http://www.MYURL.com/ (HTTP 200)
[info] [phantom] Step anonymous 2/4: done in 721ms.
[info] [phantom] Step anonymous 3/4 http://www.MYURL.com/ (HTTP 200)
[info] [phantom] Step anonymous 3/4: done in 731ms.
[info] [phantom] Step _step 4/5 http://www.MYURL.com/ (HTTP 200)
[info] [phantom] Step _step 4/5: done in 752ms.
[info] [phantom] wait() finished waiting for 5000ms.
[debug] [phantom] Mouse event 'mousedown' on selector: .btn.btn-strong-submit
[debug] [phantom] Mouse event 'mouseup' on selector: .btn.btn-strong-submit
[debug] [phantom] Mouse event 'click' on selector: .btn.btn-strong-submit
[info] [phantom] Step anonymous 5/5 http://www.MYURL.com/ (HTTP 200)
//After click URL should have changed to http://www.MYURL.com/#login
[info] [phantom] Step anonymous 5/5: done in 5772ms.
[info] [phantom] Step _step 6/6 http://www.MYURL/ (HTTP 200)
[info] [phantom] Step _step 6/6: done in 5792ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to /home/TEMP/screen.png
[info] [phantom] Capture saved to /home/TEMP/screen.png
[info] [phantom] Done 6 steps in 9367ms
扩展Artjom的评论,我认为你应该改变这一点:
casper.then(function () {
casper.wait(3000);
casper.capture("screen.png");
});
成为:
casper.wait(3000, function () {
casper.capture("screen.png");
});
这更具描述性,而不仅仅是更紧凑:"等待 3000 毫秒然后做......"。
(旁白:casper.then( doSomething )
和casper.wait(0, doSomething)
是一回事。
注意:此方法的缺点是它为单元测试增加了 3 秒的延迟。您可以将其重写为:
casper.waitUntilVisible('div.join_container', {
casper.capture("screen.png");
});
然后,一旦可见,它将截取屏幕截图,然后进行下一步。这种方式的缺点是你的断言总是有效的;如果出现问题,您将获得超时,而不是测试失败。(这可能重要,也可能无关紧要,这取决于您要测试的内容以及原因。
相关文章:
- Angular$scope在模式窗口内不起作用
- 更改不在引导模式窗口中工作的月份和年份
- TinyMCE全屏不允许出现模式窗口
- 自动模式窗口?/欢迎弹出框
- 推特Boostrap模式窗口-可拖动不工作
- Twitter Boostrap:模式窗口在重新播放模式窗口后不播放视频
- 在Bootstrap模式窗口中打开远程内容
- jQuery模式窗口在内容为“”时不居中;注入“;在飞行中
- 如何在模式窗口弹出窗口中隐藏滚动条
- fancybox将内容更改为模式窗口
- 将值传递给模式窗口中的 JavaScript 函数
- HTML 瞬态模式窗口
- 具有 UI 引导模式窗口的父$scope子
- 如何将参数传递到 UI 路由器状态的模式窗口
- 如何使用引导程序创建模式窗口
- j查询模式窗口,刷新父问题
- 无法将引导模式窗口作为路由打开
- 如何使模式窗口打开动态内容并更改url
- 在引导模式窗口内路由
- 更新面板和模式窗口