These are chat archives for rosshinkley/nightmare

5th
May 2016
Maxwell Zhao
@thepiercingarrow
May 05 2016 00:52
The same thing happened..
what is visible supposed to do?
Ross Hinkley
@rosshinkley
May 05 2016 00:53
it shows the browser
i have a sneaking suspicion it's not doing what you think it's supposed to be doing
Maxwell Zhao
@thepiercingarrow
May 05 2016 00:53
It didn't for me...
Ross Hinkley
@rosshinkley
May 05 2016 00:54
... i might have the option wrong, hang on
Maxwell Zhao
@thepiercingarrow
May 05 2016 00:54
I am doing it in the terminal.. is it supposed to open a new window?
Ross Hinkley
@rosshinkley
May 05 2016 00:54
bahhh, it's show, not visible
anyway, yeah, it'll show the electron instance
that way, you can watch what it's doing
Maxwell Zhao
@thepiercingarrow
May 05 2016 00:56
WOWOW it worked!!!!!
Thats AMAZING!!
Ross Hinkley
@rosshinkley
May 05 2016 00:56
hahahah
Maxwell Zhao
@thepiercingarrow
May 05 2016 00:57
It showed an animation of the web browser, and now I know exactly what I did wrong!!
rosshinkley @rosshinkley nods
Ross Hinkley
@rosshinkley
May 05 2016 00:57
show:true is a pretty good debugging tool
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:01
YAYAYAY IT WORKED NOW!!
only problem is that it waits for 1 second, which might not always be enough
Ross Hinkley
@rosshinkley
May 05 2016 01:02
might be worth using .wait(selector) if you can
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:02
I pushed
That will work for the second .wait(), but the first one needs to wait for the page to reload. Not sure thats possible?
Wait nvm I think I know how to do it!
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:10
There is no way to wait() for the page to reload?
Ross Hinkley
@rosshinkley
May 05 2016 01:26
hm
how is it being reloaded?
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:27
Let me check.. I believe its a POST request
Ross Hinkley
@rosshinkley
May 05 2016 01:27
.wait('body') mmmight work
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:29
I'll try..
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:35
It didn't work :(
How would I use evaluate to make sure my username is correct before continuing?
Ross Hinkley
@rosshinkley
May 05 2016 01:43
uh
.evaluate( () => { return document.querySelector('.myUserNameSelector').value;}?
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:46
Its actually a property of an object
could I do .wait(.evaluate(function(){return user.username})) ?
Ross Hinkley
@rosshinkley
May 05 2016 01:47
well, what i wrote would give you what you typed... maybe i'm not following, are you trying to interact with the client-side script/objects?
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:47
Yes
Ross Hinkley
@rosshinkley
May 05 2016 01:47
can't hurt to try
but i'm going to say i kind of doubt it
unless it's attached to document/window/global scope
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:49
I want to wait until I correctly receive my username before continuing.
My username is stored in a client-side object
Ross Hinkley
@rosshinkley
May 05 2016 01:50
you can try it, but i think you'd probably be better off looking for a tell-tale sign you're logged in
eg, github has an avatar dropdown that shows who you're logged in as
something like that
... i should also say, i'm assuming this 'client-side object' is something the page is creating
that might not be a great assumption on my part
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:52
It does have one, I guess I will just use that, then.
Ross Hinkley
@rosshinkley
May 05 2016 01:53
i take it the object you want isn't accessible from global scope?
Maxwell Zhao
@thepiercingarrow
May 05 2016 01:57
Yeah... :(
Ross Hinkley
@rosshinkley
May 05 2016 01:57
bummer
Michael Groncki
@dergroncki
May 05 2016 14:58
Is there any way to use xpath with nightmare? Nightmare-xpath seems to be out-of-date? Thanks.
Rob Brackett
@Mr0grog
May 05 2016 16:03
No way to do so without writing a similar plugin.
Looking at it, it seems like it might have been written for a much older version of Nightmare; it should be much easier to write something similar now
Rob Brackett
@Mr0grog
May 05 2016 16:15
Probably something roughly like:
Nightmare.action('xpath', function(selector, handler, done) {
  if (arguments.length == 2) {
    done = handler;
    handler = (node) => node.toString();
  }
  this.evaluate_now(function(selector, handler) {
    handler = Function('', `return (${handler}).apply(null, arguments);`);
    var node;
    var result = [];
    var xpathResult = document.evaluate(selector, document, null, XPathResult.ANY_TYPE, null);
    while (node = xpathResult.iterateNext()) {
      var item = handler(node);
      result.push(item);
    }
    return result;
  }, done, selector, handler.toString());
});
Michael Groncki
@dergroncki
May 05 2016 16:28
Thanks, I will try your code (if I understand it) later on
Rob Brackett
@Mr0grog
May 05 2016 16:29
:thumbsup:
If you need any help understanding what it does, start here: https://github.com/segmentio/nightmare/#nightmareactionname-electronactionelectronnamespace-actionnamespace
But happy to help you get a sense of it if you need more help.
(Also, would be curious if you have a use case you need XPath for that you can’t solve effectively with CSS selectors.)
Michael Groncki
@dergroncki
May 05 2016 16:37
@Mr0grog text without html tags
Rob Brackett
@Mr0grog
May 05 2016 16:39
Ah, so just trying to get individual text nodes, rather than the textual content of an element?
Michael Groncki
@dergroncki
May 05 2016 16:41
@Mr0grog for example <strong>...</strong>anytext
@Mr0grog how to select anytext?
Rob Brackett
@Mr0grog
May 05 2016 16:42
ah
Ross Hinkley
@rosshinkley
May 05 2016 17:43
fixing to work through 2.4.0
unless there's an objection
Rob Brackett
@Mr0grog
May 05 2016 17:43
what is 2.4.0?
Ross Hinkley
@rosshinkley
May 05 2016 17:43
the next version?
Rob Brackett
@Mr0grog
May 05 2016 17:44
oh, nm
Ross Hinkley
@rosshinkley
May 05 2016 17:44
sorry, i should have been more specific :)
Rob Brackett
@Mr0grog
May 05 2016 17:44
no, it was reasonable
didn’t see that you’d queued up things into the milestone
Ross Hinkley
@rosshinkley
May 05 2016 17:44
579 looks good btw
thanks for doing that
Rob Brackett
@Mr0grog
May 05 2016 17:48
np
minor note: maybe a good policy to not accept a PR w/out tests unless a good argument is clearly stated in the discussion about why it doesn’t have them?
(or if the PR only affects documentation)
rosshinkley @rosshinkley nods
Ross Hinkley
@rosshinkley
May 05 2016 17:49
i assume you're referring to the chromium arguments one
you make a valid point, although the only "switches" test is to assert construction
(removing that one from 2.4.0 for the time being)
Rob Brackett
@Mr0grog
May 05 2016 17:55
I have no concerns otherwise!
Ross Hinkley
@rosshinkley
May 05 2016 17:55
it's a fair point :)
and one i should have considered
but i like to live dangerously
:P
Rob Brackett
@Mr0grog
May 05 2016 17:56
Yeah, the existing switches test is not very good. Probably should be a bug to fix that :)
Ross Hinkley
@rosshinkley
May 05 2016 17:59
not exactly sure what you'd do to fix that... assert that the switches are set inside electron, i guess?
probably worth an investigation
Rob Brackett
@Mr0grog
May 05 2016 18:11
^ yeah
maybe a test-only plugin that spies on the underlying electron machinery
makes sure it gets ticked
Ross Hinkley
@rosshinkley
May 05 2016 18:13
seems reasonable
and i'm making the hopefully safe assumption that information is exposed by electron... somewhere
Ross Hinkley
@rosshinkley
May 05 2016 18:34
@Mr0grog do you want me to file that issue?
Ross Hinkley
@rosshinkley
May 05 2016 18:43
aaaand submitted
Rob Brackett
@Mr0grog
May 05 2016 19:03
oh, sorry, a little busy ATM
Ross Hinkley
@rosshinkley
May 05 2016 19:03
no worries, i figured