Tips and Hints for Developing Automated Test Scripts


is running slower than the newly introduced wait times during test execution due to external factors such as the LAN having delays or system maintenance. In this scenario, the tester would have to continually guess a new reasonable wait time--each time. Slowing down a script with wait times is not very scientific and does not contribute to the creation of a robust automated test script that playbacks successfully without user intervention.

If possible, testers should avoid introducing artificial wait times or arbitrary sleep variables to synchronize test scripts with the application.

"While" statements or nested "loops" are appropriate techniques used to synchronize test scripts that require synchronization points and will playback successfully regardless of the response times of the application under test. Inserting "nested" loops or "while" statements within a test script also reduces user intervention during the test script playback. For example, I insert "while" statements in recorded test scripts that continually press the Enter button until a scheduling agreement is created no matter how long the application under test takes to generate the agreement. The test script works independently of the response times for the application under test.

Signed-off, Peer Reviewed
As part of the test readiness review criteria, test scripts should be formally accepted and approved prior to starting the test cycle. SMEs, business analysts, and developers should be involved in approving recorded test scripts. The tester writing the automated test script should demonstrate that the test script successfully plays back in the QA environment and, if possible, with various sets of data.

Recording, Playing Back Against Hidden Objects
Scripts might be recorded to populate or double click values for a field within a table grid or an array where the location of this field is not fixed. If the field's location within a table grid or array changes from the time it was recorded, the script might fail during playback. Test scripts often fail during playback because the location of objects that are not displayed or visible within the screen have changed.

In order to playback scripts that are location sensitive or where the location is subject to change, it might be necessary to enhance the script with functionality such as "scroll down," "next page," or "find." Including such utilities ensure that hidden objects requiring playback will be identified, populated, and/or double-clicked regardless of their location within an array, table grid, or the displayed screen.

As an example, I once recorded a script where I scrolled down twice during the initial recording to find an empty field where data could be entered within a table grid. When I played back the script a few weeks later, I had to scroll down four times to find an empty field instead of twice as previously recorded. Consequently the script failed, so I embedded logic in the script that instructs the script to scroll down as many times as necessary to find an empty field. I did this by placing the "next page" function in a "while" loop, which caused the script to "page down" until an empty field was found.

Schedule Recurring Scripts/Store Execution Logs
To circumvent the limitation of test tools not capable of scheduling test scripts on a recurring basis, one can schedule test script via the NT scheduler which supports various command line options. Test scripts should have execution logs stored in a shared drive or within test management tools for test results that are subject to audits.

Create Automatic Notification for Critical Scripts
Test scripts can be enhanced with error-handling programming logic that instantly sends error messages to a wireless device or an email

About the author

AgileConnection is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.