How to use selenium webdriver with jmeter.

Prerequisite
1. Download Apache JMeter from http://jmeter.apache.org/download_jmeter.cgi and UnZip
2. Download WebDriver plugins for JMeter from http://jmeter-plugins.org/downloads/all/#Latest-Stable-Release and UnZip
3. Download Mozilla Firefox 26 from http://mozilla_firefox.en.downloadastro.com/old_versions/ and install

How to install Selenium Webdriver in Jmeter
1. Copy the jar files from 'lib' folder of JMeterPlugins-WebDriver and paste to Jmeter_Home/lib folder.
2. Copy the files from ext folder and paste to Jmeter_Home/lib/ext folder.
3. Delete older / Duplicate http jars from Jmeter_Home/lib
Example:
    httpclient-4.2.6.jar (delect this jar)
    httpclient-4.5.jar
    httpcore-4.2.5.jar (delect this jar)
    httpcore-4.4.1.jar
    httpmime-4.2.6.jar (delect this jar)
    httpmime-4.5.jar

4. Now the Installation is Completed.

How to configure and run Jmeter
1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.bat to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group
Number of Threads (users): 1
Ramp-Up Period (in seconds):  1
Loop Count: 1
3. Add 'jp@gc - Firefox Driver Config' under 'Thread Group'
Right-click on the Thread Group > Add > Config Element > jp@gc - Firefox Driver Config

4. Add 'jp@gc - WebDriver Sampler' Sampler under 'Thread Group' 
Right-click on the Thread Group > Add > Sampler > jp@gc - WebDriver Sampler

WDS.sampleResult.sampleStart()
WDS.browser.get('http://www.google.com')
WDS.sampleResult.sampleEnd()



5. Add 'View Results in Table' and View Results Tree Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > View Results in Table

6. Finally Save Test plan then Press Menu > Run > Start or 'Ctrl'+ 'R' to run Test plan
  Open Firefox browser then navigate to 'http://www.google.com'



N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

How to perform load or performance test on FTP Server using Jmeter.

             How to make FTP server in local computer
1. Download and Install GOLDEN FTP Server Software
2. Run 'Golden FTP Server'
3. Select 'Open shares' then Click on 'Add' button

4. Enter your desired Path and Name, Enable full control then click on 'Ok' button.
5. Finally will show the access path to the file

You can connect to this file from another system of your network (if only firewall is disabled) through command prompt (ftp 10.6.0.38).Once it is connected you can check the connections to your server.

N.B: Off FTP Firewall

Configure FTP Server in Jmeter 
1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.sh to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group
Number of Threads (users): 1
Ramp-Up Period (in seconds):  1
Loop Count: 1
3. Add 'FTP Request Defaults' under 'Thread Group'
Right-click on the Thread Group > Add > Config Element > FTP Request Defaults

Server Name or IP - 10.6.0.38
4. Add 'FTP Request' Sampler under 'Thread Group' to fetch file.
Right-click on the Thread Group > Add > Sampler > FTP Request
Remote File - /Uploaddownload/importanturl.txt
Local File - importanturl.txt
Select get(RETR)
Username - anonymous
Password - anonymous

5. Add 'FTP Request' Sampler under 'Thread Group' to upload file.
Right-click on the Thread Group > Add > Sampler > FTP Request

Remote File - /Uploaddownload/examplefile.txt
Local File - D:\ftpjmeter\examplefile.txt
Select .Select put (STOR)
Username - anonymous
Password - anonymous
6. Add 'View Results Tree' and 'Summary Report' Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > Summary Report
View Results Tree:
You can see how many request successfully serve, how many request fail to serve and it reason.
Summary Report:
    Sample - number of requests sent
    Avg - an Arithmetic mean for all responses (sum of all times / count)
    Minimal response time (ms)
    Maximum response time (ms)
    Error rate - percentage of failed tests
    Throughput - how many requests per second does your server handle. Larger is better.
    KB/Sec - self expalanatory
    Avg. Bytes - average response size
   
7. Finally Save Test plan then Press Menu > Run > Start or 'Ctrl'+ 'R' to run Test plan


N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

How to perform load or performance test on wsdl web services using Jmeter.

Downlaod and install soapui and here is wsdl url: http://www.webservicex.com/CurrencyConvertor.asmx?wsdl

1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.sh to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group

Number of Threads (users): The number of users that JMeter will attempt to simulate. Set the 'Number of Threads (users)' field to 10
Ramp-Up Period (in seconds): start the total number of threads. Set the 'Ramp-Up Period' field to 1
Loop Count: The number of times to execute the test. Set the 'Loop Count' field to 1.

3. Add 'SOAP/XML-RPC Request' Sampler  under 'Thread Group'
Right-click on the Thread Group > Add > Sampler > SOAP/XML-RPC Request

4. Open soap UI and create new soapui project using wsdl url as I used in below
 
5. After soap ui project created successfully. Copy soap request data as I copy below soap request.

6. Past copied soap request code into created Jmeter SOAP/XML-RPC Request” sampler in  Soap/XML-RPC data as below:

7. Add 'View Results Tree' and 'Summary Report' Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > Summary Report

View Results Tree:
You can see how many request successfully serve, how many request fail to serve and it reason.
Summary Report:
    Sample - number of requests sent
    Avg - an Arithmetic mean for all responses (sum of all times / count)
    Minimal response time (ms)
    Maximum response time (ms)
    Error rate - percentage of failed tests
    Throughput - how many requests per second does your server handle. Larger is better.
    KB/Sec - self expalanatory
    Avg. Bytes - average response size
   
8. Finally Save Test plan then Press 'Ctrl'+ 'R' to run Test plan

N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

How to perform load or performance test on REST API using Jmeter.

1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.sh to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group

Number of Threads (users): The number of users that JMeter will attempt to simulate. Set the 'Number of Threads (users)' field to 10
Ramp-Up Period (in seconds): start the total number of threads. Set the 'Ramp-Up Period' field to 1
Loop Count: The number of times to execute the test. Set the 'Loop Count' field to 1.

3. Add 'HTTP request' Sampler under 'Thread Group'
Right-click on the Thread Group > Add > Sampler > HTTP request

Method - Depending on the type of method, the API was build over, select Get, Put, Post, Delete etc (in our demo we will be working on Post method)
Path: Enter your desired request which page do you want to perform load or performance test.
Set the Path field to 'http://localhost:8080/execute?command=CheckEmailAvailability'
N.B: How many Sampler do you want to add?.
It is depend on how many request do you want to perform load or performance test. For example you want to perform load or performance test for get request and you must have add 5 Sampler.
Parameters/Post Body - Add request input josn in 'Body Data'


 4. Add HTTP Header Manager under 'Sampler'
Right-click on the Sampler > Add > Configure Element > HTTP Header Manager

Click on Add button on HTTP Header Manager and add "Content-Type" under Name and "application/x-www-form-urlencoded" under Value.

5. Add 'View Results Tree' and 'Summary Report' Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > Summary Report

View Results Tree:
You can see how many request successfully serve, how many request fail to serve and it reason.
Summary Report:
    Sample - number of requests sent
    Avg - an Arithmetic mean for all responses (sum of all times / count)
    Minimal response time (ms)
    Maximum response time (ms)
    Error rate - percentage of failed tests
    Throughput - how many requests per second does your server handle. Larger is better.
    KB/Sec - self explanatory
    Avg. Bytes - average response size
   
6. Finally Save Test plan then Press 'Ctrl'+ 'R' to run Test plan



N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

How to perform get request load or performance test on application server using Jmeter.

 1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.sh to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group

Number of Threads (users): The number of users that JMeter will attempt to simulate. Set the 'Number of Threads (users)' field to 50
Ramp-Up Period (in seconds):start the total number of threads. Set the 'Ramp-Up Period' field to 5
Loop Count: The number of times to execute the test. Set the 'Loop Count' field to 5

3. Add Sampler under 'Thread Group'
Right-click on the Thread Group > Add > Sampler > HTTP request

Path: Enter your desired get request which page do you want to perform load or performance test.
Set the Path field to 'http://localhost:8080/AppMetaDataServer/metaservice?operation=get&servicename=mobilemaps&servicekey=isthebest&code=Base_and_version_configured&version=1.0.1&platform=BB'
N.B: How many Sampler do you want to add?.
It is depend on how many get request do you want to perform load or performance test. For example you want to perform load or performance test for get request and you must have add 5 Sampler.

4. Add Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > Summary Report

View Results Tree:
You can see how many request successfully serve, how many request fail to serve and it reason.
Summary Report:
    Sample - number of requests sent
    Avg - an Arithmetic mean for all responses (sum of all times / count)
    Minimal response time (ms)
    Maximum response time (ms)
    Error rate - percentage of failed tests
    Throughput - how many requests per second does your server handle. Larger is better.
    KB/Sec - self explanatory
    Avg. Bytes - average response size
   
5. Finally Save Test plan then Press 'Ctrl'+ 'R' to run Test plan

N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

How to perform load or performance test on Website using Jmeter.

1. Start Jmeter
Click on Jmeter_Home/bin/ApacheJMeter.jar or jmeter.sh to open Jmeter window

2. Add 'Thread Group' under 'Test Plan'
Right-click on the Test Plan > Add > Threads (Users) > Thread Group

Number of Threads (users): The number of users that JMeter will attempt to simulate. Set the 'Number of Threads (users)' field to 100
Ramp-Up Period (in seconds): start the total number of threads. Set the 'Ramp-Up Period' field to 10
Loop Count: The number of times to execute the test. Set the 'Loop Count' field to 1.

3. Add Sampler under 'Thread Group'
Right-click on the Thread Group > Add > Sampler > HTTP request

Path: Enter your desired website page url which page do you want to perform load or performance test. Set the 'Path' field to 'http://www.apache.org/foundation/preFAQ.html'
N.B: How many Sampler do you want to add?.
It is depend on how many page do you want to perform load or performance test. For example you want to perform load or performance test for 5 pages and you must have add 5 Sampler.

4. Add Listener under 'Thread Group'
Right-click on the Thread Group > Add > Listener > View Results Tree
Right-click on the Thread Group > Add > Listener > Summary Report

View Results Tree:
You can see how many request successfully serve, how many request fail to serve and it reason.
Summary Report:
    Sample - number of requests sent
    Avg - an Arithmetic mean for all responses (sum of all times / count)
    Minimal response time (ms)
    Maximum response time (ms)
    Error rate - percentage of failed tests
    Throughput - how many requests per second does your server handle. Larger is better.
    KB/Sec - self explanatory
    Avg. Bytes - average response size
   
5. Finally Save Test plan then Press 'Ctrl'+ 'R' to run Test plan

N.B: You can change all names like as 'Test Plan', 'Thread Group', 'Sampler' and 'Listener' name

How to get all links url and links text on page in Selenium Webdriver using java.


import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Getallllinksurltext {

public static void main(String args[]) throws IOException {
// WebDriver reference but Firefox object
WebDriver driver = new FirefoxDriver();
//Maximize browser window 
driver.manage().window().maximize();
//Navigate to page to get link urls abd texts
driver.navigate().to("http://www.facebook.com");
//Set  timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Store all link tag imagetags array  
List<WebElement> urltags = driver.findElements(By.tagName("a"));
for (WebElement url : urltags) {
// Fiter only valid link
if ((url.getAttribute("href").trim().length() != 0) && (url.getText().trim().length() != 0)) {
//print page link
System.out.println(url.getText().trim() + " --> " + url.getAttribute("href").trim());

 }
}
//close firefox browser    
driver.quit();
    }

}



How to find out broken or invalid images in Selenium Webdriver using java.


More HTTP Status Code
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Findbrokenimages {
    static int statusCode;
public static void main(String args[]) throws IOException {
// WebDriver reference but Firefox object
WebDriver driver = new FirefoxDriver();
//Maximize browser window 
driver.manage().window().maximize();
//Go to page URL which page / url want to find out invalid or broken
driver.get("http://www.google.com");

//Set  timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Store all image tag imagetags array  
List<WebElement> imagetags = driver.findElements(By.tagName("img"));

for (WebElement imtag : imagetags) {
    if (!(imtag.getAttribute("src").trim() == null) && !(imtag.getAttribute("src").equals(""))) {
//Get status code
statusCode = getResponseCode(imtag.getAttribute("src").trim());
// Invalid or Broken image 
if (statusCode == 404) {
    System.out.println("Invalid or Broken image url # " + imtag.getAttribute("src").trim());
}
}
}

//close firefox browser    
driver.quit();
}

 // Return status code
public static int getResponseCode(String urlString) throws MalformedURLException, IOException {
URL u = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("GET");
huc.connect();
return huc.getResponseCode();
    }
}



How to catch NoSuchElement exception in Selenium WebDriver using java?


import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class NoSuchElementexception {

 public static void main(String args[]) {
// WebDriver reference but Firefox object      
WebDriver driver = new FirefoxDriver();
//Maximize browser window       
driver.manage().window().maximize();
//Go to URL      
driver.get("http://www.google.com");
//Set  timeout      
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Catch Exception
try {
    driver.findElement(By.linkText("Gmail1")).click();
} catch (NoSuchElementException e) {
    e.printStackTrace();
}

//close firefox browser  
driver.close();
    }

}