Book Reference: Software Automation Testing Secrets Revealed
Widely acknowledged one of the best practical guide to software test automation, Narayanan Palani's Automation Labs has been helping freshers write better automation test scripts for the last three years. Now this classic book has been fully updated and revised with leading-testing tools—and hundreds of new script samples—illustrating the art and science of automation testing. Capturing the body of knowledge available from strong professional experience and industry best practices, Palani synthesizes the most effective techniques and must-know principles into clear, pragmatic guidance. No matter what your experience level,test environment, or project size, this book will inform and stimulate your thinking—and help you build the highest quality automation scripts.
Discover the timeless techniques and framework designing methods that help you:
• Design for TestNG,Visual Studio, Jenkins,Excel VBA,Selenium, HP UFT (formerly QTP),Ranorex, RFT and other wide ranged QA Testing Tools.
• Reap the benefits of well built selenium webdriver automation framework!
• Apply powerful programming techniques to build well-estabilished data driven framework,keyword driven framework, hybrid framework,Agile Continuous Integration Automation Framework.
• Exploit opportunities to design Web services based REST/SOAP Automation Frameworks and SQL Automation to validate Database!
• Use construction practices using Object Recognition Technology of test automation tools and capture dynamic web elements.
• Debug problems in software development life cycle to improve testing process using test estimation techniques, tool selection process.
• Build quality automation scripts by understanding the machine learning basics of selenium automation framework
• Resolve automation issues and introduce cucumber, specflow based Behavior Driven Development and Test Driven Development in functional testing.
3. 6.1 What is Page Object Design Pattern?
• Page Object is a Design Pattern which has become popular in test automation for enhancing test maintenance
and reducing code duplication.
• A page object is an object-oriented class that serves as an interface to a page of your AUT.
• The tests then use the methods of this page object class whenever they need to interact with that page of the UI.
• The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within
the page object needs to change.
• Subsequently all changes to support that new UI are located in one place.
• Page Objects are meant to encapsulate the messy internal state of a page.
• In a simple form of Page Object Model, Create two packages – one will contain one java file which contains the
objects of all the pages in an application and other package will contains all smoke test java files which will utilize
those objects.
4. 6.2 Creating Objects In Page Object Design Pattern
• Create all the page objects in one java file (or create the objects on page level under one java folder )and then
create the test file in other file (or under other java folder). There is a Page Factory in the support package that
provides support for this pattern. Using Page Factory under test file, we can access these page objects in other
java file.
5. Page Factory
• In order to support Page Object Design Pattern. Web Driver Supports a library that contains a factory class.
• There is a Page Factory in the Support package that provides support for this pattern.
• Using Page Factory under test file, we can access these page objects in other java file.
• While creating any object, if you use the Page Factory , you can assume the fields are initialised, else
NullPonterExceptions will be thrown.
7. @FindBy and @FindBys Annotation
• Fields are decorated if and only if they have @FindBy or @FindBys annotation.
• Default search strategy "by id or name" that works for WebElement fields is hardly suitable for lists because it is
rare to have several elements with the same id or name on a page.
• If you never use a WebElement field in a PageObject, there will never be a call to "findElement" for it.
10. InitElement Methods
• Page Factory class provides four variations of InItElements methods which can be used based on the project
requirement.
• Based on the requirement, we can use one or all of them in a single framework so that we can attain the
respective functionality.
1. ElementLocatorFactory:
InitElements method will contain an “ElementLocatorFactory”.
ElementLocatorFactory: is used for providing the mechanism for fniding elements.methods.
Syntax:
• initElements(ElementLocatorFactory factory, java.lang.Object page)
11. InitElement Methods
2. FieldDecorator
• InitElements method will contain an FieldDecorator.
FieldDecorator is used for decorating each of the fields.
Syntax:
initElements(FieldDecorator decorator, java.lang.Object page)
12. InitElement Methods
3 .Page Class
.InitElements method which will contain a page class.
Syntax:
• initElements(WebDriver driver,java.lang.Class<T> pageClass)
• Instantiate an instance of the given class, and set a proxy for each of the WebElement and List fields that have
been declared, assuming that the field name is also the HTML element's "id" or "name". Means there will be an
element that can be located using the xpath expression.
13. InitElement Methods
4.PageClass Variation
InitElements method will contain a page class similar to variation:
Syntax:
• initElements(WebDriver driver, java.lang.Object page)
• As initElements(org.openqa.selenium.WebDriver, Class) but will only replace the fields of an already instantiated
Page Object.
14. 6.3 Advantages of PODM
The following are the advantages of Page Object Design Pattern:
• There is clean separation between test code and page specific code such as locators (or their use if you’re using
a UI map) and layout.
• There is single repository for the services or operations offered by the page rather than having these services
scattered through out the tests.
In both cases this allows any modifications required due to UI changes to all be made in one place.
15. 6.3 Dis Advantages of PODM
The following are the disadvantages of Page Object Design Pattern:
• There is no separation between the test method and the AUTs locators (IDs in this example); both are
intertwined in a single method. If the AUT’s UI changes its identifiers, layout, or how a login is input and
processed, the test itself must change.
• The id-locators would be spread in multiple tests, all tests that had to use this login page.