我正在尝试casperjs
根据文档提交一个带有简单任务的表单。但是,它只是行不通。
这是代码:
casper.test.begin('Logging in', nbTests, function(test) {
casper.start(A_SERVER);
casper.then(function() {
this.fill('form', {
'username': GOOD_LOGIN,
'password': GOOD_PASSWORD}, true);
this.waitUntilVisible('.success');
this.waitForText('Successful login', function (){
casper.test.assertExists('.success');
});
});
casper.run(function(){
test.done();
this.exit();
});
});
但是,这样做会返回:
# Logging in
PASS Found an element matching: form
FAIL Redirection to dashboard after successfull login.
# type: assertExists
# file: /home/fx/SRC/server/tests_integration/ti_login.js:28
# code: test.assertExists('.success', "Redirection to dashboard after successfull login.");
# subject: false
# selector: ".success"
Unsafe JavaScript attempt to access frame with URL http://127.0.0.1:8000/accounts/login/ from frame with URL file:////etc/local/bin/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.
第一个麻烦当然是失败。但是,我也担心另一个警告(这是随机发生的)。你知道这件事吗?
编辑:我重构了代码,现在它可以工作了。但是,我不明白为什么。有人会好心解释这个问题吗?