Sunday, 19 July 2015

Working with Multiple browsers...

package com.actitime.demo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Driver {

public static WebDriver driver;


/**
*
* @param browser
* pass string parameter like firefox , ie or chrome
* @return
* based on your argumnet , mtd will return browser object
*/

public static WebDriver getDriver(String browser){
if(browser.equals("firefox")){
driver = new FirefoxDriver();
}else if (browser.equals("ie")){
System.setProperty("webDriver.ie.driver", "");
driver = new InternetExplorerDriver();
}else{
System.setProperty("webDriver.chrome.driver", "");
driver = new ChromeDriver();
}
return driver;
}


}



Cross Browser Testing Code

package parallelTest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

public class Guru99CrossBrowserScript {

    WebDriver driver;

    

    /**

     * This function will execute before each Test tag in testng.xml

     * @param browser

     * @throws Exception

     */

@BeforeTest

    @Parameters("browser")

    public void setup(String browser) throws Exception{

        //Check if parameter passed from TestNG is 'firefox'

        if(browser.equalsIgnoreCase("firefox")){

        //create firefox instance

            driver = new FirefoxDriver();

        }

        //Check if parameter passed as 'chrome'

        else if(browser.equalsIgnoreCase("chrome")){

            //set path to chromedriver.exe You may need to download it from http://code.google.com/p/selenium/wiki/ChromeDriver

            System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");

            //create chrome instance

            driver = new ChromeDriver();

        }

else if(browser.equalsIgnoreCase("ie")){

            //set path to IEdriver.exe You may need to download it from

     // 32 bits http://selenium-release.storage.googleapis.com/2.42/IEDriverServer_Win32_2.42.0.zip

     // 64 bits http://selenium-release.storage.googleapis.com/2.42/IEDriverServer_x64_2.42.0.zip

            System.setProperty("webdriver.ie.driver","C:\\IEdriver.exe");

            //create chrome instance

            driver = new InternetExplorerDriver();

        }

        else{

            //If no browser passed throw exception

            throw new Exception("Browser is not correct");

        }

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    }

Welcome to the World of Automation


Few Good Things about Selenium Automation Testing Tool...

1. Selenium is an open source tool i.e. Unlike the proprietary tools its available free of cost.
2. This is the best tool available in the market for web application testing
3. Its extensible and flexibility, along with its tight integration with the browser, is unmatched by available proprietary tools.
4. Selenium is possibly the most widely used open source solution.
5. One of the selenium's key features is the support for executing one's tests on multiple browser platforms like Internet Explorer, Firefox, Google Chrome, Opera, Safari etc.
6. Selenium allows you to control a browser from a language of your choice. You can choose any one of these Six languages to write automation scripts -> Java, C#, Ruby, Python, Perl and Php
7. Selenium is available for Operating Systems such as Windows, Linux and Mac
8. Selenium can be used for functional, compatibility, regression testing and User Acceptance Testing 9. Selenium is mainly used for Regression testing, to decrease the effort of Manual Testers.
  • Functional Testing refers to the test that verifies a specific action of the software e.g. - Logging into the Facebook is an action.
  • Compatibility Testing is performed to verify whether a software works with all other supported Browser, OS, Hardware and Different kind of System Environment. 
  • Regression Testing is the testing done by executing older test cases to make sure that new functionality is not Impacted on older one.
  • User Acceptance Testing is testing an application prior to customer delivery for functionality and usability  using real world scenarios which resemble how the application will be used by the end users.
Drawbacks of using Selenium Automation Tools:

1. Selenium is a browser based testing tool. It can be used only to test web based applications.