Learning Objectives
Review
Create a new test script via cloning
Xpath locator
AJAX Testing
Fixed Waits
Selenium Explicit Waits
My way of handling waits in Ruby
Test Case 12
Knowledge Point: AJAX
Ajax (Asynchronous JavaScript and XML") makes websites dynamic. You must have seen it before (the loading animated image), such as sending an email in Gmail. AJAX makes test automation more challenging. To understand that, please compare two types of HTTP requests.
1. Normal HTTP Request
In this mode, the test script interacts with the web app synchronously. In other words, test step 2 will be only executed after test step 1’s response is fully returned. That’s how we have been writing the test scripts so far. By the way, this is the default and natural style.
2. AJAX Request
In AJAX mode, a dummy response (my term, strictly not correct terminology) is returned immediately. The actual data will be sent later. From test automation’s point of view, if test step 1 invokes an AJAX request (such as clicking the ‘Pay now’ button on AgileTravel’s payment page), test step 2 starts immediately (after receiving the dummy response). However, Test Step 1’s actual response is not received yet. Most likely, the upcoming test steps will fail.
The Solution: Wait for the full response.
Knowledge Point: Waiting in Selenium
Task:
Run the test case.
The assertion step failed after clicking the ‘Pay now’ button.
But this step passes in the debugging mode.
This means: the test step functionally is fine, just a timing issue, related to the previous step.
Keep reading with a 7-day free trial
Subscribe to AgileWay’s Test Automation & Continuous Testing Blog to keep reading this post and get 7 days of free access to the full post archives.