Sam R.
Sam R.

Reputation: 16450

Selenium WebDriver and generic wait or delay

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.

Upvotes: 2

Views: 3177

Answers (2)

Shishir M
Shishir M

Reputation: 29

This should work:

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

driver.sleep(1000);

Upvotes: 0

alecxe
alecxe

Reputation: 473983

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:

Upvotes: 2

Related Questions