Selenium AJAX
The objective of this article is to briefly discuss the common issues that one may face when trying to automate an AJAX control using Selenium Automation tool. Let us start with the definition of AJAX.
What is AJAX?
- AJAX is about updating parts of a webpage, without having to reload the entire webpage.
- AJAX stands for Asynchronous Javascript and XML. It is a technique for creating fast and dynamic webpages.
- AJAX allows webpages to be updated asynchronously by exchanging small amounts of data with the server in the background.
- Examples of applications using AJAX are - Google Search, Gmail, Google Maps, YouTube etc.
Scenario
Let us say that we have a webpage that contains a text field and a button. The initial value in the text field is "Old Value". Now as the user clicks the button, some AJAX magic will happen and the value in the text field will be updated from "Old Value" to "New Value" without reloading the webpage.
The question here is how do we go about testing such functionality?
An obvious approach would be:
- Open the web page.
- Click on the button &
- Check for the updated value in the text field.
What happens is that the asynchronous nature of AJAX means that the result did not reach from the server immediately but our but our Selenium test case checked for the updated result immediately and failed to fetch the new updated value.
How do we rectify such a problem?
The trick here is to wait for the result to come from the server. Selenium WebDriver supports two types of waits:
- Explicit Waits &
- Implicit Waits
This concludes our basic article.
No comments:
Post a Comment