Header
OV_Static and Dynamic Objects
Understanding Static and Dynamic Web Elements
Static Web Elements
A static web element is an element whose attribute values do not change. For example, the attribute 'font-family' for a website's logo text typically remains constant. Identifying static web elements accurately is crucial for building reliable and maintainable test automation scripts. Misidentifying these elements can lead to ineffective or failed test executions.
Scenario: Assume a Login page where the username field's “name” attribute is static, while its “id” attribute is dynamically generated each time the page is loaded. Here, using the “name” attribute is the best practice for identifying this static web element since its value remains constant.
Dynamic Web Elements
A dynamic web element is one whose attribute values may change. For example, the value of the 'src' property of a carousel image on a Homepage might vary. Identifying dynamic web elements correctly is critical for creating effective test automation scripts that can handle changes in the application.
Scenario: Let's consider, a news website where the main headline's “id” attribute changes based on the latest news story. In such cases, it would be better to identify the headline using a static attribute like “class,” or if there's a pattern in the dynamic attribute, we could use regular expressions. You can also customize the value to accommodate predictable dynamic changes.
Avoid attributes with unpredictable dynamism for identifying web elements, as this could lead to unreliable test scripts.
Setting Locator Priorities
The types of locators can be:
Link
Name
ID
XPath
CSS
This sequence is adjustable according to your specific needs.
Before we get in to creating objects, let’s cover some fundamentals.
Rules for Duplicate Objects
You can add an existing object under a different page, but QAS renames the object automatically. This is to avoid confusion when referring to the objects in your test cases.
When you add an object with the same name and same locator values manually, QAS either does not allow it or might rename the object automatically depending on the time span. This is to ensure the unique identification of each object.
You cannot add the same object with the same name and same locator values under the same page. This is to prevent ambiguity during test execution.
Use Case for Duplicate Objects:
Suppose you are testing a web application that has multiple pages, and each page has a Submit button with the same ID submitBtn
.
If you try to add the "Submit" button object from the second page while it already exists from the first page, QAS will automatically rename the second object to avoid confusion. For example, it might rename it to
submitBtn_1
.If you try to add another "Submit" button object on the first page with the same ID `submitBtn, QAS will not allow it to avoid ambiguity during test execution.
If you try to add a Submit button object with the same ID
submitBtn
but manually change the name toSubmitButton
, QAS might still rename it automatically if it detects that the locator values are the same. This is to ensure that each object can be uniquely identified not just by its name but also by its locator values.
Footer