Tuesday, February 2, 2016

                                      Selenium Webdriver Multibrowser Testing


We need to test application in different browsers. So, in order to test application in firefox, chrome, IE etc we can use selenium webdriver. 

Firefox (Say FF): No need to add any additional driver for this.
Chrome: Need to install chrome driver.
IE: Need to install IE driver.

Steps to install chrome driver:

2. Search(CTRL+F) for chrome. It will highlight Google Chrome Driver click on this. Then click on "Latest release chrome version" again it will navigate to new page. Again click on "Latest release chrome version". Now you are on required page. Here you can see "win32.zip". click on it.
3. chromedriver.zip will be downloaded. 
4. Extract chromedriver.exe and install it by "double click" on it.

Now you are ready to use chrome driver.

Same thing you have to do for Internet Explorer. (Please comment if you want detailed steps for it as well)

Now, we are having chrome driver, IE driver and firefox driver (By default) with us.

Pre-requisites:
1. Java installed
2. eclipse IDE
3. TestNG
4. Project created in eclipse

Let us look at the program which we can use:


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


class MultiBrowsersTest {

WebDriver driver;

public void multibrowserfunction(String browser)
{
if(browser.equalsIgnoreCase("chrome"))
{
System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
driver = new ChromeDriver();

}
else if(browser.equalsIgnoreCase("internetexplorer"))
{
System.setProperty("webdriver.chrome.driver",".\\IEDriverServer.exe");
driver = new ChromeDriver();
}
else
{
driver=new FirefoxDriver();
}
callGoogle();
}

public void callGoogle()
{
driver.get("http://www.google.com");
}
}

public class MultiBrowserMains
{
public static void main(String arg[])
{
MultiBrowsersTest mbt=new MultiBrowsersTest();
mbt.multibrowserfunction("Chrome");
}

}

Please share your views, suggestions, questions and comments (if any).

Happy Learning !!

Monday, February 1, 2016

Today's Topic: I am picking some random topic related to java which may help in creating framework or basic understanding for a automation tester.

Constructor: Is a function having below mentioned features:
  • Same name as class
  • No return type
  • Used to initialize the object
Types: Two types-
  1. Default constructor
  2. Parameterized constructor
Examples:

Default Constructor: If i want to do testing only in single browser. Then code can be like this-

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


class defaultConstructorTest {

    public defaultConstructorTest()
    {
        WebDriver driver ;
        System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
        // Puts an Implicit wait, Will wait for 10 seconds before throwing
        // exception
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("https://www.blogger.com");
       
    }

}
public class constructorTest
{
    public static void main(String arg[])
    {
        defaultConstructorTest pct=new defaultConstructorTest();
       
    }

}


Parameterized Constructor:
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


class parameterizedConstructorTest {

    public parameterizedConstructorTest(String browser)
    {
        WebDriver driver ;
        if(browser.equalsIgnoreCase("chrome"))
        {
        System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
        // Puts an Implicit wait, Will wait for 10 seconds before throwing
        // exception
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("https://www.blogger.com");
        }
    }

}
public class constructorTest
{
    public static void main(String arg[])
    {
        parameterizedConstructorTest pct=new parameterizedConstructorTest("chrome");
      
    }

}



Wednesday, January 27, 2016

Hi,

Today i am re-continuing my blog. I promise to do at least one blog each month.
It may be based on my learning in testing or my experience.

I hope i will keep my promise !!

Thanks,
Sonal