使用 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();
});
这是一个 Angular 模态,因此按 ESC 将关闭它。卡斯珀有 sendKeys
但是:
The currently supported HTMLElements that can receive keyboard events from sendKeys are , , and any HTMLElement with attribute contenteditable="true".
如果页面上没有任何文本输入,就会出现问题。我可以在其他控件上添加一个或设置 contenteditable,但这意味着我正在修改页面以使测试通过,这不好。
(我通过为取消链接提供一个 id 并在其上使用 this.click
解决了这个问题,但我真的不需要修改我的标记来进行测试通过)
我怎样才能用 casper 发送一个简单的按键?
最佳答案
解决方法是发送 phantomjs 特殊 key 。
casper.then(function() {
test.comment('Send Esc key');
this.sendKeys('#contact-us-modal', casper.page.event.key.Escape);
});
这是list casper.page.event.key 中可用的特殊键
这是sendKeys文档链接。
关于javascript - 如何使用 CasperJS 发送退出按键(以关闭模式)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23276720/