These are chat archives for rosshinkley/nightmare

13th
May 2016
Rick Medina
@rickmed
May 13 2016 00:00
cool, let me try that
didn't work for me
I'm seeing messages in the instance console like "instantiating uh search component", "no outcome. setting it to null"
running the yahoo example
but it's not being forwarded to the node's console
nodejs
Rob Brackett
@Mr0grog
May 13 2016 00:03
yeah, that will capture all console.[whatever]() calls from the web page
whether they are from the page itself or from code you evaluate
I gotta run. Later, all!
Ross Hinkley
@rosshinkley
May 13 2016 00:04
see you :)
Rick Medina
@rickmed
May 13 2016 00:04
later
I'm getting "log
log
log
log"
with the yahoo example script
Ross Hinkley
@rosshinkley
May 13 2016 00:07
ahhh
yeah
the example @Mr0grog gave is very close, but not quite
the first argument of the event handler is going to be the method type
or method name
nightmareInstance
  .on('console', function(method, message) { console[method](message); })
  .goto('some-url')
  .evaluate(function() {
    // do some stuff
    console.log('some message');
  })
  .then(function() { something; });
i think
Rick Medina
@rickmed
May 13 2016 00:17
yeap, that was it
:+1:
Ross Hinkley
@rosshinkley
May 13 2016 00:17
you may also want to double-check string interpolation with console methods
Rick Medina
@rickmed
May 13 2016 00:18
string interpolation, say what??
Ross Hinkley
@rosshinkley
May 13 2016 00:18
for example, a call that looks like console.log('hello %s!', 'rickmed');
Rick Medina
@rickmed
May 13 2016 00:19
sorry, you lost me
Ross Hinkley
@rosshinkley
May 13 2016 00:20
ha, that's fine
the simplified version: you can define strings in console.log (for example) that can have special tokens substituted
like the example i gave
Rick Medina
@rickmed
May 13 2016 00:23
for example %s! what does that?
how is it diffrente from a variable?
Ross Hinkley
@rosshinkley
May 13 2016 00:23
... i'm realizing now i picked a bad example
Rick Medina
@rickmed
May 13 2016 00:23
i ran it and i got hello rickmed!
Ross Hinkley
@rosshinkley
May 13 2016 00:23
yep
%s is a token that specifies replacement with a string
this mdn page explains text output
if you're curious
my point was, there are circumstances where the console event could be called with >2 arguments
so in the console, it would look fine, you'd get 'hello rickmed!'
but i suspect if you look at it in the node console, you may end up with 'hello %s!'
Rick Medina
@rickmed
May 13 2016 00:29
ok I get it
thank you
Ross Hinkley
@rosshinkley
May 13 2016 00:29
no problem
Rick Medina
@rickmed
May 13 2016 06:19
guys quick question, I'm having trouble returning an array from querySelectorAll with evaluate
Ross Hinkley
@rosshinkley
May 13 2016 06:19
shoot
Rick Medina
@rickmed
May 13 2016 06:19
I've tried the convert to array and returning that object on the evaluate function but is not working https://developer.mozilla.org/en-US/docs/Web/API/NodeList
any ideas?
Ross Hinkley
@rosshinkley
May 13 2016 06:20
possible i'm just extremely tired, but i feel like i've talked about this before
hmmmm
hang on
segmentio/nightmare#617
i don't know that simply converting into an array is going to be particularly helpful, i haven't dug into the implementation details of DOMElement for example
but i suspect the properties aren't enumerable
based on the behavior i've seen so far
Rick Medina
@rickmed
May 13 2016 06:23
makes sense
thank you!
Ross Hinkley
@rosshinkley
May 13 2016 06:23
no problem :)
and with that... i need to get some sleep :P
Rick Medina
@rickmed
May 13 2016 06:23
a yes definitely non enumerable properties do not pass the ipc barrier
I was just reading the docs
neither callbacks
that one bit my ass
me too
Ross Hinkley
@rosshinkley
May 13 2016 06:24
mmm
Rick Medina
@rickmed
May 13 2016 06:24
later
Ross Hinkley
@rosshinkley
May 13 2016 06:24
gnight
James Tindall
@atomless
May 13 2016 13:47
Hi - I'm really puzzled by this. I am passing a couple of params into a Nightmare wait and I can see they are getting in as I can console them out. However as soon as I try to get the keys of one of the params Nightmare just silently fails to execute any the code in the wait. Here's my code:
let matches_expected_state = await browser
    .wait(function(slot_index, expected_state_obj) => {
        console.log('slot_index:', slot_index);
        console.log('expected_state_obj:', expected_state_obj);
        console.log('expected_state_obj keys:', Object.keys(expected_state_obj));
        console.log('getting here?');
   }, '1', { my_param_1: true });
From this I get in the console:
slot_index: 1
expected_state_obj: { my_param_1: true}
slot_index: 1
expected_state_obj: { my_param_1: true}
slot_index: 1
expected_state_obj: { my_param_1: true}
...
console.log('expected_state_obj keys:', expected_state_obj.hasOwnProperty('my_param_1)); works fine but not Object.keys
Anyone have any idea why this is failing?
James Tindall
@atomless
May 13 2016 14:54
BTW the above code is being run inside the Ava test framework https://github.com/sindresorhus/ava
Rob Brackett
@Mr0grog
May 13 2016 18:45
@atomless Is it possible the page you are examining does something funny to Object.keys? I tried this and it worked fine:
nightmare
  .on('console', (type, ...args) => console[type](args))
  .goto('about:blank')
  .wait(function(slot_index, expected_state_obj) {
      console.log('slot_index:', slot_index);
      console.log('expected_state_obj:', expected_state_obj);
      console.log('expected_state_obj keys:', Object.keys(expected_state_obj));
      console.log('getting here?');
  }, '1', { my_param_1: true })
  .end()
  .then(result => console.log(result))
  .catch(error => console.error('Error:', error));
"getting here?" got logged
Maybe try this to get a better sense of what's going wrong:
  .wait(function(slot_index, expected_state_obj) {
      console.log('slot_index:', slot_index);
      console.log('expected_state_obj:', expected_state_obj);
      try {
        console.log('expected_state_obj keys:', Object.keys(expected_state_obj));
      }
      catch(error) {
        console.log(`ERROR! ${error.message} / ${error.stack}`);
      }
      console.log('getting here?');
  }, '1', { my_param_1: true })
Rob Brackett
@Mr0grog
May 13 2016 18:52
(as a side note, wait could probably do a better job surfacing errors in your function, maybe by logging it if DEBUG=nightmare:action is set or something)