【发布时间】:2016-04-14 21:15:48
【问题描述】:
使用 casper 测试模态对话框:
.then(function() {
this.click(variables.configButton);
}).then(function() {
this.capture('./test/screencaps/edit-afterClickFlyout1.png');
test.assertVisible('#addDataDialog');
}).then(function() {
// send ESC key, how?
}).then(function() {
this.capture('./test/screencaps/edit-afterClickFlyout2.png');
test.assertNotVisible('#addDataDialog');
}).run(function() {
test.done();
});
这是一个角度模式,所以按 ESC 将关闭它。 Casper 有 sendKeys 但是:
目前支持的可以接收键盘事件的 HTMLElements 从 sendKeys 是 , , 和任何 HTMLElement 与 属性 contenteditable="true"。
如果我在页面上没有任何文本输入,那就有点问题了。我可以在其他控件上添加一个或设置 contenteditable,但这意味着我正在修改页面以使测试通过,这并不好。
(我通过给取消链接一个 id 并在其上使用 this.click 解决了这个问题,但我真的不应该修改我的标记来使测试通过)
如何使用 casper 发送一个简单的按键?
【问题讨论】:
标签: javascript angularjs functional-testing casperjs