I have a web page which makes an AJAX call to update data in the database. I want to write a cucumber test to enter the data on the page, triggering the AJAX call, and then verify that the data was saved in the database.
When I fill in selectized with "BP"
And I enter selectized
And Bug "222222" should have tag "BP"
However, because AJAX is asynchronous, cucumber is testing that the bug has a tag before the controller has finished creating the data.
How can I have the test wait until the AJAX call is completed?
You can wait for an AJAX using selenium JavascriptExecutor
example:
public boolean isAjaxDone() {
JavascriptExecutor js = (JavascriptExecutor) driver;
Object result = js.executeScript("return document.readyState");
return result.equals("complete");
}