Writing Selenium WebDriver Test Cases

Writing Selenium WebDriver Test Cases

Pre-requisites  to practise Selenium Test Cases


i) Test Scenario

ii) Element Locators - To Locate / identify/recognize Elements.

iii) Selenium WebDriver Commands/Methods - To perform Operations on Elements.

iv) Programming Features - To heighten Test cases
------------------
v) JUnit/TestNG Annotations - To grouping Test cases, Batch Testing as well as generate Test Reports.
---------------------------------------------------------------
1) Test Case: Verify Internal as well as External Links inwards Wikipedia.org

Internal Link: It redirects to roughly other page or place inwards the same application.

External Link: It redirects to roughly other page or place inwards other application
-----------
Test Steps:

i) Launch the Browser
ii) Navigate to Selenium page inwards Wikipedia.org
iii) Click "Create Account" Link
iv) Capture Current Url
v) Navigate dorsum to Selenium Page
vi) Click "selenium.org" Link
vii) Capture Current Url
viii) Close Browser
---------------------
Verification Points:
 

i) Check if the First URL is an Internal Link or not?
ii) Check if the instant URL is an External Link or not?
---------------------------------------
Selenium Webdriver Test Case:
WebDriver driver = novel FirefoxDriver();
driver.get("https://en.wikipedia.org/wiki/Selenium_%28software%29");
driver.findElement(By.linkText("Create account")).click();
String url = driver.getCurrentUrl();
//System.out.println(url);
if (url.contains("wikipedia.org")){
System.out.println("It is an Internal Link - Redirected to roughly other page inwards the Same Application - Passed");
}
else{
System.out.println("It is an External Link - Redirected to roughly other page inwards the Other Application -Failed");
}
driver.navigate().back();
driver.findElement(By.partialLinkText("seleniumhq.org")).click();
url = driver.getCurrentUrl();

if (! url.contains("wikipedia.org")){
System.out.println("It is an External Link - Redirected to roughly other page inwards the Other Application - Passed");
}
else{
System.out.println("It is an Internal Link - Redirected to roughly other page inwards the same Application - Failed");
}
driver.close();
}
}
------------------------------------------------------
2) Test Case: Verify Element Existence (Gmail link beingness inwards Google dwelling page)

Test Steps:

i) Launch the browser
ii) Navigate to Google.com (Google Home page)
------------------
Verification point:

 
Check the beingness of Gmail link.

Selenium Test Case:

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.com");
boolean beingness = driver.findElement(By.linkText("Gmail")).isDisplayed();

if (existence == true){
System.out.println("Gmail Link Exists - Passed");
}
else {
System.out.println("Gmail Link Not Exists - Failed");
}
}
}
------------------------------------------
WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.com");

try
{
if (driver.findElement(By.linkText("Gmailabc")).isDisplayed()){
System.out.println("Gmail Link Exists - Passed");
}
}

catch (NoSuchElementException e)
{
System.out.println("Gmail Link Not Exists - Failed");
}
driver.close();
}
}
--------------------------------------------------------------
3) Test Case: Login to Indian Railways Online spider web portal

Test Steps:
 

i) Launch the Browser
ii) Navigate to https://www.irctc.co.in (Indian Railways Online spider web portal)
iii) Enter User Id
iv) Enter Password
v) Enter Captcha (Verification Code)
vi) Click Login Button
-------------------------------
Verification Point:
 

Capture the URL as well as Compare alongside https://www.irctc.co.in/eticketing/home

Test Data:
 

User Id: gcreddy7 (Static Input)
Password: gld938 (Static Input)

Captcha: (Dynamic Input)
---------------------------------------------------
Selenium WebDriver Test Case:

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.irctc.co.in/");
driver.findElement(By.id("usernameId")).sendKeys("gcreddy7");
driver.findElement(By.className("loginPassword")).sendKeys("gld938");

Scanner scan = novel Scanner(System.in);//System.in is an Input stream
System.out.println("Enter Captcha");
String captcha = scan.nextLine();

driver.findElement(By.className("loginCaptcha")).sendKeys(captcha);
driver.findElement(By.id("loginbutton")).click();
String url = driver.getCurrentUrl();

if (url.equals("https://www.irctc.co.in/eticketing/home")){
System.out.println("Login Successful - Passed");
}
else{
System.out.println("Login Unsuccessful - Failed");   
}
driver.close();
}
}
--------------------------------------------------------
4) Test Case: Verify Customer Registration inwards gcrShop Web portal
Test Steps:
 

i) Launch the Browser
ii) Navigate to http://gcrit.com/build3/
iii) Enter all Mandatory fields
iv) Click "Continue" Button
-----------------------
Verification point:
 

Capture conformation message as well as compare alongside expected.

WebDriver driver = novel FirefoxDriver();
driver.get("http://gcrit.com/build3/");
driver.findElement(By.linkText("create an account")).click();
driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input

[1]")).click();
driver.findElement(By.name("firstname")).sendKeys("Rahman");
driver.findElement(By.name("lastname")).sendKeys("Mohommed");
driver.findElement(By.name("dob")).sendKeys("10/20/1990");
driver.findElement(By.name("email_address")).sendKeys("rahman1237@gmail.com");
driver.findElement(By.name("street_address")).sendKeys("abcd xyz");
driver.findElement(By.name("postcode")).sendKeys("12345");
driver.findElement(By.name("city")).sendKeys("Hyderabad");
driver.findElement(By.name("state")).sendKeys("Telangana");

Select Dropdown = novel Select (driver.findElement(By.name("country")));
Dropdown.selectByVisibleText("India");

driver.findElement(By.name("telephone")).sendKeys("9234565453");
driver.findElement(By.name("password")).sendKeys("abcd123");
driver.findElement(By.name("confirmation")).sendKeys("abcd123");
driver.findElement(By.id("tdb4")).click();

String ConformationMessage = driver.findElement(By.xpath(".//*[@id='bodyContent']/h1")).getText();

if (ConformationMessage.equals("Your Account Has Been Created!")){
System.out.println("Customer Registration Successful - Passed");   
}
else{
System.out.println("Customer Registration Unsuccessful - Failed");   
}
driver.close();
--------------------------------------
5) Test Case: Verify Customer Login inwards gcrShop Web portal
Test Steps:

i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/
iii) Click "login" Link
iv) Enter Email Address
v) Enter Password
vi) Click "Sign In" Button
-----------------------
Verification Point:
 

Capture electrical current url as well as compare alongside http://www.gcrit.com/build3/index.php

Selenium Test Case:
WebDriver driver = novel FirefoxDriver();
driver.get("http://gcrit.com/build3/");
driver.findElement(By.linkText("login")).click();
driver.findElement(By.name("email_address")).sendKeys("rahman1237@gmail.com");
driver.findElement(By.name("password")).sendKeys("abcd123");
driver.findElement(By.id("tdb5")).click();
String url = driver.getCurrentUrl();
//System.out.println(url);

if (url.contains("http://www.gcrit.com/build3/index.php")){
System.out.println("Login Successful - Passed");
}
else{
System.out.println("Login Unsuccessful - Failed");
}
driver.close();
-------------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post