问题描述
我当时正在考虑在ribs.js和jquery中编写一些UI测试.它们可能不是最好的方法,但这是我在考虑的事情-通过普通代码自动执行测试,而无需记录和回放.
I was thinking of writing some UI tests in backbone.js and jquery. They may not be the best way to do it but it's something that I was thinking about - to automate the tests without record and playback - through plain code.
使用这种方法让我抓狂的唯一事情是:在(执行的)某些用例流程"中,将显示确认/警告对话框.我想单击确定"并继续操作-这甚至可以通过简单的javascript代码来完成吗?怎么样?
The only thing that made me scratch my head using this approach is this: In some 'use-case flow' (of the execution) confirm/alert dialogs would show up. I'd like to click 'Ok' and continue the flow - is this even doable through plain javascript code? How?
注意:我确实知道GUI测试库的存在,但是我想知道如果可能的话,仅使用jQuery/javascript代码来做到这一点.
Note: I do know GUI testing libraries exist, but I want to know how to do it using just jQuery/javascript code, if at all possible.
推荐答案
据我所知,如果您使用标准的alert()
调用,则无法触发确定"单击,因为警报调用会阻止正常的JS事件循环.
As far as I know if you use a standard alert()
call you cannot trigger an "OK" click because the alert call blocks the normal JS event loop.
但是您应该能够用您自己不执行任何操作的函数替换window.alert
和window.confirm
:
However you should be able to replace window.alert
and window.confirm
with your own function that does nothing:
window.alert = function() {
console.log.apply(console, arguments);
};
在加载其他任何内容之前,将它们放在JS的顶部,随后对alert()
或confirm()
的任何调用将改为调用这些.
Place these at the top of your JS before anything else is loaded and any subsequent calls to alert()
or confirm()
will call these instead.
这篇关于在警报上单击“确定"还是通过jquery/javascript确认对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!