Javascript 噩梦在同一个测试中有多个页面

Javascript 噩梦在同一个测试中有多个页面,javascript,node.js,nightmare,Javascript,Node.js,Nightmare,我试图从Drupal站点上的两个网页中提取标题标签文本。我想用梦魇 以下是我目前的代码: // 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')

我试图从Drupal站点上的两个网页中提取标题标签文本。我想用梦魇

以下是我目前的代码:

// 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.');
        })
      ;
    })
 ;
//从Drupal站点内部获取文本
var噩梦=需要(“噩梦”);
用户变量foobar@example.com';
var pass='foobar';
新噩梦
后藤先生('http://example.com/user')
.type(“#编辑名称”,用户)
.type(“#编辑过程”,过程)
。单击(“.searchsubmit”)
.等等
.评估(功能){
返回文档.getElementsByTagName(“标题”)[0];
},功能(res){
console.log('主页标题:'+res.text);
})
.run(函数(错误、噩梦){
console.log('Done1');
//步骤2
噩梦
后藤先生('http://example.com/admin')
.等等
.评估(功能){
返回文档.getElementsByTagName(“标题”)[0];
},功能(res){
log('管理页面标题:'+res.text);
})   
.run(函数(错误、噩梦){
console.log('Done2');
})
;
})
;
当我运行此命令时,使用:node app.js,我能够成功登录到第一个页面。不幸的是,当我试图打开第二个页面时,我看到第二个页面调用()上的访问被拒绝。会话未被执行到第二个“goto”命令中


我该怎么做才能用同一个噩梦会话打开多个页面?

您是否尝试过链接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();

从读取run开始,它只执行前面的命令。

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