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 config.properties file. Depending on the type of browser, it setups the property as browser driver executable file and then initiates the browser specified in config.properties. 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)
	{
		
		if(browserName.equals("Chrome"))
		{
			System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver.exe");
			ChromeOptions op = new ChromeOptions();
			op.addArguments("--remote-allow-origins=*");
	         driver = new ChromeDriver(op);
		}
		else if(browserName.equals("Firefox"))
		{
			System.setProperty("webdriver.chrome.driver", "./Drivers/geckodriver.exe");
	         driver = new FirefoxDriver();
		}
		else if(browserName.equals("IE"))
		{
			System.setProperty("webdriver.chrome.driver", "./Drivers/IEDriverServer.exe");
	         driver = new InternetExplorerDriver();
		}
		else
		{
			System.out.println("We do not support this browser ");
		}

		
		driver.manage().window().maximize();
		driver.get(appUrl);
		driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
	
		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 config.properties 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: https://www.youtube.com/watch?v=eqzwR5NonJs

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)
	{
		driver.quit();
	}

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

Gain knowledge in software testing and elevate your skills to outperform competitors.

Training Program Demo Timing Training Fees Action
Software Testing Online Certification Training Demo at 09:00 AM ET Starts at $1049 Book your demo
Software Testing Classroom Training in Virginia Demo at 01:00 PM ET every Sunday Starts at $1699 Book your demo
Selenium Certification Training Demo at 10:00 AM ET Starts at $550 Book your demo
Manual Testing Course Demo at 09:00 AM ET Starts at $400 Book your demo
SDET Course – Software Automation Testing Training Demo at 11:00 AM ET Starts at $550 Book your demo
Automation Testing Real-Time Project Training Demo at 10:00 AM ET Starts at $250 Book your demo
Business Analyst Certification Demo at 12:00 PM ET Starts at $550 Book your demo

Search for QA Testing Jobs, Automation Roles, and more…