webdriver test cases

Selenium WebDriver Sample Test Case
--------------------------------------------------- 
Operating Environment: MS Windows

Programming Language: Java

IDE: Eclipse:
------------------------
WebDriver Environment Setup: 

---------------------------------------------------
> Download and Java (JDK) and Install

> Set Path Variable (Environment Variable)

> Download EClipse Software

> Download WebDriver Java Language Binding and Add WebDriver Jars to Java Project
in Eclipse

> Download and Install Firebug (As Firefox Browser Plug in)
(If we want use IE or Chrome browsers, no need to download any plug in, they have their own developer tools to inspect elements.)

> Download Internet Explorer and Chrome Drivers for WebDriver.

---------------------------------------------------
Write A Sample Test:


 > Launch EClipse IDE

> Create java Project

> Create Package

> Create Class and write Test/Program

---------------------------------------------------
 How to Write: 
---------------------------------------------------
 > Import WebDriver Libraries and Browser (Ex: Firefox) driver libraries.

> Create Driver Object

> Inspect Elements using Firebug for Firefox browser.

> Write Test using Element locators and WebDriver Methods.
-----------------------------------------------------------------
Note: WebDriver Methods and Web element locators are common for all Browsers.
 
---------------------------------------------------
 Create a Test for Gmail Login Functionality:
Steps:
i) Launch the Browser
ii) Navigate to Gmail home page
iii) Enter Email
iv) Enter Password
v) Click Sign In Button
---------------------------------
a) Test for Firefox Browser:

-----------------------------
package WebDriverTests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GmailLogin {
    public static void main(String [] args) throws InterruptedException {
        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();
        Thread.sleep(10000);
        String Expected ="inbox";
        String URLTitle = driver.getCurrentUrl();
        if (URLTitle.contains(Expected)){
            System.out.println("Login Successful");
        }
            else{
                System.out.println("Login Failed");   
            }
            }
    }
-------------------------------------------------------
a) Test for Internet Explorer Browser:
package WebDriverTests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class GmailLogin {
    public static void main(String [] args) throws InterruptedException {
        System.setProperty("webdriver.ie.driver", "d://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();
        Thread.sleep(10000);
        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
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GmailLogin {
    public static void main(String [] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "d://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();
        Thread.sleep(10000);
        String Expected ="inbox";
        String URLTitle = driver.getCurrentUrl();
        if (URLTitle.contains(Expected)){
            System.out.println("Login Successful");
        }
            else{
                System.out.println("Login Failed");   
            }
            }
    }
----------------------------------------------------------

0 comments:

Post a Comment