Save 如何在Dalekjs终端中保存
打开“测试”对象后,如何保存其内容? 例如:Save 如何在Dalekjs终端中保存,save,phantomjs,interaction,Save,Phantomjs,Interaction,打开“测试”对象后,如何保存其内容? 例如: module.exports = { 'Page title is correct': function (test) { test .open('http://google.com') // save content of test the HTML DOM .assert.title().is('Google', 'It has title') .done(); } };
module.exports = {
'Page title is correct': function (test) {
test
.open('http://google.com')
// save content of test the HTML DOM
.assert.title().is('Google', 'It has title')
.done();
}
};
或者直接与幻影互动
有可能吗 即使DalekJS的主要目的不是做这样的事情,但从技术上讲,这样做是可能的:
module.exports = {
'Can store html': function (test) {
test.open('http://google.com')
.execute(function () {
this.data('htmlData', window.document.getElementsByTagName('html')[0].outerHTML);
})
.log.message(function () {
var data = test.data('htmlData');
var fs = require('fs');
fs.writeFileSync('nameOfTheFile.html', data);
return data;
})
.assert.title().is('Google', 'It has title')
.done();
}
};
我们使用execute
方法在浏览器中执行一些JavaScript,并使用data('key','value')
存储方法将其传递到节点
稍后,我们将在节点上下文中运行的log.message
方法中访问这些数据。这使我们能够加载文件系统
模块&最后将捕获的html存储到一个文件中