Friday, 5 August 2016

Why Cucumber ?

It's an open debate for all the Automation Test Engineers. Few like it, few hate it.

For some it beautifully defines your scripts but for some it can be just another burden that adds to the list of tools.

The truth lies behind both the thoughts. For first point, cucumber helps in abstraction of code and plain english sentences & for the second point, its just doing what other tools do without adding another layer on their code.

Cucumber actually helps product owners & business analysts to identify the coverage of test scripts. Also , it helps in enhancing test coverage by people who don't have the knowledge of the code.

If you see the reporting of cucumber its so easy to read & understand it. Any person who doesn't know the code of automation script can also understand what all steps have been passed & failed.

Is it only useful in organisation of Business Analysts or direct clients ?

I think when I write my code with plain readable English sentences, its make it more objective. As a coder, If I just write the code somewhere the 'why' part is lost in all those lines of code. But if we write feature files, it will be somewhere in the back of mind the objective of that code.

Also, even if there is no direct client but there are developers or managers who want to see our report or tests. Is it meaningful or interesting for them to read each line of code to understand the motive of script. In this case, these feature files will be the best way to make a hold of it.

Also the benefit is to collate requirements, manual tests & automation tests at one place. And tools like cucumber helps in achieving this

Page Factory for Selenium POM Frameworks

What is Page Factory (PF) ?

Page Factory is an inbuilt optimized page object model concept for Selenium. Page factory Class is derived from Page Object Pattern. It can be used in any kind of framework like Data driven, modular & keyword.

Advantages of PF

1. It finds WebElement every time it comes. Hence, no StaleElementExceptions should come.
2. Also we should not see NoSuchElementExceptions.
3. Helps in separating Page Object Repository & Test Methods.

How to Use PF ?

- @FindBy annotation is used to find WebElement.
- initElements method is used to initialise web elements.
-@FindBy can accept tagName, partialLinkText, name, linkText, id, css, className, xpath as attributes.

Example for using Page Factory :

Page Factory class would look like this :

Also you need to initiate this PF class in the constructor of your page object class, as follows :

PF actually keeps all the elements in cache which helps in easy & fast access to web elements hence it increases the speed of automation scripts as well.