ariya / phantomjs

Scriptable Headless Browser
http://phantomjs.org
BSD 3-Clause "New" or "Revised" License
29.47k stars 5.75k forks source link

Synchronous mode #10157

Closed huntc closed 4 years ago

huntc commented 13 years ago

hunt...@gmail.com commented:

In a recent project of mine that uses Phantomjs (1), I found that I had to use recursion to execute multiple tests. The project calls upon Phantomjs to load a list of html pages that represent QUnit pages. The list of test urls is passed as a csv argument to the script. I prefer this mode of operation as opposed to invoking PhantomJS multiple times as it is faster.

I was wondering if it would be useful if WebPage provided a version of its open method that executed synchronously. In my case I would then be able to call the open method within a loop and then do away with recursion.

The entire script can be found at (2).

Thanks.

(1) http://js-testrunner.codehaus.org/ (at present largely undocumented) (2) http://git.codehaus.org/gitweb.cgi?p=js-testrunner.git;a=blob;f=src/main/js/org/codehaus/jstestrunner/run-qunit.js

Disclaimer: This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #157. :star2:   13 people had starred this issue at the time of migration.

ariya commented 13 years ago

roejame...@gmail.com commented:

Does this topic help you out*? There are also other pure-JS ways to accomplish this without sacrificing asynchronousness (issue 66).

huntc commented 13 years ago

hunt...@gmail.com commented:

Hi and thanks - I'm familiar with the topic and see that the solution being proposed is one based around providing a JS one. That's ok (and I already have a js solution based on recursion), but I'm particularly interested in whether it would be useful to extend the open method to incorporate a sync/async flag; just as the xhr open method does.

Thanks again for the consideration.

ariya commented 13 years ago

ariya.hi...@gmail.com commented:

Additional note: there is a discussion about this in the mailing list.

ariya commented 13 years ago

ariya.hi...@gmail.com commented:

This should be generic, I changed the title.

 
Metadata Updates

ariya commented 12 years ago

erics...@blekko.com commented:

Is there any progress on this?

I would like to test interactions with web site,

Even a simple one like "Open Google. Type a search into the search bar. Click Search Button. When the search finishes, verify that a certain result is listed." i can not achieve this.

ariya commented 12 years ago

ariya.hi...@gmail.com commented:

In the mean time, you should use CasperJS: http://casperjs.org.

ariya commented 12 years ago

erics...@blekko.com commented:

Thank you for the advice, this looks awesome!

fschwiet commented 11 years ago

New to phantom.js, but I've done a bunch of selenium code. I did want to make sequential calls... I spiked using promises, the results are here: https://gist.github.com/fschwiet/5667135

With this approach, there is new layer of nesting only when I want to access the result of an async operation. Otherwise I can chain async operations without nesting. Errors bubble up naturally to a single error handler. Python is not required :)

It will be interesting to see how waits could be handled. From my selenium experience, I can usually limit when I need to wait to cases where I'm looking for a screen element (if an element isn't found, I'd poll the page a bit until it is).

JamesMGreene commented 11 years ago

@fschwiet Sounds like you might be a big fan of CasperJS, give it a look: http://casperjs.org/

Its API is mostly promise-based as well, so it looks relatively synchronous out-of-the-box.

fschwiet commented 11 years ago

maybe, I didn't want to add a dependency on python or another global install.

JamesMGreene commented 11 years ago

@fschwiet I'm pretty sure you can still use CasperJS without external dependencies, you just have to load it differently. See the "Earlier versions of CasperJS" section on the Installation page.

cc: @n1k0: Am I correct on that?

n1k0 commented 11 years ago

@JamesMGreene @fschwiet sure, just set the phantom.casperPath property and inject the bootstrap script, though you'll probably miss the casperjs command-line utility and its convenient options, especially the test subcommand

zackw commented 9 years ago

It's not clear to me whether this is something that should be in core, but I note that a great many of the test cases in our own test suite contain race conditions because the asynchrony of the API isn't fully handled.

huntc commented 9 years ago

I'm ok that this is closed now given the use of promises. I don't think I understood how promises could solve this four years back. Thanks.

ariya commented 4 years ago

Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!