33 – Writing Selenium Test Cases Part-4

Selenium Class 33 – Writing Selenium Test Cases Part-4

Writing Test Cases:
1) Verify Internal and External Links in a web site
2) Verify element existence…..
3) Verify Customer Registration….
4) Verify Customer Login….
5) Verify User Registration in a Forum
6) Verify “Redirect” Functionality from Admin Interface to User Interface

Test Case 7: Data Driven Testing for Admin Login in gcrShop Admin Interface by reading test data from a text file.

Steps:

i) Create Test Script
ii) Create / Prepare/Collect Test Data
iii) Connect Test Data with the Test Script
iv) Run the Test Script

Selenium WebDriver Test Case:

public class AdminLogin {
public static WebDriver driver;

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

FileReader file = new FileReader(“C:/Users/admin/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 [] Farjana=line.split(“, “, 2);
driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get(“http://www.gcrit.com/build3/admin/”);

driver.findElement(By.name(“username”)).sendKeys(Farjana[0]);
driver.findElement(By.name(“password”)).sendKeys(Farjana[1]);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(3000);

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

}
}
br.close();
file.close();
}
}

Test Case 8: Verify Admin Login, Error Message in gcrshop Admin Interface

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

Verification Point/s:
i) Capture the url after Login to application then compare with expected
ii) Verify the error message and compare with expected

Expected Result:
i) http://www.gcrit.com/build3/admin/index.php
ii) “Error: Invalid administrator login attempt.”

Input Data/Test Data:

i) Test data for Positive Scenario:
a) Username: admin
b) Password: admin@123

ii) Test data for Negative Scenario 1:
a) Username: admin1
b) Password: admin@123

iii) Test data for Negative Scenario 2:
a) Username: admin
b) Password: admin@1234

iv) Test data for Negative Scenario 3:
a) Username: admin1
b) Password: admin@1234

v) Test data for Negative Scenario 4:
a) Username: Blank
b) Password: Valid/Invalid

vi) Test data for Negative Scenario 5:
a) Username: valid/Invalid
b) Password: Blank

vii) Test data for Negative Scenario 6:
a) Username: Blank
b) Password: Blank

Selenium WebDriver Test Case:

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(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@1234”);
driver.findElement(By.id(“tdb1”)).click();

String url=driver.getCurrentUrl();

if (!url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
ErrorMessage =driver.findElement(By.className(“messageStackError”)).getText();
//System.out.println(ErrorMessage);
}

if (url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
System.out.println(“Admin Login Successful – Passed”);
}
else if (ErrorMessage.contains(“Error: Invalid administrator login attempt.”)){
System.out.println(“Admin Login is Unsuccessful, but showing correct error message – Passed”);
}
else
{
System.out.println(“Admin Login Unsuccessful – not showing correct error message -Failed”);
}
driver.close();

Selenium Video
Selenium WebDriver Tutorial for Beginners

Test Case 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:
Incomplete
……………………………………………..