我很想在水豚中编写测试,但我无法获取页面的当前URL.我这样写的:
url = page.current_url + page.current_path
Run Code Online (Sandbox Code Playgroud)
不知何故,它只是返回基本URL.非常感谢帮助.
我是PhantomJS和Javascript的新手,我正在研究一个测试加载时间的脚本,我希望它能够检测到在测试它时是否遇到404/500错误,并在console.log中显示和消息. .代码如下:
var page = require('webpage').create(), t, address;
t = Date.now();
var testArray =
['someURL'];
function loadTest(testURL)
{
address = testURL;
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address' + address);
return;
}
});
}
for(var i = 0; i < testArray.length; i++)
{
loadTest(testArray[i]);
t = Date.now() - t;
console.log('Testing ' + testArray[i]);
console.log('Loading time ' + t + ' msec\n');
}
phantom.exit();
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助.谢谢