cdu*_*dub 5 javascript testing tdd phantomjs casperjs
如何测试我的页面上的警告框被调用?我可以抓住警报框的文本并进行评估吗?
我在CasperJS中的点击是这样完成的:
casper.waitForSelector('a[href="javascript:UserLogin()"]',
function success() {
this.test.comment("Submiting the bad login info");
this.test.assertExists('a[href="javascript:UserLogin()"]');
this.click("a#h_login");
},
function fail() {
this.test.assertExists('a[href="javascript:UserLogin()"]');
});
Run Code Online (Sandbox Code Playgroud)
UserLogin函数检查,在这种情况下,返回:
alert('Login has failed.');
Run Code Online (Sandbox Code Playgroud)
我该如何检查?
NiK*_*iKo 13
你必须听听这个remote.alert 事件:
casper.on('remote.alert', function(message) {
this.echo('alert message: ' + message);
// or if you want to test it
this.test.assertMatch(message, /Login has failed/);
});
Run Code Online (Sandbox Code Playgroud)
试图让它更加同步:
function testAlert(message) {
this.test.assertMatch(message, /Login has failed/);
}
casper.then(function() {
// temporarily registering listener
this.on('remote.alert', testAlert);
});
casper.waitForSelector('#login', function success() {
this.test.pass('selector was found');
this.click("#login");
}, function fail() {
this.test.fail('selector was found');
});
casper.then(function() {
this.removeListener('remote.alert', testAlert);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5224 次 |
| 最近记录: |