Automation Framework-Modular,DataDriven,Keyword,Hybrid

Refer to the below Links for Practise
Collections in Java
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume


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

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.

Usage of TestNG Listeners-Types of Listeners

Refer to the below Links for Practise
Collections in Java
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

TestNG Listeners

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)

2. Types of Listeners in TestNG
• IAnnotationTransformer
• IAnnotationTransformer2
• IConfigurable
• IConfigurationListener
• IExecutionListener
• IHookable
• IInvokedMethodListener
• IInvokedMethodListener2
• IMethodInterceptor
• IReporter
• ISuiteListener
• ITestListener




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

ISuiteListener

IInvokedMethodListener

IExecutionListener

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.

ListenerClass

TestClass for Automation

TestNg.XML

Upload a File in Selenium WebDriver Using Robot Class

Refer to the below Links for Practise
Collections in Java
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

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.

Reading and Writing data to excel file using Apache POI

Refer to the below Links for Practise
Collections in Java
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

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.

Step 1 Download the apache poi jar file as below
Access the below link for Downloading the Apache POI.
http://poi.apache.org/download.html

Step 2Click on the Latest Binary Distribution zip file to download.

Apache POI[Poor Obfuscation Implementation File System]

Apache POI[Poor Obfuscation Implementation File System]

Latest Binary of Apache POI for Reading XLSX

Latest Binary of Apache POI for Reading XLSX


Step 3 Add the Highlighted Jars to the project build path.
Apache POI Jars are added to the build path.

Apache POI Jars are added to the build path.


ooxml-lib jars added to the project

ooxml-lib jars added to the project


Program: Reading xlsx using Apache POI (“Poor Obfuscation Implementation”)

Utility Methods-loadXLSX(),writeCellData()

Program: Reading xls using Apache POI (“Poor Obfuscation Implementation”)

JavaScript Executor in Selenium WebDriver

Refer to the below Links for Practise
Collections in Java
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

Javascript Executor

JavascriptExecutor is an interface available in the package org.openqa.selenium.
This interface is implemented by classes ChromeDriver, EdgeDriver, EventFiringWebDriver,
FirefoxDriver, InternetExplorerDriver, OperaDriver, RemoteWebDriver, SafariDriver

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:

Console Output:

static-keyword-in-java

      No Comments on static-keyword-in-java
Refer to the below Links for Practise
Collections in Java
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

Static Keyword:

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:
Output:

2
B
1
A
ABC
ABC
DEF

Java Collections-List,Set,Map,Queue,Iterator,Generics

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

Refer to the below Links for Practise
Selenium Wiki
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

In Collection Framework they are mainly 4 interfaces which mentioned as follows:

List,Set,Map,Queue

List:
List Example: List Console Output:

Set Interface:

Set Example:

Set Console Output:

Queue Interface:

Queue Example:

Queue Console Output:

Map Interface:

Map Example:

Iterator Interface:

Iterator Example:

Generics

Generics Example:

Headless Browser-Selenium,HTMLUnitDriver

      1 Comment on Headless Browser-Selenium,HTMLUnitDriver

Headless Browser-Selenium,HTMLUnitDriver

Refer to the below Links for Practise
Selenium Wiki
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

HtmlUnit

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.

Refer to the document “Getting Started with HtmlUnit” for an introduction.

Selenium WebDriver Example:

1. Add the “htmlunit-driver-xxx-jar” from maven repository using the Download Link.
http://central.maven.org/maven2/net/sourceforge/htmlunit/htmlunit/2.13/htmlunit-2.13.jar
2. Add the downloaded jar to the build path of the project.
3. Execute the below program:

Console Ouput:

Title:Job Search India | Indeed
Title:Selenium Jobs in Bengaluru, Karnataka – June 2018 | Indeed.co.in

Exceptions-Selenium Exceptions,Java Exceptions,Exception Handling

Hands-on with different exceptions in Selenium and Java. Please go through the different scenario’s of Exceptions with Programs,Exceptions and Solution.

Refer to the below Links for Practise
Selenium Wiki
Complete List of Selenium Basics
50 Real Time Interview Questions
Real Time Scenario’s
Java Platform Standard Edition 8 Documentation
Complete List of Java Basics
Java Quiz
Java OOPS Quiz
Selenium Advanced Quiz
Selenium Quiz
Selenium WebDriver Resume

Run-Time Exception: org.openqa.selenium.InvalidSelectorException

Console Output:

Solution:


Run-Time Exception: org.openqa.selenium.StaleElementReferenceException Indicates that a reference to an element is now “stale” — the element no longer appears on the DOM of the page.



Console Output:

Solution:


Run-Time Exception: org.openqa.selenium.NoSuchElementException

Console Output:

Solution:


Run-Time Exception:org.openqa.selenium.ElementNotInteractableException

Console Output:

Solution:


Run-Time Exception:org.openqa.selenium.SessionNotCreatedException

Console Output:

Solution:


Run-Time Exception:org.openqa.selenium.NoSuchSessionException
Session ID is null. Using WebDriver after calling quit()

Console Output:

Solution:


Run-Time Exception:org.openqa.selenium.TimeoutException
Thrown when a command does not complete in enough time.

Console Output:

Solution:


Run-Time Exception: org.openqa.selenium.NoSuchWindowException


Run-Time Exception: org.openqa.selenium.NoSuchFrameException

Cucumber BDD with Selenium WebDriver and Testng Framework

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 the Cucumber Basics

Cucumber-BDD using Page Object Model and Testng Framework:

1. Create a Maven Project with name as ‘cucumbermvn’. Refer to the steps->

http://total-qa.com/advanced-selenium/maven/

2. Add the following dependencies and plugins required for Cucumber,Selenium,Testng.
Refer to the dependencies for Cucumber – Java project


https://cucumber.io/docs/reference/jvm#java

3. Create a following Directory Structure for the project as mentioned below:

Cucumber - BDD,StepDefs,Selenium,Testng,Page Object Model,Maven

Cucumber – BDD,StepDefs,Selenium,Testng,Page Object Model,Maven

4. Refer to the Functional Tests OpenMRSTests.java as mentioned below:

5. Refer to the Step Definitions file LoginPage.java as mentioned below:

6. Feature file Login.feature contains the steps to be performed as part of the scenario:

7. Refer to the testng.xml file.

8. Execute the following maven command with Goals as verify to generate the Cucumber Reports.

mvn verify


Cucumber Reports,CucumberTestReport.json

Cucumber Reports,CucumberTestReport.json