Automation Frameworks are mainly useful to reduce the test effort and maintenance costs. Also these frameworks are set of rules and guidelines used for automating the Test cases. This tutorial gives an overview of all the Automation frameworks for the QA professionals interested to switch to Automation Testing.
Modular Framework:
Modular Framework is the approach where all the test cases are first analyzed to find out the reusable flows. Then while scripting, all these reusable flows are created as functions and stored in external files and called in the test scripts wherever required. Advantages:
Modular division of scripts leads to easier maintenance and also the scalability of the automated test Scripts are independent to write. Disadvantages:
Since data is still hardcoded in the script, the same test case cannot be run for multiple data values without changing data after each run.
Additional time is spent in analyzing the test cases to identify with reusable flows.
Good programming knowledge is required to create and maintain function libraries.
Automation Frameworks
Datadriven framework: Example: DataDriven Fwk using Data Provider
In Data Driven Framework, the data is NOT hard-coded in the test scripts. Instead, it is stored in some external files. The test script first connects to the external data source and then extracts the data from that source. Advantages
Since the data is kept separate from the test script, the same script can be run multiple times for different sets of data (which can be kept in multiple rows in the data sheet).
Changes made in the test data don’t affect the test scripts in any way and vice versa. Disadvantages
Additional effort and good technical expertise is required to create functions that connect to the external data sources to retrieve the data.
Keyword framework:
In Keyword Driven framework, you can create various keywords and associate function with each of these keywords. Then you create a Function Library that contains the logic to read the keywords and call the associated action. Advantages
The keyword and function libraries are completely generic and thus can be reused easily for different applications
All the complexity is added in the function libraries. Once the libraries are ready, it becomes very easy to write the actual test script steps in excel sheets. Disadvantages
Lot of time and effort needs to be spent initially to create the function libraries.
The benefits of the keyword driven framework are realized only after it has been used for longer periods of time.
Very high programming skills are needed to create the complex keyword library functions.
Hybrid framework:
Hybrid Framework is a framework that is created by combining different features of any of the frameworks mentioned above. Based upon your requirements, you can combine the features of any of the above frameworks to come up with your own version of Hybrid Framework. Advantages
The main advantage of this approach is that you can use the best features from all the types of frameworks to create your own. Disadvantages
The framework is highly complex and needs very good programming expertise and experience to build a Hybrid Framework from scratch.
1. What are Listeners?
• TestNG listeners are set of class exposed into TestNG framework which we can utilize to modify default TestNG’s behavious.
• As the name suggests Listeners “listen” to the event and behave accordingly.
• It allows customizing TestNG reports or logs or to take a screen shot.
• Listeners contains unimplemented methods(blank body and we can customize it)
ITestListener
ITestListerner is an interface which implements with TestNG .
We can either extend ‘TestListenerAdapter’ or implement Interface ‘ITestListener’ for test running. For custom listener we extends TestListenerAdapter which implements ITestListener. Hence no need to override all methods of interface. ITestListener contains below unimplemented methods
ITestListener
1
2
3
4
5
6
7
OnStart-OnStart method is called when any Test starts.
onTestSuccess-onTestSuccess method is called on the success of any Test.
onTestFailure-onTestFailure method is called on the failure of any Test.
onTestStart-Invoked each time beforeatest will be invoked.
onTestSkipped-onTestSkipped method is called on skipped of any Test.
onTestFailedButWithinSuccessPercentage-method is called each time Test fails but is within success percentage.
onFinish-onFinish method is called after all Tests are executed.
ISuiteListener
ISuiteListener
1
2
onStart()&onFinish().
Wheneveraclass implements this listener,TestNG guarantees the end-user that it will invoke the methods onStart()and onFinish()before and after runningaTestNG Suite.
IInvokedMethodListener
IInvokedMethodListener
1
2
afterInvocattion()&beforeInvocation()
It makes the call before and after every Method.
IExecutionListener
IExecutionListener
1
2
3
onExecutionStart()
onExecutionFinish()
Method onExecutionStart()run before the TestNG starts running the suites and onExecutionFinish()run after TestNG has completed running all the test suites.
Steps to create a TestNG Listener Step1
• Create a Test class for automation Step 2
• Create a listener class that implements TestNG listeners
• import org.testng.ITestNGListener
• Add unimplemented methods
• Customize the methods Step 3
Implement the listeners to the Test class
Method 1: class level
• use listeners annotation @listeners (packageName.ListenerClassName)
• Execute the Test class. Methods in the Listener class are called automatically according to the behavior of methods annotated as @Test.
Method 2: Multiple classes
• Create a testng.xml and add listeners tag in XML.
java.awt.Robot class is used to generate native system input events for the purposes of test automation, to perform mouse and keyboard actions.As interacting with windows dialog is a limitation in selenium. So, we need to use either AutoIT or Robot class in Selenium Webdriver to interact the Windows Dialog. In this topic we are discussing about the usage of Robot Class.
Test Scenario
1. Access the website url http://www.indeed.co.in.
2. Click on upload resume link.
3. Implement the Logic using the java.awt.robot to provide the absolute location of the file.
4. Capture the full page of the screenshot by providing the dimensions.
Uploading a File using Robot Class
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.tq.selenium;
importjava.awt.AWTException;
importjava.awt.Dimension;
importjava.awt.Rectangle;
importjava.awt.Robot;
importjava.awt.Toolkit;
importjava.awt.datatransfer.StringSelection;
importjava.awt.event.KeyEvent;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.IOException;
importjavax.imageio.ImageIO;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
publicclassRobotEx{
public static void main(String[]args)throwsAWTException,InterruptedException,IOException{
What is Apache POI?
Apache POI is a popular API that allows programmers to create, modify, and display MS Office files using Java programs. It is an open source library developed and distributed by Apache Software Foundation to design or modify Microsoft Office files using Java program. It contains classes and methods to decode the user input data or a file into MS Office documents.
• HSSF (Horrible Spreadsheet Format) : It is used to read and write xls format of MS-Excel files.
• XSSF (XML Spreadsheet Format) : It is used for xlsx file format of MS-Excel.
1. Executes JavaScript in the context of the currently selected frame or window.
2. The script fragment provided will be executed as the body of an anonymous function.
3. Within the script, use document to refer to the current document.
4. To interact with Highcharts: Interactive JavaScript charts for your webpage,
JavascriptExecutor will be helpful.
Reference Link->https://www.highcharts.com/
JavascriptExecutor Program:
JavascriptExecutor Example
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.totalqa.selenium;
importorg.openqa.selenium.By;
importorg.openqa.selenium.JavascriptExecutor;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.firefox.FirefoxDriver;
publicclassJavascriptEx{
public static void main(String[]args)throwsInterruptedException{
1. The static keyword is applicable for the Class Members.
2. The static Class Members are accessed using Class Name.
3. Non static members are accessed using through reference variable or object.
4. The static members are loaded once into the memory for program execution.
5. The static members are shared across the objects.
6. Non-static & Static Class Members are inherited to the subclass
Static Program:
Static Example
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package org.totalqa.java;
publicclassStudent{
int rollno=1;
char section='A';
static String schoolName="ABC";
public static void main(String[]args)
{
Student s1=new Student();
s1.rollno=2;
s1.section='B';
System.out.println(s1.rollno);
System.out.println(s1.section);
Student s2=new Student();
System.out.println(s2.rollno);
System.out.println(s2.section);
System.out.println(Student.schoolName);
//Can we call static class members using objects?? Yes
An overview of java-Collections-List,Set,Map,Queue Interface are explained in this post. For complete understanding please refer to Sun Certified Programmer for Java 6 Study Guide available in the scribd.com. Please click on this Ebook Link->Kathy-sierra-PDFBooks
is a “GUI-Less browser for Java programs”. It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating Chrome, Firefox or Internet Explorer depending on the configuration used.
It is typically used for testing purposes or to retrieve information from web sites. HtmlUnit is not a generic unit testing framework. It is specifically a way to simulate a browser for testing purposes and is intended to be used within another testing framework such as JUnit or TestNG.
Hands-on with different exceptions in Selenium and Java. Please go through the different scenario’s of Exceptions with Programs,Exceptions and Solution.
Cucumber BDD with Selenium WebDriver and Testng Framework
Cucumber is a Behavior Driven Development (BDD) testing framework that helps the non technical members of the team can easily understand the scenario’s automating by testers. In Cucumber, the feature files plays very important role that contains plain English text written using gherkin language which is easy to understand. Refer to theCucumber Basics
Cucumber-BDD using Page Object Model and Testng Framework:
1. Create a Maven Project with name as ‘cucumbermvn’. Refer to the steps->