Batch Testing and Data Driven Testing in Selenium

Batch Testing, Data Driven Testing in Selenium

Batch Testing, Data Driven Testing within Batch Testing

Batch Testing: Executing series of Tests.

Data Driven Testing: Executing the Same functionality with multiple sets of Test Data.

Batch Testing in Selenium:

i) Batch Testing using Testing Framework (JUnit/TestNG) Annotations
ii) Batch Testing without using Testing Framework Annotations (using programming features)
-----------------------------------------------------
AUT (Application Under Test)
gcrShop Web Portal ("www.gcrit.com/build3/admin/")

Test Cases:
1) Verify Admin Login Functionality

2) Verify "Manufacturers" Link (Element) existence in index page of the Application(after Login to Application)

3) Verify Redirect Functionality between Admin and User Interfaces.

4) Data Driven Testing for Admin Login Functionality
-----------------------------------------------------
1) Verify Admin Login Functionality
Test Steps:

i) Launch the Browser
ii) Navigate to Admin Interface ("http://www.gcrit.com/build3/admin/")
iii) Enter Username
iv) Enter Password
v) Click "Login" Button

Input Data:
Username = admin
Password = admin@123

Verification Point
Capture the Current URL and Compare with Expected

Expected URL: "http://www.gcrit.com/build3/admin/index.php"

Inspect Element:

Username -Edit box - name - username
Password - edit box - name - password
Login - Button - id - tdb1
-----------------------------------------------------
2) Verify "Manufacturers" Link (Element) existence in index page of the Application (after Login to Application)
Pre-Condition: Login to Application

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.

Pre-Condition: Login to Application

Click "Online Catalog" Link in Index page.

Verification Point
Capture the Current URL and Compare with expected

Expected URL:
http://www.gcrit.com/build3/
------------------------------------------------------
4) Data Driven Testing for Admin Login Functionality

Test Steps:

i) Launch the Browser
ii) Navigate to Admin Interface ("http://www.gcrit.com/build3/admin/")
iii) Enter Username
iv) Enter Password
v) Click "Login" Button

Input Data:
Source File / Test Data file: input.txt

Verification Point
Capture the Current URL and Compare with Expected

Expected URL: "http://www.gcrit.com/build3/admin/index.php"

Inspect Element:

Username -Edit box - name - username
Password - edit box - name - password
Login - Button - id - tdb1
-----------------------------------------------------
Create Reusable Components (User defined Methods)

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

public class Class1 {
public static WebDriver driver;   
public static String line;
//Launch Browser
public void launchBrowser(){
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
driver = new ChromeDriver();   
}
//Close Browser
public void closeBrowser(){
driver.close();   
}
//Adming Login
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, IOException {
//Create Object
Class1 obj = new Class1();

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

if (Url.equals("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 (Element) Existence in index page of the Application(after Login to Application)
obj.launchBrowser();
obj.adminLogin("admin", "admin@123");
Thread.sleep(3000);
try
{
if (driver.findElement(By.linkText("Manufacturers")).isDisplayed()){
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");
Thread.sleep(3000);
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: -Redirecting from Admin to User Interface - Passed");
}
else
{
System.out.println("Test Case 3: -Not Redirecting from Admin to User Interface - Failed");
}
obj.closeBrowser();
//-----------------------------------------
//Test Case 4: Data Driven Testing for Admin Login Functionality
FileReader file = new FileReader("C:\\Users\\gcreddy\\Desktop\\input.txt");   
BufferedReader br = new BufferedReader(file);

int Count = 0;
while ((line = br.readLine()) != null) {
Count = Count+1;
if (Count > 1){
obj.launchBrowser();
String [] inputData = line.split(", ", 2);
obj.adminLogin(inputData[0], inputData[1]);
Thread.sleep(4000);
String url3 = driver.getCurrentUrl();

if (url3.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Test Case 4: Iteration -" + (Count-1) + " - Admin Login Successful Passed");   
}
else {
System.out.println("Test Case 4: Iteration -" + (Count-1) + " - Admin Login Unsuccessful Failed");   
}
obj.closeBrowser();   
}
}
}
}
----------------------------------------------------

0 comments:

Post a Comment