niklasb / webkit-server

[not actively maintained] The C++ webkit-server from capybara-webkit with useful extensions and Python bindings
MIT License
48 stars 38 forks source link

Async requests #4

Closed ghost closed 11 years ago

ghost commented 11 years ago

I have a scenario in which the user clicks a 'login' button, an ajax request is sent to the server and on success, they are redirected to the logged in homepage.

I am trying to write a test for this, with click(wait=True), however I'm not sure that the 'wait' will wait for the request to come back. If I include time.sleep(0.5), then the test passes, but otherwise it fails.

Is there an 'asyncronous mode' or am I doing something wrong?

niklasb commented 11 years ago

the Wait command basically waits until Webkit reports the pageFinished event. It might well be that your web page is not fully loaded, maybe there's a dangling HTTP request or something? It might also be that the page is already loaded if you call Wait, that's a more tricky case. Typically dryscrape is used for accessing remote pages, which don't load too quickly. Could also be that there is no page loading involved at all, that the button click merely executes some Javascript. In that case, you have no chance to get this right rather than waiting for some DOM change or just sleeping as you already do.

ghost commented 11 years ago

Unfortunately its the latter reason. I guess we will just have to put a sleep in there. Thanks for the timely response.