Automating a Manual Test Case


Automating a Manual Test Case...

1) Create a Manual Test Case
2) Automate the Manual Test Case using Selenium
3) Exception Handling for Selenium Test Case
------------------------------
1) Create a Manual Test Case

I am taking a Manual Test Case, that is Generic Test Case, 
"Verify Gmail Link existence in Google Home Page"

Sample Test Case Template (Manual Test Case):

i) Test Case Id: 
ii) Test Case Title: 
iii) Precondition: 
iv) Test Steps: 
v) Test Data: 
vi) Expected Result: 
vii) Post-condition: 
viii) Actual Results: 
ix) Status: 
x) Comments: 
------------------------------
Test Case Document...

i) Test Case Id: TC_001
ii) Test Case Title: Verify "Gmail" Link existence in Google Home page
iii) Precondition: NA
iv) Test Case Step/s: 
                     i) Launch the Browser and Navigate to www.google.com             
v) Test Data: NA
vi) Expected Result: Gmail Link will be available in Google Home Page
vii) Post-Condition: Google Home Page with Gmail Link, and Other Links...
viii) Actual Results: (* During Test Case Execution)
ix) Status: (* After Test Case Execution)
x) Comments: 
---------------------------------------------
Note: We can select existing Manual Test Cases for Automation, or we can directly write automated Test Cases using Test Scenarios.

we can start the Test Automation process at beginning of the Project or middle of the Project (only for Regression Testing), or end of the Testing (for Maintenance Testing) based on the Project and the Company.
---------------------------------------------
Writing Software Test Cases
2) Automating the Manual Test Case using Selenium WebDriver

> Using Element Locators and WebDriver methods we create Test Steps, and use Java programming Statements to enhance the Test case.

Steps:

i) First Create Instantiate Browser Driver (Mozilla Firefox or chrome or IE etc..)

ii) Create the Browser driver

iii) Generate the Test Steps using Element Locators and WebDriver Commands.

iv) Enhance the Test Case using Java programming Statements.

Selenium Test Case / Test Script

package abcde;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Class1 {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
boolean LinkStatus =driver.findElement(By.linkText("Gmail")).isDisplayed();

if (LinkStatus=true){
System.out.println("Gmail Link is Exists in Google Homepage - Passed");
}
else
{
System.out.println("Gmail Link is Not Exits in Google Homepage -Failed");
}
driver.close();
}
}
---------------------------------------------
Note: Whenever we check an Element existence in web pages, if the Element is exists then It will show "Pass", if the Element is not exists then it will show Error / NoSuchelement exception instead of showing "Fail" status, then we need to provide "NoSuchElement" exception then we can get current result (If the Element is exists or not). 
---------------------------------------------
Selenium Test Case with Exception Handling

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");

try
{
boolean LinkStatus =driver.findElement(By.linkText("Gmail")).isDisplayed();

if (LinkStatus=true){
System.out.println("Gmail Link is Exists in Google Homepage - Passed");
}
}
catch (NoSuchElementException e){
System.out.println("Gmail Link is Not Exists in Google Homepage -Failed");
}
driver.close();
}
-------------------------------------------------------------------------------------------------
Note: Exception Handling is mandatory for some Selenium Test Cases only, not for all Selenium Test Cases.

4 comments:

Post a Comment