Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous injected JS doesn't get to finish #123

Open
danvk opened this issue Dec 17, 2014 · 2 comments
Open

Asynchronous injected JS doesn't get to finish #123

danvk opened this issue Dec 17, 2014 · 2 comments
Labels

Comments

@danvk
Copy link
Collaborator

danvk commented Dec 17, 2014

@ihodes ran into this, if you inject some JS along the lines of:

window.setTimeout(function() {
  // click something
}, 1000);

Then the screenshot gets taken before the click happens. The page.waitForReady function waits for XHRs to complete, but it doesn't wait for other async code to run. I'm not even sure if this is possible with Phantom.

@danvk danvk added the bug label Dec 17, 2014
@bslatkin
Copy link
Owner

Yeah this is hard. We could try to override setTimeout to register / wrap callbacks? What I worry about is it's often the case that a page always has N callbacks set at all times and the set of outstanding callbacks never goes to zero.

One option is to have a "trigger test end" callback in the global scope like window._dpxdt_Done(). Then the injectJs can set the whole page up, do its own timeouts, and trigger the load. You can boost the timeout to make room for this to happen, or maybe we could have another flag per test which says to always wait for the Done() call to happen?

@danvk
Copy link
Collaborator Author

danvk commented Dec 17, 2014

The flag + done() approach would work; it's similar to how qunit solves the problem.

I'd like to look into how CasperJS implements its waitFor methods. It's a much nicer API if we can make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants