Selenium WebDriver Examples

Selenium WebDriver Test Case Examples
Using Web Element locators (id, name, className, tagNeme, linkText, partialLinkText, cssSelecor and xpath) and WebDriver methods we can create Tests or Test Script or Test Cases.
---------------------------------------------------
If we want to execute Selenium WebDriver Test cases using different Browsers then Browser driver only varies from one Browser to another.

Element locators are same, WebDriver methods are same and Enhancing test cases using Programming features also same.

Browser driver varies from one browser to another.
------------------------------------------
Firefox Browser driver is default driver,
If we want user IE or Chrome Browsers then download the Browser drivers and provide driver path.
--------------------------------------------
1) Test Case: Verify the Gmail Login Functionality
Test Steps/Navigation:

i) Launch the Browser
ii) Navigate to Gmail Home page
iii) Enter Email
iv) Enter Password
v) Click signin Button
------------------
Verification Point: Verify if the URL contains "inbox" or not?
--------------------------------------------------------
a) Test for Firefox Browser:
WebDriver driver = new FirefoxDriver();
driver.get("http://gmail.com");
driver.findElement(By.id("Email")).sendKeys("gcreddy123");
driver.findElement(By.id("Passwd")).sendKeys("selenium123");
driver.findElement(By.id("signIn")).click();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
               
String Expected ="inbox";
String URLTitle = driver.getCurrentUrl();
if (URLTitle.contains(Expected)){
System.out.println("Login Successful");
}
else{
System.out.println("Login Failed");   
-------------------------------------------------------
b) Test for Internet Explorer Browser:
 

System.setProperty("webdriver.ie.driver", "e://IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://gmail.com");
driver.findElement(By.id("Email")).sendKeys("gcreddy123");
driver.findElement(By.id("Passwd")).sendKeys("selenium123");
driver.findElement(By.id("signIn")).click();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
               
String Expected ="inbox";
String URLTitle = driver.getCurrentUrl();
if (URLTitle.contains(Expected)){
System.out.println("Login Successful");
}
else{
System.out.println("Login Failed");   
---------------------------------------------------------
c) Test for Chrome Browser:
 

System.setProperty("webdriver.chrome.driver", "e://chromeDriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://gmail.com");
driver.findElement(By.id("Email")).sendKeys("gcreddy123");
driver.findElement(By.id("Passwd")).sendKeys("selenium123");
driver.findElement(By.id("signIn")).click();
 

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
               
String Expected ="inbox";
String URLTitle = driver.getCurrentUrl();
if (URLTitle.contains(Expected)){
System.out.println("Login Successful");
}
else{
System.out.println("Login Failed");   
-----------------------------------------------------------
2) Check an Object Existence in Google Home Page 

(Check if the Gmail link exists or not in Google Home page)

WebDriver driver = new FirefoxDriver();
driver.get("http:/google.com");
int i = driver.findElements(By.linkText("Yahoo")).size();

if ( i != 0) {
System.out.println("Passed");
}
else
{
System.out.println("Failed");   
}
------------------------------------------------
Using Google Chrome Browser:

 
System.setProperty("webdriver.chrome.driver", "E://chromeDriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http:/google.com");
int i = driver.findElements(By.linkText("Gmail")).size();

if ( i != 0) {
    System.out.println("Passed");
}
    else
    {
    System.out.println("Failed");   
}
-------------------------------------------------------------
3) Verify "Customer Registration" in www.indiae.in web portal.
Steps:
----------
i) Launch the browser
ii) Navigate to www.indiae.in
iii) Click Register link
iv) Enter Email
v) Re-Enter Email
vi) Enter Password
v) Click on Register Button

Verification Point:
Capture the Message and Compare with expected
-------------------------------------------

WebDriver Test:
WebDriver driver = new FirefoxDriver();
        driver.get("http:/indiae.in");
        driver.manage().window().maximize();
        driver.findElement(By.linkText("register")).click();
       
    driver.findElement(By.id("email")).sendKeys("gcreddy4321a1a@gcreddy.com");
        driver.findElement(By.id("email2")).sendKeys("gcreddy4321a1a@gcreddy.com");
        driver.findElement(By.id("password")).sendKeys("abcd123");
        driver.findElement(By.xpath(".//*[@id='botonenviar']")).click();
String Message = driver.findElement(By.xpath(".//*[@id='contenido']/div[2]/h1")).getText();
       
        if (Message.contentEquals("Check your e-mail!")) {
            System.out.println("Passed");
        }
        else
        {
            System.out.println("Failed");   
        }   

2 comments:

Sir, please help us to learn Data Drive Framework. This would be really help to us..

Post a Comment