2

So I'm desperately looking for a way to delay some executions in WebDriver but I don't seem to find one.

The web app which I try to run black box test against, works with ajax calls but these ajax calls do not render anything on DOM, thus I can't use explicit wait. Also, the implicit only works for find_element statements and again won't be useful.

I had success using time.sleep() but I hope there is a nicer way of delaying the execution.

4
  • What do these AJAX calls return? If you open the browser manually, how would you identify that the load is completed? Thanks. Commented Jul 23, 2015 at 5:04
  • @alecxe, sometime they set cookies and sometime they just store variable on the ng-controller. Commented Jul 23, 2015 at 5:06
  • Thanks, and this is only during the page load, correct? Commented Jul 23, 2015 at 5:07
  • @alecxe, not necessarily. Think of a form that when is submitted, send an ajax call. Before response is received if you click next, you're doomed but after that, it'll take you where it should. And no, the button is not disabled or enabled during this. Commented Jul 23, 2015 at 5:10

2 Answers 2

2

From what I understand (it's 1am here, I may miss something), you need your tests to be synchronized with AngularJS, waiting for outstanding requests and angular to "settle down".

This is what, in Javascript world, protractor solves perfectly - it always knows when Angular is ready and it makes the tests much more natural, you don't even think about synchronization issues - it works smoothly and out of the box:

You no longer need to add waits and sleeps to your test. Protractor can automatically execute the next step in your test the moment the webpage finishes pending tasks, so you don’t have to worry about waiting for your test and webpage to sync.

As for Python, there is pytractor project that sounds like something you should evaluate:

pytractor is an extension to the Selenium bindings for Python. Its goal is to make testing of angular.js applications easier with Python.

It is built on some parts of protractor, the "official" Javascript E2E/Scenario testing framework for Angular.js.

As a red flag, note that the project is not actively maintained. At least, you may study the source and use the ideas introduced in the code.

Note that internally protractor and pytractor inject client-side scripts which are asynchronously executed. In order to wait for Angular to be "ready", they both use angular.getTestability(el).whenStable() (source).


See also:

Sign up to request clarification or add additional context in comments.

7 Comments

This sounds cool, but how does it do that? Does it listen to all ajax calls on the browser?
@norbertpy protractor (and pytractor) injects client side scripts. Before any action executes an async script and use angular.getTestability(el).whenStable() internally (source).
@norbertpy you can actually use driver.execute_async_script() and make a custom wait based on this idea.
Awesome, I'll give it a shot. Thanks.
@norbertpy added some more links. Let me know if you'll need help with the async script and a wait (I'll be afk for a rather long time but I hope I'll come back here). Good luck in solving it. Thanks.
|
0

This should work:

var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();

driver.sleep(1000);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.