segment-boneyard/nightmare

Evaluate is broken

Closed this issue · 3 comments

Using the exact mocha example given in the readme.md, times out at 30000

var Nightmare = require('nightmare');
var expect = require('chai').expect; // jshint ignore:line

describe('test yahoo search results', function() {
  this.timeout(30000);

  it('should find the nightmare github link first', function(done) {
    new Nightmare()
      .goto('http://yahoo.com')
        .type('input[title="Search"]', 'github nightmare')
        .click('.searchsubmit')
        .wait('.url.breadcrumb')
        .evaluate(function () {
          return document.querySelector('.url.breadcrumb').innerText;
        }, function (breadcrumb) {
          expect(breadcrumb).to.equal('github.com');
        })
        .run(done);
  });
});

Output:

child_process: customFds option is deprecated, use stdio instead.


  test yahoo search results
    1) should find the nightmare github link first


  0 passing (30s)
  1 failing

  1) test yahoo search results should find the nightmare github link first:
     Error: timeout of 30000ms exceeded
      at [object Object].<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:157:19)
      at Timer.listOnTimeout (timers.js:89:15)

Seems to be working okay for me, can you try upping the timeout?

I upped the timeout to be 60000, new error. This is something I ran into previously as well, document seems to be undefined within evaluate()

ϟ test  mocha
child_process: customFds option is deprecated, use stdio instead.


  test yahoo search results
phantom stdout: TypeError: null is not an object (evaluating 'document.querySelector('.url.breadcrumb').innerText')


phantom stdout:   phantomjs://webpage.evaluate():2
  phantomjs://webpage.evaluate():3

    1) should find the nightmare github link first


  0 passing (7s)
  1 failing

  1) test yahoo search results should find the nightmare github link first:
     Uncaught AssertionError: expected null to equal 'github.com'
      at /Users/henrysnopek/projects/test/test/test.js:16:33
      at wrapped (/Users/henrysnopek/projects/test/node_modules/nightmare/lib/actions.js:403:14)
      at Proto.apply (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:123:13)
      at Proto.handle (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:99:19)
      at D.dnode.handle (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/dnode/lib/dnode.js:140:21)
      at D.dnode.write (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/dnode/lib/dnode.js:128:22)
      at SockJSConnection.ondata (stream.js:32:26)
      at emitOne (events.js:77:13)
      at SockJSConnection.emit (events.js:169:7)
      at Session.didMessage (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/lib/transport.js:220:25)
      at WebSocketReceiver.didMessage (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/lib/trans-websocket.js:102:40)
      at /Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/lib/trans-websocket.js:75:22
      at null.<anonymous> (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js:41:7)
      at Array.forEach (native)
      at EventTarget.dispatchEvent (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js:40:33)
      at API.receive (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/node_modules/faye-websocket/lib/faye/websocket/api.js:30:10)
      at instance._emitFrame (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/node_modules/faye-websocket/lib/faye/websocket/hybi_parser.js:285:44)
      at instance.parse (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/node_modules/faye-websocket/lib/faye/websocket/hybi_parser.js:143:18)
      at Socket.<anonymous> (/Users/henrysnopek/projects/test/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/node_modules/faye-websocket/lib/faye/websocket.js:72:33)
      at emitOne (events.js:77:13)
      at Socket.emit (events.js:169:7)
      at readableAddChunk (_stream_readable.js:145:16)
      at Socket.Readable.push (_stream_readable.js:109:10)
      at TCP.onread (net.js:519:20)


ack sorry for the trouble here... this kind of unreliable stuff seems to plague phantom and in v2 we're moving to electron which (so far) feels much more stable and speedy.