nodeca/navit

Is it possible to call .run but leave the current browser tab open after completion

Closed this issue · 9 comments

I'm using the ability to not teardown the browser on run, but I've found navit still closes all of the tabs on completion of the run. In my particular use I am iterating through a dynamically (and thus random in length) generated set of options in a select list (running and processing the current option before moving on to the next). Right now I work with this by reopening the target url and processing, but what would be most efficient would be to leave the browser tab open. Is this even possible with the current implementation? What I'm envisioning is a 3rd [Parameter] on the run call that when true skips the tab close call in the run. I would be willing to attempt a PR on this, but I'm a C# dev who is just getting his feet wet in node and I'm not very up to speed on mocha tests for PRs.

What are your thoughts, feedback?

I don't like idea to keep tab state between runs. We have batches to record repeating sequences + undocumented afterOpen() handler to run those on init automatically for complex cases.

Tend to reject it.

https://github.com/nodeca/navit/blob/master/lib/index.js#L126-L199 you can register alternate run with another name or monkeypatch existing as you wish. But i'm not sure feature to keep tab open is good for upstream, until people can confirm that it's a popular use case.

Personally it feels a bit like a hack, but it was the best proposal I could come up with. However I'm intrigued on the mention of afterOpen().... I don't want to take up too much of your time but can give a quick rundown of it?

I am going to close this since I'm in agreement that there are better ways (with the use of batches I can get my run calls down to 2: one to get the contents of the select list and one to actually batch through it) and this is kind of a hack implementation (and on that while testing would end up requiring more changes than it is worth really). The other option I saw was to run the select list iteration in a get.evaluate and just use jquery, but then you lose the nice clean .wait('selector') function and start mucking around in setting timeouts and the like. For me an extra run call is a small price to pay for a clean readable stack.

Thanks for your development of this. I know for me and my crew it's been very useful.

However I'm intrigued on the mention of afterOpen().... I don't want to take up too much of your time but can give a quick rundown of it?

  • scripts injection (some special case when global option is not convenient).
  • clever wait for full page init (not just DOM load) instead of stupid fixed pause, when page has dynamic scripts loader.
  • check success status (200 / 301 / 302)

See here how we customize navit for our project https://github.com/nodeca/nodeca.core/blob/master/lib/test/navit_plugins.js

navit's idea is to allow easy modification without needs to change upstream, to make users independent on my personal opinion :).

Added docs for .afterOpen https://github.com/nodeca/navit#afteropen

I'm not sure implementation is beautiful, and this can be changed after feedback. But we already use it now.

Thank you so much for the added info.... and YES! to the wait for init with afterOpen()....it's exactly the kind of feature we were looking for.

Usually people do .wait(500), but that's very ineffective. Also i don't remember what happens when some server methods return json instead of html. Anyway, you can temporary rewrite .afterOpen locally in specific test, or we could do improvments if better ideas found.

This is a new feature, compared to other frameworks, and it needs feedback to stabilize.

nylen commented

@puzrin I want to place my vote for this feature as well. Some workflows are too complicated for a strict sequence of actions. You need real flow control like if and while deciding which path to take next, and so you need a way to run and then leave the browser context alone and the current tab open.

The alternative is to provide the primitives like if and while in the sequence of actions - if this is already possible, for example with batches, then I do not understand how to do it.

Here is a lot more context on what I am doing: https://github.com/nylen/node-banker/commit/1b01b5566e39701f274cb8c8c9d0c6852aa8d724

In this commit I am using navit to scrape transaction history from PayPal's site. It works very well, but in my commit message I've listed several problems with the code. Maybe we can share ideas for how navit can help address the problems?