Selenium Real time Project Framework – Browser Factory #4

Welcome to the Selenium Real-time Project framework series. The last tutorial showed us how to set up the project framework. The purpose of this tutorial is to show you how to implement Browser-based functionality. We recommend that you read past tutorials before jumping to the Selenium real time project framework.

  1. Selenium Real-time Project Framework – #1 (Maven Project)
  2. Selenium Real-time Project Framework #2 Framework Structure
  3. Selenium Real-time Project Framework #3 Configure Project

Without any further delay, let us proceed with discussing the functionality that is based on browsers. As the name suggests, we are going to implement browser-based methods like

  1. Open browser
  2. Close browser

Let’s move ahead with Open browser.

  1. The logic behind this method, known as the Open Browser method, appears to be straightforward; however, it is not. The primary principle of Open browser is to initiate the necessary browser, but it first checks the type of browser that has been specified in the file. Depending on the type of browser, it setups the property as browser driver executable file and then initiates the browser specified in Furthermore, it requires one additional parameter that is the base URL of your project that you want to test.
public static WebDriver startApplication(WebDriver driver,String browserName,String appUrl)
			System.setProperty("", "./Drivers/chromedriver.exe");
			ChromeOptions op = new ChromeOptions();
	         driver = new ChromeDriver(op);
		else if(browserName.equals("Firefox"))
			System.setProperty("", "./Drivers/geckodriver.exe");
	         driver = new FirefoxDriver();
		else if(browserName.equals("IE"))
			System.setProperty("", "./Drivers/IEDriverServer.exe");
	         driver = new InternetExplorerDriver();
			System.out.println("We do not support this browser ");

		return driver;


So if you see the definition of startApplication method:

  • It requires 3 parameters: driver, browserName and appUrl.
  • It checks the name of browser that we defined in file & thereafter initiate the browser.
  • Furthermore, it maximizes the browser window.
  • Thereafter, it opens the project URL.
  • And in last, it adds up the implicit wait to test case. To get more about implicit wait, please follow the link:

2. Close browser: This method is pretty simple. the logic of this method is to close the browser that initialized in startApplication method.

public static void quitBrowser(WebDriver driver)

To get more explanation, we would like you to follow the below video tutorial:

Selenium Automation testing with TestNG
Testing Next Generation.
Learn - Selenium Real-Time Project with Data-driven testing
Learn how to create data-driven testing framework.
Selenium Automation testing with TestNG
Learn - Selenium Real-Time Project with Data-driven testing

Similar Posts