Introduction to Selenium
Selenium is an open source web based automation testing tool which is used for functional and regression testing. which allows us to automate web application;Selenium architecture is very simple to understand and utilised to perform testing across multiple browsers and platforms. it has its own core library along with interfaces, packages and classes. It is not a record and playback tool. It supports multiple languages which gives tester flexibility to use language (Java, .net, Python, etc.) of their choice.
Selenium Architecture divides into 4 parts:
- Selenium IDE
- Selenium RC
- Selenium Web Driver
- Selenium Grid
Languages and Platform supported by Selenium
Selenium supports all the operating system either windows or unix, it supports ruby,python,c# and java.
Selenium provides most of the readymade functionality to handle browser activities which makes the automation very handy and helps to play with any actions performed on web application. But Handling Popup windows is not possible using Web Driver so to perform activity on the pop up window ,one freeware tool is used which is known as Auto IT. Auto IT is also freely available tool which can be integrated with selenium.
POM (Page Object Model) is a design pattern which has to be implemented while creating a selenium framework by which code reusability can be achieved.
Locator is an address of the web element(Text Box,Buttons,Check Boxes,Links etc) on which some actions take place. Each and every web Element in a webpage is associated with some identifier which can be used as a locator in our automation script. There are various ways by which locator can be found out such as tag Name, id, name, class Name, link Text, partial Link Text, css, xpath etc. Below image shows that sign up link in MMT site is associated with id,class and link text i.e sign up.
Synchronization is the way of bringing two or more components to work on the same pace. While executing automation script the target application might not load elements due to below issues:-
- Network issues
- Application issues
So there is a need to synchronize our automation script in such a way that both the components should work with same speed. Selenium provides some methods i.e. Implicit wait, Explicit wait, Custom wait which has to be incorporated to achieve synchronization.
Getter and Setter for validation
Selenium provides Advanced User Interactions API to handle various types of keyboard and mouse events. This Api contains the Actions and the Action classes that are needed when executing these events. Actions class contains methods related to drag and drop, double click, clicking multiple elements etc.
TestNG is a framework commonly used for automation testing. This is inspired by Junit and Nunit but it has more advantages over those.
Benefits of TestNG
- Annotations are biggest advantage
- Builtin methods for Execution and Logging
- Supported by many tools and plugins(Maven, Eclipse,ant,etc)
- Supports parameters,Groups,Data Provider
- Parallel Execution
- Efficient execution model
Execution in TestNG
- If you use TestNG for Execution you done have to use main() method. We have @Test method which is a replacement of main()
- Program execution will start from this annotation if we don’t have any other(Like @Before Method,@Before class, etc) in a class.
- Parallel Execution:
Parallel execution means we can run many classes at a time parallely. For parallel execution, TestNG provides a file called TestNG.xml
If you create a file by right click on project and select convert as TestNG
By giving a parameter called “Parallel” in Suite level or class level , Parallel execution can be achieved.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1" verbose="1" parallel="classes" thread-count="2"> <test name="MainTest1" > <packages> <package name="test.sample1" /> </packages> </test> <test name="MainTest2" > <packages> <package name="test.sample2" /> </packages> </test> </suite>
In this Example we have implementer parallel execution in class level by defining thread-count to 2.
Annotations and Parameter
Groups are the parameter inside @Test annotation, if you define a group name with multiple Test Cases, and if you want to run them separately, like smoke suite, this can be achieved in TestNG.
Before Method and After Method
We have different annotations like @Before method and @After method which will achieve setting and termination of drivers for all the Test methods only once by defining these type of annotations.
@parameter is an annotation which will provide some parameter for Test method. You can provide username and password by using this
Listeners are the interface between a script and TestNG. This will listen each and every status of Scripts and perform the defined actions accordingly by implementing ITest Listeners
For example, If test fails what should be the action to be performed will be defined by testFails().
Test Listener Adapter is a class which implements an ITest listener interface to show all the logs step by step in TestNG
TestNG is very useful to generate a report customize and email reports using ITest Listener and ITest Reporter interfaces. Built In Emailable report will generated with in output folder which does not need any listeners .Overall, TestNG is an already available designed framework of third party which can be implemented with in selenium with many advanced options