Writing Selenium WebDriver Test Cases Part -2

Writing Selenium WebDriver Test Cases Part -2

Writing Selenium WebDriver Test Cases

6) Test Case: Check Admin Login Functionality in gcrShop web portal (Positive Test Case)
7) Test Case: Check Error Message/s in Admin Login Functionality(Negative Test Case)
8) Test Case: Check Admin Functionality with valid and invalid inputs(Positive and Negative Testing)

6) Test Case: Check Admin Login Functionality in gcrShop web portal (Positive Test Case)

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)
iii) Enter Valid User name
iv) Enter Valid Password
v) Click “Login” Button
————————-
Verification Point:
Capture the url and compare with expected.

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

Actual:
Test Data:
User name = admin
Password = admin@123
———————————–
Selenium Test Case:

WebDriver driver = new FirefoxDriver();
driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();

String url = driver.getCurrentUrl();

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

7) Test Case: Check Error Message/s in Admin Login Functionality (Negative Test Case)

Test Steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)
iii) Enter Invalid User name and / or Password
iv) Click “Login” Button
—————————-
Verification point:
Capture the Error Message and compare with expected.

Expected: Error: Invalid administrator login attempt.

Test Data:
User Name: admina
Password: admin@123
———————————–
Selenium Test Case:

WebDriver driver = new FirefoxDriver();
driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(“admina”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();

String url = driver.getCurrentUrl();
if (url.contains(“http://www.gcrit.com/build3/admin/login.php”)){
String ErrorMessage = driver.findElement(By.className(“messageStackError”)).getText();

if (ErrorMessage.contains(“Invalid administrator login attempt.”)){
System.out.println(“Handling Invalid Inputs – Passed”);
}
}
else {
System.out.println(“Not Handling Invalid Inputs – Failed”);
}
driver.close();
———————————-
Assignment:

Verify the maximum Login attempts (For invalid inputs only)
Verification: After 3 attempts it blocks the Login Functionality for 5 minutes.

Writing Selenium WebDriver Test Cases

8) Test Case: Check Admin Functionality with valid and invalid inputs (Positive and Negative Testing)

Test steps:
i) Launch the Browser
ii) Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/)
iii) Enter valid “User name”
iv) Enter Valid “Password”
v) Click “Login” Button
—————
* Repeat the navigation with Invalid User Name and / or Password

Verification Points:
i) Capture the url and compare with expected.
Expected: http://www.gcrit.com/build3/admin/index.php

Test Data:
User name = admin
Password = admin@123
————–
ii) Capture the Error message and compare with expected:
Expected =Error: Invalid administrator login attempt.

Test Data:
User name = admina
Password = admin@123a
(Invalid User name and Invalid Password)

Other Negative Scenarios:

1) Valid User name and Invalid Password
2) Invalid user Name and Valid Password
3) Blank User name and Valid Password/Invalid Password
4) Valid / Invalid User name and Blank password
5) Blank User name and Blank password
———————————–
Selenium Test Case:

public class VerifyLogin {
static int i;
static String username, password, iteration;
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();

for (i = 1; i <= 2; i++){
if (i == 1) {
username = “admin”;
password = “admin@123”;
iteration = “Iteration 1:”;
}
else if(i == 2){
username = “admina”;
password = “admin@123a”;
iteration = “Iteration 2:”;
}

driver.get(“http://www.gcrit.com/build3/admin/”);
driver.findElement(By.name(“username”)).sendKeys(username);
driver.findElement(By.name(“password”)).sendKeys(password);
Thread.sleep(3000);
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 + (“Input Data: “) + username + “, “+ password + ” Admin Login

Successful -Passed”);
driver.findElement(By.linkText(“Logoff”)).click();
Thread.sleep(2000);
}
else if (! url.contains(“http://www.gcrit.com/build3/admin/index.php”)){
String ErrorMessage = driver.findElement(By.className(“messageStackError”)).getText();
if (ErrorMessage.contains(“Invalid administrator login attempt.”)){
System.out.println(iteration + (“Input Data: “) + username + “, “+ password + ” Handling Invalid

Inputs -Passed”);
}
else {
System.out.println(iteration + “- Failed”);
}
}
}
driver.close();
}
}

9) Test Case: Check communication between different browsers.

Test Steps:
i) Create Mozilla Firefox driver, Google chrome driver and IE driver.
ii) Launch three different applications
iii) Interact from one application to another
iv) Close all browsers one by one.
———————————–
Selenium Test Case:

WebDriver firefoxDriver = new FirefoxDriver();
firefoxDriver.get(“https://www.google.com”);
firefoxDriver.findElement(By.linkText(“Gmail”)).click();
String text = firefoxDriver.findElement(By.xpath(“html/body/div[1]/div[2]/div[1]/h2”)).getText();

System.setProperty(“webdriver.chrome.driver”, “E:\\chromedriver.exe”);
WebDriver chromeDriver = new ChromeDriver();
chromeDriver.get(“http://www.gcrit.com/build3/create_account.php?

osCsid=1vbg1oj32ole3qrcv4b6mr7m24”);
chromeDriver.findElement(By.name(“firstname”)).sendKeys(text);
Thread.sleep(3000);

System.setProperty(“webdriver.ie.driver”, “E:\\IEDriverServer.exe”);
WebDriver IEDriver = new InternetExplorerDriver();
IEDriver.get(“https://in.mail.yahoo.com/”);

firefoxDriver.close();
chromeDriver.close();
IEDriver.close();
———————————–

(66)

You may also like...

Leave a Reply