Data Driven Testing and Batch Testing

Data Driven Testing and Batch Testing using Selenium

i) Data Driven Testing
ii) Batch Testing
--------------------------------------------
i) Data Driven Testing

1) What is Data Driven Testing?

Testing the Same Functionality with multiple inputs

2) Why Data driven Testing?

For Positive and Negative Testing

3) How to conduct Data Driven Testing

By Reading Test Data from external files (Text File/Excel File...)
-----------------------------------------------------------
Example:

Data Driven Testing for Login Functionality by Reading Test Data from a Text File.

Test Case: Verify Login Functionality in gcrShop Admin Interface

Test Steps:
i) Launch the Browser
ii) Navigate to "http://gcrit.com/build3/admin/"
iii) Enter Username
iv) Password
v) Click "Login" Button
-----------------------
Input Data/Test Data

Refer: input.txt

Verification Points:

1) Capture the URL after Login and Compare with Expected:
Expected: http://www.gcrit.com/build3/admin/index.php

2) Capture the Error Message and Compare with Expected
Expected: Error: Invalid administrator login attempt.
-------------------------------------------------------------
Write Selenium WebDiver Test Case

public class DataDrivenTesting {
public static WebDriver driver;
public static String Error_Messge;
public static void main(String[] args) throws InterruptedException, IOException {
FileReader file = new FileReader("C:/Users/gcreddy/Desktop/Input.txt");
BufferedReader br = new BufferedReader(file);
int Count =0;
int Iteration =0;
String line;
while ((line = br.readLine()) != null){
Count = Count+1;

if (Count > 1){
Iteration = Iteration+1;
String [] inputData = line.split(", ", 2);
driver = new FirefoxDriver();
driver.get("http://gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys(inputData[0]);
driver.findElement(By.name("password")).sendKeys(inputData[1]);
driver.findElement(By.id("tdb1")).click();
Thread.sleep(3000);
String url = driver.getCurrentUrl();
//System.out.println(url);
if (! url.contains("http://www.gcrit.com/build3/admin/index.php")){
Error_Messge = driver.findElement(By.className("messageStackError")).getText();
}

if (url.contains("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Iteration "+Iteration + " -Admin Login Successful -Passed");
}
else if ((! url.contains("http://www.gcrit.com/build3/admin/index.php")) && (Error_Messge.contains("Error: Invalid administrator login attempt."))){
System.out.println("Iteration "+Iteration + " -Admin Login Unsuccessful and Showing Correct Error Message - Passed");
}
else {
System.out.println("Iteration "+Iteration + " -Admin Login Unsuccessful and Not Showing Correct Error message - Failed");
}
driver.close();
}
}
}
}
--------------------------------------------------------------
Assignment:

Verify the maximum Login attempts (Invalid input) for Admin Login Functionality
---------------------------------------------------------------
ii) Batch Testing

Executing Series of Tests

AUT (Application Under Test)
gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)

Test Cases:
1) Verify Admin Login Functionality
2) Verify "Manufacturers" Link Existence in the index page of the application (After login to Application)
3) Verify Redirect Functionality between Admin and User Interface (After Login to Admin Interface)
---------------------------------------------------
1) Verify Admin Login Functionality

i) Launch the Browser
ii) Navigate to "http://gcrit.com/build3/admin/"
iii) Enter Username
iv) Password
v) Click "Login" Button
-----------------------
Input Data/Test Data
Username: admin
password: admin@123

Verification Point:
Capture the URL after Login and Compare with Expected:
Expected: http://www.gcrit.com/build3/admin/index.php
-----------------------------------------------------------------
2) Verify "Manufacturers" Link Existence in the index page of the application (After login to Application)

i) Launch the Browser
ii) Navigate to "http://gcrit.com/build3/admin/"
iii) Enter Username
iv) Password
v) Click "Login" Button
-----------------------
Input Data/Test Data
Username: admin
Password: admin@123

Verification Point:
Check the existence of "Manufacturers" Link, if exists then pass otherwise fail

Exception Handling:
Insert "NoSuchElementException"
-------------------------------------------------------------
3) Verify Redirect Functionality between Admin and User Interfaces (After Login to Admin Interface)

i) Launch the Browser
ii) Navigate to "http://gcrit.com/build3/admin/"
iii) Enter Username
iv) Password
v) Click "Login" Button
vi) Click "Online Catalog" Link
-------------------------------------
Input Data/Test Data
Username: admin
Password: admin@123

Verification Point:
Capture the URL after Redirecting and Compare with Expected:
Expected: http://www.gcrit.com/build3/
--------------------------------------------------------
Create Reusable Components:

i) Launch Browser
ii) Login to Admin Interface 
iii) Close Browser
-------------------------------------------------------
Create Selenium Test Batch

public class BatchTesting {
public static WebDriver driver;
//Launch Browser
public void launchBrowser(){
driver = new FirefoxDriver();
}
//Close Browser
public void closeBrowser(){
driver.close();
}
public void adminLogin(String Username, String Password){
driver.get("http://www.gcrit.com/build3/admin");
driver.findElement(By.name("username")).sendKeys(Username);
driver.findElement(By.name("password")).sendKeys(Password);
driver.findElement(By.id("tdb1")).click();
}
public static void main(String[] args) throws InterruptedException {
//Create Object
BatchTesting obj = new BatchTesting();

//Test Case 1: Verify Admin Login Functionality
obj.launchBrowser();
obj.adminLogin("admin", "admin@123");

String url = driver.getCurrentUrl();

if (url.contains("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Test Case 1: Admin Login Successful - Passed");
}
else {
System.out.println("Test Case 1: Admin Login Unsuccessful - Failed");
}
obj.closeBrowser();
//-------------------------------------------------------
//Test Case 2: Verify "Manufacturers" Link Existence in the index page 
obj.launchBrowser();
obj.adminLogin("admin", "admin@123");
try
{
boolean linkExistence = driver.findElement(By.linkText("Manufacturers")).isDisplayed();

if (linkExistence == true){
System.out.println("Test Case 2: Manufacturers Link Exists - Passed");
}
}
catch (NoSuchElementException e) {
System.out.println("Test Case 2: Manufacturers Link Not Exists - Failed");
}
obj.closeBrowser();
//------------------------------------------------
//Test Case 3:Verify Redirect Functionality between Admin and User Interfaces
obj.launchBrowser();
obj.adminLogin("admin", "admin@123");
driver.findElement(By.linkText("Online Catalog")).click();
Thread.sleep(3000);
String url2 = driver.getCurrentUrl();

if (url2.equals("http://www.gcrit.com/build3/")){
System.out.println("Test Case 3: Redirected from Admin to User Interface - Passed");
}
else {
System.out.println("Test Case 3: Not Redirected from Admin to User Interface - Failed");
}
obj.closeBrowser();
//------------------------------------------------------
}
}
-----------------------------------------------------------
Test Case: Verify Communication between two different Browsers

Steps:
i) Create Mozilla Firefox Browser and Google Chrome Browser
ii) Launch the Two different applications
iii) Interact from one application to another
iv) Close browsers
--------------------------------------------------
WebDriver Firefoxdriver = new FirefoxDriver();

System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver ChromeDriver = new ChromeDriver();

Firefoxdriver.get("https://www.gmail.com");
String Text = Firefoxdriver.findElement(By.tagName("h1")).getText();

ChromeDriver.get("http://www.gcrit.com/build3/create_account.php?osCsid=38s238i67jk84tno82uhfd7mk2");
ChromeDriver.findElement(By.name("firstname")).sendKeys(Text);

Firefoxdriver.close();
ChromeDriver.close();
-------------------------------------------------------------

1 comments:

Thank you very much, Sir. Its very simple, easy to understand lecture. Gratefully appreciated.

Post a Comment