Last updated: Feb 08, 2018 10:52
This article will describe best practices for the developers of your applications to follow to help ensure your test scripts are durable and can withstand application design changes.
By Jeremy Payne
As I've already covered in my YIKES! Article, the developers of your application are the ones who "allow" you to do your job. The developers can drastically reduce your efforts to automate and maintain your test scripts by following the best practices as outlined below.
The key to having durable automation tests is the use of unique identifiers for locating objects in the application. If you must change your object locator because the text of a link changed, the text of a button changed, or the location of something changed this would make your life as an automation tester a nightmare. You would potentially be changing every test case every build! Below I will define unique identifiers that you can use on Web, Android, and iOS applications.
By their nature ID attribute associated with web elements are supposed to be unique. When automating a test for a web application, in theory, you should always be able to use the syntax below to achieve your goals.
The problem with HTML is that it is not a strict language. Therefore even if the ID was misused in some way this would not throw an error when the code was developed and will not cause the application to functionally fail.
- Ensure all objects on the page have a unique id attribute associated with them
- Depending on the "framework" used by the developer the ids themselves could be dynamically generated and NEVER be the same when the page loads from one time to the next. In this case the developer could create a custom attribute to use as the unique identifier for you.
Android's unique identifier is the resource-id attribute
iOS's unique identifier is the Accessibility Label
You may find the Android and iOS attributes aren't exposed through the object tree and if this is the case, then work with your application developers to expose them. Once exposed, ensure the attributes are unique per object.
Set them and forget them!
One other thing that is critical to stress is once the attribute values are set then leave them be. The goal is to have a unique id which will remain the same for each object utilized in your automation. If these attribute values change then your script will break and require updating.