Writing a Selenium Test Case

Writing a Selenium Test Case with Exception Handling Code

Writing a Selenium Test Case, Inspect HTML elements, locate elements in Selenium, perform actions on the elements using Selenium WebDriver methods.

selenium tutorial

Selenium Tutorial for Beginners

Manual Test Case: 

Test Case Name: Verify Admin Login in gcrShop admin interface login page

Test Case ID: GC_Adm_TC001

Test Steps: 

i. Launch Browser
ii. Navigate / launch /load login page of admin interface of the gcrShop application (https://gcreddy.com/project/admin/login.php)
iii. Enter valid “Username”
iv. Enter valid “Password”
v. Click on “Login” Button
vi. Capture the current URL
vii. Close the Browser window

Verification Point
Compare the captured URL with Expected

Input / Test Data:
Username = gcreddy
Password = [email protected]

Expected Result:
https://gcreddy.com/project/admin/index.php

Actual Result: * After Test Case Execution

Test Result: pass/fail (* After Test Case Execution)

Comments: * After Test Case Execution


Selenium WebDriver Test Case:

System.setProperty(“webdriver.chrome.driver”, “C:\\Users\\user\\Downloads\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get(“https://gcreddy.com/project/admin/login.php”);

driver.findElement(By.name(“username”)).sendKeys(“gcreddy”);
driver.findElement(By.name(“password”)).sendKeys(“[email protected]”);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(2000);
String url = driver.getCurrentUrl();

if (url.equals(“https://gcreddy.com/project/admin/index.php”)) {
System.out.println(“Admin Login is Successful – Passed”);
}
else {
System.out.println(“Admin Login is Unsuccessful – Failed”);
}
driver.close();


Selenium WebDriver Test Case using anoter Verification point with Exception handling code:

Check the existence of “Logoff” link after login

System.setProperty(“webdriver.chrome.driver”, “C:\\Users\\user\\Downloads\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get(“https://gcreddy.com/project/admin/login.php”);

driver.findElement(By.name(“username”)).sendKeys(“gcreddy”);
driver.findElement(By.name(“password”)).sendKeys(“[email protected]”);
driver.findElement(By.id(“tdb1”)).click();
Thread.sleep(2000);

try {
boolean linkExists = driver.findElement(By.linkText(“Logoff”)).isDisplayed();

if (linkExists == true) {
System.out.println(“Admin Login is Successful – Passed”);
}
}
catch (NoSuchElementException e1) {
System.out.println(“Admin Login is Unsuccessful – Failed”);
}
driver.close();


Writing Selenium Test Cases

Steps:

1. Verify Readiness of the Selenium Test Environment

2. Select “Manual Test Case” for Automation

3. Inspect HTML elements and get unique locators

4. Write Selenium Test Cases using Element Locators and Selenium WebDriver methods.

5. Enhance Test Cases using Programming (Java) features.

6. Install TestNG plugin for Selenium

7. Integrate Maven with Selenium.


Test Tool: Selenium WebDriver

Editor: Eclipse IDE

Programming Language: Java

Testing Framework: TestNG

Build Automation Tool: Maven

CI Tool: Jenkins

Etc.

G C Reddy

G C Reddy, Working as a Software Testing Trainer in Hyderabad, India.

You may also like...