Cross Browser Testing using Selenium


Cross Browser Testing using Selenium
> Using Selenium WebDriver we can execute Test cases against different browsers.

> Using Element Locators, Webdriver methods and programmatic statements (Java or any other supported language) we can create Test cases.

> Element Locators, WebDriver Methods and Programmatic Statements are common for all browsers (Ex: Firefox, IE and Chrome etc...)

Note: Browser driver only varies from one Browser to another.

Note 2: We need to download IE, Chrome drivers and set driver path, but for Firefox browser no need to download browser driver.

Note 3: We can download IE and Chrome drivers from seleniumhq.org website.
------------------------------------------
Cross Browser Testing using Selenium WebDriver.
Manual Test Case: Verify Gmail Login Functionality
Steps:
i) Launch the Browser
ii) Enter www.gmail.com url in the Browser Address bar Or Navigate to gmail home page.
iii) Enter Email
iv) Click "Next" Button
v) Enter Password
vi) Click "Sign in" Button

Verification: Capture URL after Login and compare if the "inbox" text is available or not?
-------------------------------
a) Selenium Test Case for Firefox Browser
public class VerifyLogin {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();   

driver.get("https:/www.gmail.com");   
driver.findElement(By.id("Email")).sendKeys("gcrindia");
driver.findElement(By.id("next")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("Passwd")).sendKeys("gcreddy123");
driver.findElement(By.id("signIn")).click();
String url = driver.getCurrentUrl();
   
    if (url.contains("inbox")){
    System.out.println("Test Passed");
    }
    else {
    System.out.println("Test Failed");   
    }
    driver.close();
    }
    }
------------------------------------------------
b) Selenium Test Case for Google Chrome Browser
public class VerifyLogin {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver driver = new ChromeDriver();   

driver.get("https:/www.gmail.com");   
driver.findElement(By.id("Email")).sendKeys("gcrindia");
driver.findElement(By.id("next")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("Passwd")).sendKeys("gcreddy123");
driver.findElement(By.id("signIn")).click();
String url = driver.getCurrentUrl();
   
    if (url.contains("inbox")){
    System.out.println("Test Passed");
    }
    else {
    System.out.println("Test Failed");   
    }
    driver.close();
    }
    }
--------------------------------------------------
c) Selenium Test Case for Internet Explorer Browser
public class VerifyLogin {

public static void main(String[] args) {

System.setProperty("webdriver.ie.driver", "E:/IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();   

driver.get("https:/www.gmail.com");   
driver.findElement(By.id("Email")).sendKeys("gcrindia");
driver.findElement(By.id("next")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("Passwd")).sendKeys("gcreddy123");
driver.findElement(By.id("signIn")).click();
String url = driver.getCurrentUrl();
   
    if (url.contains("inbox")){
    System.out.println("Test Passed");
    }
    else {
    System.out.println("Test Failed");   
    }
    driver.close();
    }
    }
----------------------------------------------------

0 comments:

Post a Comment