These are chat archives for rosshinkley/nightmare

16th
Mar 2017
Gabin Desserprit
@gahabeen
Mar 16 2017 09:27
Hello guys, I'm struggling since a couple of days to get specific actions to work. I'm using co generators (which is new to me) to be able to sequence actions into prototyped actions. I made a simple example in the following github issue : segmentio/nightmare#1044. Any clue on how to solve my problem ? :)
Gabin Desserprit
@gahabeen
Mar 16 2017 13:48

I've got the following code (a simple example):

Nightmare.prototype._scrollTo = function(destination, options) {

    let action = function(destination, options) {
       let self = this
       return co(function*() {
             // get back some data
            let data = yield self.evaluate(...)
            // do actions based on the data like scrolling for ex
            self.scrollTo(data.x, data.y)
       }).then(() => { return self }).catch((err) => console.log("Error:", err))
   }

    let args = [destination, options]
    this.queue().push([action, args])

    return this
}

And I use it like so:

nightmare
    .goto("http://youtube.com")
    ._scrollTo("bottom")
    .goto("http://wikipedia.org")
    .then((res) => {})
    .catch((err) => console.log("Error:", err)

But it always stops / get stuck at _scrollTo("bottom"). Nothing happens after. Any idea why?

Am I maybe doing things the wrong way? :L
Ross Hinkley
@rosshinkley
Mar 16 2017 14:09
let me get to a real keyboard... there are two issues with what you've posted I think, one with returning nightmare from then and one possibly with your function arguments
Gabin Desserprit
@gahabeen
Mar 16 2017 14:12
Amazing. Tbh I studied Nightmare's code, yours and others and tried many strategies to see what was required or not. Obviously couldn't get to a solution. When you wrote about arguments, would it be regarding a possible missing Done parameter?
Anyway, thanks for reading. I'll wait ;)
Ross Hinkley
@rosshinkley
Mar 16 2017 16:07
sorry @gahabeen, i got ambushed this morning :)
sooo yeah, you've hit the nail: your queued function is missing done
off the cuff i can't remember exactly how that fits together
Gabin Desserprit
@gahabeen
Mar 16 2017 16:08
Ahah no worries. Ok. Well I'll do some more tests adding done then
Ross Hinkley
@rosshinkley
Mar 16 2017 16:09
i also suspect you're going to have a not-so-good time using .then() internal to an action hung off of prototype
the other problem there, just to tie a bow on this
returning a nightmare instance from .then() is going to resolve to undefined
as nightmare itself is a thenable
Gabin Desserprit
@gahabeen
Mar 16 2017 16:09
Humm that's what I've experienced
Ross Hinkley
@rosshinkley
Mar 16 2017 16:10
so you'll end up effectively with .then().then(), which is probably not what you want :)
Gabin Desserprit
@gahabeen
Mar 16 2017 16:10
Humm so should I simply do return co(...)?
Ross Hinkley
@rosshinkley
Mar 16 2017 16:11
you might want to look into .use()
which i know.. i know is terribly documented
Gabin Desserprit
@gahabeen
Mar 16 2017 16:11
Ah ah
Well I tried it actually.
But still got something wrong somewhere I guess
Ross Hinkley
@rosshinkley
Mar 16 2017 16:11
if you've got an example, paste it here, i'd be happy to help :)
Gabin Desserprit
@gahabeen
Mar 16 2017 16:12
Also I felt it would be sexier to simply have prototypes attached xP
Ok, let me have a look and I'll paste some simple samples here :)
Ross Hinkley
@rosshinkley
Mar 16 2017 16:12
if you want that, use .action() with the nightmare-side only
that glues all of that together for you
Gabin Desserprit
@gahabeen
Mar 16 2017 16:12
Tried it too. I'll paste the examples ;)
Ross Hinkley
@rosshinkley
Mar 16 2017 16:13
(to be fair, prototype will probably work for what you want to do)
hahaha
well then! this will be an adventure!
:P
Gabin Desserprit
@gahabeen
Mar 16 2017 16:14
Ah ah. I'm actually building a json based framework to wrap nightmare's features.
So that's a whole adventure
Anyway, let me do some tests with your advices and see what happens next.
Ross Hinkley
@rosshinkley
Mar 16 2017 16:14
sure
i'll be around...ish
things are still on fire, just not as on fire :P
Gabin Desserprit
@gahabeen
Mar 16 2017 16:33
Ofmg.
It works :L
I'll comment my issue with the solutions (with Actions or Prototyped).
Also I better followed how Nightmare's core worked and I found out the issue with what you told me x)
Ross Hinkley
@rosshinkley
Mar 16 2017 16:46
awesome
Gabin Desserprit
@gahabeen
Mar 16 2017 16:52
Anyway, thanks for you time @rosshinkley ;)
Ross Hinkley
@rosshinkley
Mar 16 2017 17:22
no problem