Author: Daz

Software QA Engineer with 3+ years of industrial experience. Worked with Mobile, Banking & Finance, Healthcare, Telco and Search Engine domains. Passion to learn some technical stuffs regarding QA such as Automation, Performance & Security testing etc.

How to Configure Selenium WebDriver

Hola Testers,

Today I’m going to to tell how to configure Selenium WebDriver. Yes, this is the first lesson for Selenium WebDriver. I hope this will be useful for new users. In here, I’m going to use Java as my programming language. I’m going to divide this tutorial for below partitions.

  • Create a project and configure .jar files
  • Configure TestNG
  • Configure Firefox browser
  • Configure Chrome browser
  • Configure Internet Explore browser

Create a project and configure .jar files

To create a project we need programming IDE. Here I’m using eclipse.

  • Open Eclipse
  • Create a new Java Project

Screen Shot 2017-04-11 at 5.25.04 PM

After create a java project we need to download selenium webdriver jars.

  • Go to seleniumhq download page
  • Download and unzip the WebDriver bindings

Screen Shot 2017-04-11 at 4.19.34 PM.png

  • Create a folder called “libs” in java project (right click on the project > New > Folder)

Screen Shot 2017-04-11 at 5.37.45 PM

  • Paste all the .jar files from extracted folder of the downloaded zip file

Screen Shot 2017-04-11 at 5.45.01 PMScreen Shot 2017-04-11 at 5.46.12 PM

Now we have to add those .jar files to build path.

Select all .jar files in “libs” folder > right click > Build Path > Add to Build Path

Screen Shot 2017-04-11 at 5.49.22 PM

  • After that you can see all the .jar files in newly created “Referenced Libraries” library folder

Screen Shot 2017-04-11 at 5.49.37 PM

Configure TestNG

Click on Help menu > Install New Software..

Screen Shot 2017-04-11 at 6.00.43 PM.png

  • Click on Add button, “Add Repository” box will appear.
  • Enter below values as inputs and click “OK”
    • Name: TestNG
    • Location: http://beust.com/eclipse

Screen Shot 2017-04-11 at 6.02.59 PM

  • Accept agreement details and install TestNG. (If it gives warning, click OK)
  • After successful installation system ask to restart eclipse, allow it.

Screen Shot 2017-04-11 at 6.15.04 PM.png

 

Configure Firebox browser

  • Download geckoDriver from seleniumhq download page Third Party Drivers, Bindings and Plugins section and unzip it

Screen Shot 2017-04-11 at 9.19.58 PM

  • Create a folder called “driver” in project and add unzipped file. Don’t copy through eclipse.

Screen Shot 2017-04-11 at 9.40.04 PM.png

  • Create a class
  • Import Firefox browser driver
import org.openqa.selenium.firefox.FirefoxDriver
  • Initialize FirefoxDriver object
System.setProperty("webdriver.gecko.driver", "path of geckodrivergeckodriver"); 
FirefoxDriver fd=new FirefoxDriver();

Sample code

@Test

  public void firefoxTest() {

 System.setProperty("webdriver.gecko.driver", "/Users/deranthika/Documents/eclipse/workspace/TestSelenium/drivers/geckodriver");

FirefoxDriver fd=new FirefoxDriver();

fd.get("http://google.lk");

  }

If you are using windows OS, you need to put location as below

System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");

Screen Shot 2017-04-11 at 8.22.38 PM.png

Screen Shot 2017-04-11 at 9.42.55 PM.png

 

Configure Chrome browser

  • Instead of gecko, you need to download chromeDriver from seleniumhq download page
  • Download the latest stable version for your OS and copy it to drivers folder
  • Import chromeDriver
import org.openqa.selenium.chrome.ChromeDriver;
  • Create new test method
  • Initailize chromeDriver object
System.setProperty("webdriver.chrome.driver", "/Users/deranthika/Documents/eclipse/workspace/TestSelenium/drivers/chromedriver");

ChromeDriver cd=new ChromeDriver();

sample code

@Test

  public void chromeTest() {

 System.setProperty("webdriver.chrome.driver", "/Users/deranthika/Documents/eclipse/workspace/TestSelenium/drivers/chromedriver");

ChromeDriver cd=new ChromeDriver();

cd.get("http://google.lk");

  }

Screen Shot 2017-04-11 at 9.58.12 PMScreen Shot 2017-04-11 at 9.58.25 PM

Configure Internet Explorer browser

  • you need to download InternetExplorerDriver from seleniumhq download page
  • Download the latest stable version and copy it to drivers folder
  • Import InternetExplorerDriver
import org.openqa.selenium.ie.InternetExplorerDriver;
  • Create new test method
  • Initailize InternetExplorerDriver object
System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer.exe");

InternetExplorerDriver id= new InternetExplorerDriver();

sample code

@Test

  public void chromeTest() {

System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer.exe");

InternetExplorerDriver id= new InternetExplorerDriver();

id.get("http://google.lk");

  }

Untitled.png

I’ll add more browsers later 😉

Advertisements

Download Files Using JMeter

Hola Testers,

Let’s talk about how to download a file from API call using JMeter. First you have to create a JMeter project by adding Thread Group, HTTP Requests and etc. Then, add a “Save Responses to a file” Listener to the download HTTP Request

  • Right click on the HTTP Request > Add > Listener > Save Responses to a file

Screen Shot 2017-03-24 at 3.41.52 PM

And Then, you can add further inputs to the save file

Filename prefix: File will download to this location (~ sign mentioned: file will download to the location where jmeter script saves in your machine)

Screen Shot 2017-03-20 at 6.42.11 PM

After run test you can see the downloaded file in the mentioned location.

Screen Shot 2017-03-20 at 6.44.32 PM

Send SOAP Request using JMeter (2)

Hola Testers,

Today I would like to show another method for send SOAP request. In my previous post I showed with “HTTP Request”. Today, I’m going to do the same request using “SOAP/XML-RPC Request”.

1. First, add a Thread Group
2. Then add a “SOAP/XML-RPC Request” by right click on the Thread Group > Add > Sampler > SOAP/XML-RPC Request
Screen Shot 2016-04-24 at 9.09.21 PM.png

3. The SOAP/XML-RPC Request allows you to add following variables,
-URL of the WSDL
-SOAP Action
-And SOAP data
I’ve add request XML, WSDL URL and SOAP Action as below. (It depends with your SOAP request)
Screen Shot 2016-04-24 at 9.10.08 PM.png

4. Then, add a listener, save the project and run it.
You’ll be able to see the response in listener (I added “View Results Tree” listener and I can see the response in “Response data” tab of the listener)
Screen Shot 2016-04-24 at 9.10.36 PM.png

Send SOAP Request Using JMeter

SOAP (Simple Object Access Protocol) is a protocol specification for exchanging structured information the implementation of web services using XML. But how we implement this on jmeter? Yes, there are some solutions. Today I’ll show one simple way to do it.

1. Open JMeter > Add a Thread Group
2. Add a HTTP Request for the Thread Group
Screen Shot 2016-04-17 at 10.04.29 AM.png

3. Fill host, port, method and path according to your WSDL name
For example I’m using http://www.webservicex.net/country.asmx?WSDL file
My variables will be,
Host: webservicex.net
Port:
Method: POST
Path:/country.asmx?WSDL
Screen Shot 2016-04-19 at 10.41.57 AM

4. Select “Body Data” tab of the HTTP Request and add request URL with parameter
Screen Shot 2016-04-19 at 10.42.10 AM

5. Add a HTTP Header Manager to the Thread Group and add needed Header requests
Screen Shot 2016-04-19 at 10.42.24 AM

6. Add a Listener to get the results. I used “View Results Tree”
7. Save and Run the test. You can see response xml on “Response data” tab of the Listener
Screen Shot 2016-04-19 at 10.42.40 AM.png

Write values in CSV using JMeter

Hola Testers,

On my last post we were talking about read values from csv external data source. I thought this time we should talk about write values on csv. Imagine our jmeter script is creating some number of files in our web application, and you need to know the names of those files to use it later. In this kind of scenario, we can use csv writer to keep our files name for future use.

Add a Beanshell PostProcessor for the HTTP request which creating files
Right click on HTTP request > Add > Post Processors > Beanshell Postprocessors
Screen Shot 2016-04-10 at 8.25.09 AM.png
(You may need a regular expression extractor to HTTP Request for extract the file name.)

Write a write script to write the file name on csv
You can write a simple beanshell script to write file’s name on csv. A sample script like below,

generatedDocID = vars.get("DocID");
filepath =vars.get("FilePath");
f = new FileOutputStream(filepath, true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(generatedDocID);
f.close();

Where “DocID” is the variable we used in regular expression extractor and “FilePath” is the variable name for the csv filepath/name. That variable you can initialise in user defined variables. 🙂

Read values from CSV using JMeter

Hola Testers!

What would you do if you have to test dynamic values for a specific test field. For example you have to test login for N number of users. How do you use Jmeter for that? Today I’m going to tell how to deal with that kind of situation.

For above kind of a scenario, you can use an external data source to keep your test data. Jmeter support with CSV files greatly. SO we’ll use a CSV file to demonstrate this. Let’s take a scenario. I’m taking login scenario for alfresco. So, in order to log, you need username and password. That are our test data. Let’s create test data in CSV.

CSV Test Data
In our scenario we need to store username and password in CSV. I already created 4users with admin in alfresco. Now we’ll create a CSV file.
You can create a CSV in two ways
With heading
Without heading

You can use either with heading or without heading. Then save this file as a .csv

Add CSV Configuration file to Jmeter projet
Right click on the Test Plan > Add > Config Element > CSV Data Set Config
Screen Shot 2016-04-04 at 2.01.53 PM.png

Configuration CSV Config Element
Open “CSV Data Set Config”
Filename: CSV doc path with csv filename
If you write csv with heading, this is enough
Screen Shot 2016-04-04 at 2.09.05 PM.png

If you write csv without heading, then you need to add “Variable Names” for the values with separate by comma(,)
Screen Shot 2016-04-04 at 2.10.54 PM.png

Add parameters to the HTTP request
As we set our variables as “username” and “password”, we need to replace the HTTP request’s send parameters like ${username} and ${password}
Screen Shot 2016-04-04 at 2.17.27 PM.png

Now save the project and run again 🙂

 

Delete Files inside a Folder using Jmeter

Hola Testers,

After a long time I’m gonna tell you how to delete files inside of folder using Jmeter. Actually sometimes we need this trick while we are removing created test data.

Step 1:
Open JMeter. Obviously, since we are using JMeter. We need to open it first

Step2:
Add “User defined Variables” element
Right Click on the Test Plan > Add > Config Element > User Defined Variables
Screen Shot 2016-03-22 at 11.29.50 AM.png

Step 3:
Add user defined variable
Click on the “User Defined Variables” element
Click “Add” button
Give the folder path with a variable name.
Screen Shot 2016-03-22 at 11.33.23 AM

Step 4:
Add a Thread Group
Right click on the Test Plan > Add > Threads (Users) > Thread Group
Screen Shot 2016-03-22 at 11.35.10 AM.png

Step 5:
Add a request (I’m adding HTTP Request)
Right click on the Thread Group > Add > Sampler > HTTP Request
Screen Shot 2016-03-22 at 11.38.27 AM.png

Step 6:
Add a Beanshell PreProcessor for the Request
Right click on the HTTP Request > Add > Pre Processors > Beanshell PreProcessor
Screen Shot 2016-03-22 at 11.40.14 AM.png

Step 7:
Write a beanshell script to delete files inside of the folder (I’m deleting all the .csv files inside of “jmeterFolder” on my desktop)
Select Beanshell PreProcessor
Enter below script

import org.apache.commons.io.FileUtils;
List files = FileUtils.listFiles(new File("${folderPath}"), new String[]{"csv"}, true);
for (File file : files) {
file.delete();
}

${folderPath}: variable which you declare on “User Defined Variables”
Screen Shot 2016-03-22 at 11.47.19 AM.png

Step 8:
Save the script and Run.
jmac.jpg