Monday, 12 January 2015

Getting Off On The Right Foot With Your Test Automation Project Part-2!!!

Locators, locators, locators

Automation drivers, frameworks, and tool sets need to understand how to find elements on the page to interact with. “Locators” or “Find Expressions” are common terms used for the mechanics of how the automation tool is able to find one specific element on a page. Locators can be based on a number of factors around where and how the element is displayed in the page’s Document Object Model, or DOM. Too often automation test writers will use inflexible locators that cause tests to break when a small change is made to the page. Many times this can be traced back to selecting an overly complex XPath-based locator instead of an ID attribute, or if no ID is available, then at least another method, or at the minimum a better-crafted XPath. As a practical example, consider the following graphic that
shows an absolute XPath which starts at the document’s root and narrows down to the input field for a username. This overly complex XPath is extremely brittle and will break if any element is added anywhere to the page above the username. It will also break if the username field is moved.


Position-Based Locators

Another problem teams inflict upon themselves are locators tied to an element’s specific position on the page. We’re not talking about X-Y coordinates, but rather things like row or column order. If we’re trying to work with an edit test for the record holding the Jayne Cobb person shown below, then we shouldn’t have to worry about the test failing if the table’s sort order changes. Adding or moving columns in the table also shouldn’t break the test. (Although you may want separate tests verifying the proper sort and column order!).


Dynamic Content, Big Headaches

AJAX and frameworks/tools like JQuery give us amazingly responsive web pages, but they also make it extremely hard to deal with timing issues for our test automation scripts. Our human eyes guide us to waiting until an AJAX call completes, or JQuery has finished rendering a new control on a page.Unfortunately, automation scripts don’t work the same way.Subtle synchronization and timing issues cause scripts to fail because the needed elements aren’t currently on the page -the page is still waiting for that AJAX or JQuery call to finish their work.

Forgetting Good Software Design Principles

Test code should be treated like production code. Because it is production code! We should use the same careful design approaches in our test software as in the systems we’re testing. Avoiding duplication of locators is critical to a sustainable test suite. Ensuring we’re creating granular tests which can be reused as composable blocks is just as critical. Failing to follow good design principles in test suites will guarantee exploding maintenance costs as the tests and system evolve.

Please click here to read more on this topic.

0 comments:

Post a Comment

 
Back To Top