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:
1. Go to http://www.seleniumhq.org/download/
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.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 !!