9121822375 sdetforum@gmail.com

It is necessary to test your AUT functionality against all major browsers, In this post, we will see basic programs to launch the Chrome Browser and Firefox Browser in Selenium WebDriver.

Pre-requisites
  1. Chrome Browser – Download it from Here
  2. ChromeDriver – Download from Here
  3. Firefox Browser – Download it from Here
  4. GeckoDriver – Download from Here

Note: Download above browser drivers based on your browser version, if you don’t do – your tests are not going to execute.

Launch Chrome Browser in Selenium Java

package launchbrowsers;

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

public class LaunchChromeBrowser 
{

	public static void main(String[] args) throws InterruptedException 
	{
		// set chromedriver path
		System.setProperty("webdriver.chrome.driver", "D:\\browser-drivers\\chromedriver.exe");
		// instantiate ChromeDriver class
		WebDriver driver = new ChromeDriver();
		// launch snapshot site
		driver.get("https://www.snap.com/");
		//maximize the browser window
		driver.manage().window().maximize();
		// wait for sometime
		Thread.sleep(7*1000);
		// quit browser
		driver.quit();

	}

}

Launch Firefox Browser in Selenium Java

package launchbrowsers;

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

public class LaunchFirefoxBrowser 
{
	public static void main(String[] args) throws InterruptedException 
	{
		// set geckodriver path
		System.setProperty("webdriver.gecko.driver", "D:\\browser-drivers\\geckodriver.exe");
		// instantiate ChromeDriver class
		WebDriver driver = new FirefoxDriver();
		// launch snapshot site
		driver.get("https://www.snap.com/");
		//maximize the browser window
		driver.manage().window().maximize();
		// wait for sometime
		Thread.sleep(7*1000);
		// quit browser
		driver.quit();

	}
}

Important Note

Please set your browser driver path in the below line.
System.setProperty(“webdriver.gecko.driver”, “D:\\browser-drivers\\geckodriver.exe”);