【发布时间】:2014-03-20 23:34:05
【问题描述】:
我想用 CasperJS 测试一个网站。如果在某个输入字段上触发了 onBlur 事件,则页面上其他位置的属性会在一段时间后更新。我想等到此属性更新并编写以下代码来执行此操作:
Foo.prototype.setBar = function ( baz ) {
casper.then( function () {
// local variable baz can be passed to evaluate
casper.evaluate( function ( arg1 ) {
var $inputField = $( 'section.xyz input' );
$inputField.val( arg1 );
$inputField.blur();
}, baz ); // this works just fine
// local variable baz can not be passed to evaluate within waitFor()
casper.waitFor( function () {
return this.evaluate(function ( arg1 ) {
return __utils__.findOne('mySelector').getAttribute('data-xyz') === arg1;
}, baz);
}, function then() {
casper.log('Attribute with given value was found', 'info');
}, function timeOut() {
casper.test.fail('Attribute with given value could not be found');
}, 10000); // this doesn't work
});
};
显然,waitFor 方法中传递的变量baz 的值为空或未定义。这个问题怎么解决?
【问题讨论】:
标签: javascript automated-tests phantomjs casperjs