34 – Writing Selenium Test Cases Part-5

Selenium Class 34 – Writing Selenium Test Cases Part-5

Writing Test Cases:
1) Verify Internal and External Links in a web site
2) Verify element existence…..
3) Verify Customer Resigitration….
4) Verify Customer Login….
5) Verify User Registration in a Forum
6) Verify “Redirect” Functionality from Admin Interface to User Interface
7) Data Driven Testing for Admin Login in gcrShop Admin Interface by reading test data from a text file.
8) Verify Admin Login, Error Message in gcrshop Admin Interface

9) Write a Test Case for Admin Login Locking Functionality

Verify maximum invalid attempts for Admin Login

  • It has to lock Admin Functionality for 5 minutes after 3 failed attempts

Test Steps:
i) Launch the Browser
ii) Navigate to “http://www.gcrit.com/build3/admin/”
iii) Enter Invalid Username
iv) Enter Invalid Password
v) Click “Login” Button

Verification Point/s:
Capture the Error message and compare with expected for 4 times

Test Data:
Ref: input.txt

Selenium WebDriver Test Case:

public class Class2 {
public static WebDriver driver;
static String ErrorMessage;

public static void main(String[] args) throws IOException, InterruptedException {
System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);

FileReader file=new FileReader(“C:\Users\gcreddy\Desktop\input.txt”);
BufferedReader br=new BufferedReader(file);

int Iteration=0;
String line;

while ((line=br.readLine()) != null){
Iteration=Iteration+1;

if (Iteration > 0){
String [] inputData=line.split(“, “, 2);

WebDriver driver= new ChromeDriver();
driver.get(“http://www.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(2000);

ErrorMessage=driver.findElement(By.className(“messageStackError”)).getText();
//System.out.println(ErrorMessage);

if ((Iteration == 4) && ErrorMessage.contains(“Error: The maximum number of login attempts has been reached. Please try again in 5 minutes.”)){
System.out.println(Iteration + ” Maximum invalid Login Attempts are over – Passed”);
}
else {
System.out.println(Iteration + ” Maximum invalid Login Attempts are Not over -Done”);
}
driver.close();
}
}
br.close();
file.close();
}
}

10) Batch Testing

Write Selenium WebDriver Test Cases using User defined Methods/Reusable Components)

Test Case 1: Verify Admin Login (Positive Test Case)
Test Case 2: Verify Error Message in Admin Login Functionality (Negative Test Case)
Test Case 3: Verify Redirect Functionality from Admin Interface to user Interface

Steps:
1) Select Test Cases…
2) Identify the common Functionality among Test Cases
3) Create Reusable Components / User defined Methods for common Functionality
4) Create Test Cases using Reusable Components / User defined Methods

Reusable Components:
1) Lunch Browser
2) Admin Login
3) Close Browser…

Selenium WebDriver Test Batch:

public class BatchTesting {
public static WebDriver driver;

//Launch Browser
public void launch(){
driver = new ChromeDriver();
driver.manage().window().maximize();
}
//Close Browser
public void closeBrowser(){
driver.close();
}
//Admin Login
public void login(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) {
System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
BatchTesting obj=new BatchTesting();
//Test Case 1: Verify Admin Login (Positive Test Case)
obj.launch();
obj.login(“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 is Successful – Passed”);
}
else{
System.out.println(“Test Case 1: “+ “Admin Login is unsuccessful – Failed”);
}
obj.closeBrowser();
//Verify Error Message in Admin Login Functionality (Negative Test Case)
obj.launch();
obj.login(“admin1”, “abcder”);

String ErrorMessage=driver.findElement(By.className(“messageStackError”)).getText();
//System.out.println(ErrorMessage);
if (ErrorMessage.contains(“Error: Invalid administrator login attempt.”)){
System.out.println(“Test Case 2: “+ “Admin Login is Unsuccessful & Showing Correct Error Message -Passed”);
}
else {
System.out.println(“Test Case 2: “+ “Admin Login is Unsuccessful & Not Showing Correct Error Message -Failed”);
}
obj.closeBrowser();
//Test Case 3: Verify Redirect Functionality from Admin Interface to user Interface
obj.launch();
obj.login(“admin”, “admin@123”);
driver.findElement(By.linkText(“Online Catalog”)).click();
String url2=driver.getCurrentUrl();

if (url2.equals(“http://www.gcrit.com/build3/”)){
System.out.println(“Test Case 3: “+ “Redirected from Admin Interface to User Interface – Passed”);
}
else {
System.out.println(“Test Case 3: “+ “Not Redirected from Admin Interface to User Interface – Passed”);
}
obj.closeBrowser();
}
}

Selenium Video
Selenium WebDriver Tutorial for Beginners

11) Write a Test Case for Positive and Negative Testing for Admin Login Functionality

Test Steps:
i) Launch the Browser
ii) Navigate to “http://www.gcrit.com/build3/admin/”
iii) Enter “Username”
iv) Enter “Password”
v) Click “Login” Button

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

Expected Test Result:
1st Iteration: Login will Pass
2nd Iteration: Login will Fail

Input for Positive Testing
i) Username: admin
ii) Password: admin@123

Input for Negative Testing
i) Username: abcdef
ii) Password: xyz123

Selenium WebDriver Test Case:

public class AdminLogin {
static String Username;
static String Password;
static int Iteration=0;
public static void main(String[] args) {
for (int i=1; i<=2; i++){
Iteration=Iteration+1;
if (i==1){
Username=”admin”;
Password=”admin@123″;
}
else if(i ==2){
Username=”admin1″;
Password=”abcdefg”;
}
System.setProperty(“webdriver.chrome.driver”, “E:/chromedriver.exe”);
WebDriver driver= new ChromeDriver();
driver.manage().window().maximize();

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();

String url=driver.getCurrentUrl();

if (url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(Iteration +” Admin Login is Successful -Passed”);
}
else {
System.out.println(Iteration +” Admin Login is Unsuccessful -Failed”);
}
driver.close();
}
}
}
………………………….