Nightmarejs在同一testing中的多个页面

我试图从Drupal站点上的两个网页中拉出标题标签文本。 我想用Nightmarejs。

这是我的代码到目前为止:

// get the <title> text from inside the Drupal site var Nightmare = require('nightmare'); var user = 'foobar@example.com'; var pass = 'foobar'; new Nightmare() .goto('http://example.com/user') .type('#edit-name', user) .type('#edit-pass', pass) .click('.searchsubmit') .wait() .evaluate(function () { return document.getElementsByTagName("TITLE")[0]; }, function (res) { console.log('Homepage title: '+res.text); }) .run(function(err, nightmare){ console.log('Done1.'); // step 2 nightmare .goto('http://example.com/admin') .wait() .evaluate(function () { return document.getElementsByTagName("TITLE")[0]; }, function (res) { console.log('Admin page title: '+res.text); }) .run(function(err, nightmare){ console.log('Done2.'); }) ; }) ; 

当我运行这个,与节点app.js我能够成功login到第一页。 不幸的是,当我尝试打开第二个页面时,我发现在第二个页面调用( http://example.com/admin )上拒绝访问。 会议没有被带入第二个“goto”命令。

我能做些什么来打开同一个nightmarejs会议的许多网页?

你有没有尝试链接goto方法?

  new Nightmare() .goto('http://example.com/user') .type('#edit-name', user) .type('#edit-pass', pass) .click('.searchsubmit') .wait() .evaluate(function () { return document.getElementsByTagName("TITLE")[0]; }, function (res) { console.log('Homepage title: '+res.text); }) .goto('http://example.com/admin') .wait() .evaluate(function () { return document.getElementsByTagName("TITLE")[0]; }, function (res) { console.log('Admin page title: '+res.text); }) .run(function(err, nightmare){ console.log('Done2.'); }) ; }).run(); 

从阅读API文档运行只执行之前的命令。

经过一些testing,我发现似乎goto()只能使用一次。 为了切换到新的页面,我使用click()而不是一个额外的goto()。