Performance Testing using Jmeter and Selenium WebDriver

Refer to the below Links for Practise
Complete JAVA QUIZ
Selenium Advanced Quiz
50 Real Time Interview Questions
Selenium Quiz
REST API QUIZ

JMETER
The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

Apache JMeter features include:
Ability to load and performance test many different applications/server/protocol types:
• Web – HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)
• SOAP / REST Webservices
• FTP
• Database via JDBC
• LDAP
• Message-oriented middleware (MOM) via JMS
• Mail – SMTP(S), POP3(S) and IMAP(S)
• Native commands or shell scripts
• TCP
• Java Objects

Scenario:
Execute the Selenium Scripts in JMETER and verify the average response time taken in the execution of Selenium Scripts.
1. Download the Apache JMETER zip file from this link -> https://jmeter.apache.org/download_jmeter.cgi
Example: Download apache-jmeter-x.0.zip file.
2. Unzip the file and verify the contents of the JMETER.

Apache JMeter Directory Structure


3. Download the jmeter-plugins-webdriver from this link https://jmeter-plugins.org/?search=jpgc-webdriver and extract the contents and copy in the JMETER/lib folder.
Selenium-Jmeter Jar

Selenium-Jmeter Jar


Example: Download jpgc-webdriver-2.3.zip file.
4. Download the Java Native Access jars and JNA Platform jars and extract the files and copy in the JMETER/lib folder as shown below:

Java Native Access[JNA] allows you to call directly into native functions using natural Java method invocation. The Java call looks just like the call does in native code. Most calls require no special handling or configuration.
5. Open JMeter bat available under JMeter/bin folder.
• Right Click on Test Plan->Create Thread Group.
• Right Click on Thread Group->Select Sampler->WebDriver Sampler
• Right Click on Thread Group-> Select Config Element->Firefox Driver Config.
• Right Click on Thread Group->Listener->View Results in Table.

Sampler->Samplers tell JMeter to send requests to a server and wait for a response.
Config->Configuration elements can be used to set up defaults and variables for later use by samplers.
Listeners->A listener is a component that shows the results of the samples.
6. Copy the Jmeter Script in the WebDriver Sampler as shown below:

7. Execute the Jmeter Script and verify the Results in the View Results Table Listener for the Sample Time captured for executing the Selenium Script.

Jmeter Sampler Time in (ms)

Response Time in (ms)

QTP Basic Quiz & Interview Questions for Beginners

Cick this Subscription Link to keep in touch with us!!

QTP Quiz to test your knowledge.

1. Select the ADO( Microsoft ActiveX Data Objects) Objects used in QTP?

 
 
 
 

2. Which Scripting language used in QTP/UFT?

 
 
 
 

3. What Object is used to send information to test results at the completion of test run?

 
 
 
 

4. What is the method used to send a run-time Data Sheet to an Excel File?

 
 
 
 

5. Where can the results of Output Parameter available in QTP?

 
 
 
 

6. What are the available step commands in QTP??

 
 
 
 

7. Where can we merge the Object Repository?

 
 
 
 

8. What is the in-built method used in QTP to retrieve the number of items in the List for a WebList Object?

 
 
 
 

9. What is low-level recording mode useful?

 
 
 
 

10. How to handle exceptions in QTP?

 
 
 
 

Question 1 of 10

Xpath Axes Locators in Selenium WebDriver- Dynamic HTML Table


Refer to the below Links for Practise
Complete JAVA QUIZ
Selenium Advanced Quiz
50 Real Time Interview Questions
Selenium Quiz
REST API QUIZ

Dynamic Content:

In Web Applications the data in the HTML Table is dynamic always.
To Fetch the data available in the Dynamic Table or to identify the
Dynamic Web Elements available in the Web Page we should depend on Xpath Axes Locators.

Following are the Xpath Axes Locators:
Link for XPATH AXES-> https://www.w3schools.com/xml/xpath_axes.asp

ancestor – select parent or grand parent
following-sibling– Which follows
preceding-sibling – Which precedes
descendant – Child/subChild
parent – Select Immediate PArent
child – Select immeidate Child
following – Select all the matching nodes which are following
preceding – Select all the matching nodes which are preceding

Real Time Example:

1. Access the Web Application URL -> https://money.rediff.com/gainers/bse/daily/groupa?src=gain_lose
2. Find the Stock Name ->‘Adani Enterprises Lt’.
3. Get the Price associated with the Stock Name.

Identify the following Xpath in Firepath for understanding:
Xpath Axes Locators
Xpath Example 1:
Identify the Parent of the WebElement
//a[contains(text(),'Adani Enterprises')]/parent::td


Xpath Example 2:
Identify the Ancestor of the Web Element
//a[contains(text(),'Adani Enterprises')]/parent::td


Xpath Example 3:
Identify the following Elements of the Web Element
In the Case of following all the Elements which are matching will be selected. Now the matching nodes are 501.
//a[contains(text(),'Adani Enterprises')]/parent::td/following::td


Xpath Example 4:
Identify the following siblings of the Web Element
In the Case of following-sibling all the Elements which are matching but should be part of the parent tag ‘tr’. Now the matching nodes are 4.
//a[contains(text(),'Adani Enterprises')]/parent::td/following-sibling::td


Fetching the Price associated with the Stock:
//a[contains(text(),'Adani Enterprises')]/parent::td/following-sibling::td[2]


Selenium Program:

REST API Quiz

      No Comments on REST API Quiz
Refer to the below Links for Practise
Complete JAVA QUIZ
Selenium Advanced Quiz
50 Real Time Interview Questions
Selenium Quiz
Please go to REST API Quiz to view the test
Refer to the below Links for Practise
REST API BASICS -> REST API BASICS
REST API Real Time Example for Beginners
Facebook & Google API Examples

Error using sendKeys() with Selenium WebDriver due to java.lang.CharSequence cannot be resolved

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

Fixing java.lang.CharSequence

In Eclipse whenever we create a project automatically it will pick the latest jre installed in your system jre 1.8.0_25 which is in my case as shown below:
Java Version From Command Line
But in selenium webdriver when we use ‘sendkeys()’ method throws error java.lang.CharSequence cannot be resolved.

We can resolve this in two ways
1. Setting the Source level project should be greater then 1.5.
2. Roll back the jre 8 to jre 7 in Eclipse.

Steps for Setting the Source level of the Project to greater then 1.5

1. Select Project right click->Build Path->Configure Build Path.

2. Select the Java Compiler option as shown below:

3. Select check-box for ‘Enable project specific settings”. Change the value from the compliance level drop down from 1.4 to 1.7. Click on ‘Ok’ button.

4. Verify the program now the issue will be resolved
Steps for roll-backing from jre 8 to jre 7
1. Select Project right click->Build Path->Configure Build Path.

2. Navigate to Libraries. Select the jre 1.8 and click on remove.Do not worry we are not removing the jre 1.8 from the system, we are removing the jre 1.8 reference from this project.

3. Click on Add Library Button->JRE System Library->Next.

4. Select Alternate JRE radio button. Click on ‘Installed JREs’ button.

5. In the installed JREs click on Add and Navigate to the directory where the jre7 is installed.

6. Select the JRE Type as ‘Standard VM’ and click on Next.

7. In my case JRE7 is installed in the following location.
C:\Program Files (x86)\Java\jre7
Provide JRE Name -> jre7.0
Click on Finish button.

8. Select jre7.0 checkbox in the list of Installed JRE’s. Click on Ok button.

9. Select the workspace default jre as JRE 7.0. Click on Finish button.

10. Verify the Java Build Path.

11. Verify the program now the issue will be resolved.

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

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.

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: