不能简单地处理 HTTP 身份验证。这是我的代码:
var x = require('casper').selectXPath;
var casper = require('casper').create({
verbose: false,
logLevel: 'debug'
});
casper.options.viewportSize = {width: 1366, height: 667};
casper.start('https://example.com/a/dashboard');
casper.setHttpAuth('username', 'password');
casper.then(function() {
this.test.assertUrlMatch(/^https:\/\/example.com\/a\/dashboard$/);
});
casper.run(function() {this.test.renderResults(true);});
我在控制台中看到的错误:
casperjs mytest.js
FAIL Current url matches the provided pattern
# type: assertUrlMatch
# subject: false
# currentUrl: "https://example.com/login"
# pattern: "/^https:\\/\\/example.com\\/a\\/dashboard$/"
FAIL 1 tests executed in 2.428s, 0 passed, 1 failed.
问:为什么我当前的 Url 与 pattern 不匹配?谢谢你。