WebDriver Creation/Management

TAF have an in-built driver creation and management system in place. Following are the features available by the said API:

  • Default driver creation based on the provided driver name ex. firefox , chrome , ie , etc.
  • Flexibility to define custom driver creation and easy plugging in to the framework.
  • Multi-threaded/Non multi-threaded driver management.

Default WebDriver creation

As mentioned earlier in the features TAF provide a default implementation for driver creation. In case you need a particular driver for your tests you can use the existing API provided by TAF for it. Just mention the type of driver you need by providing a value to the property driver.name in side the TAF properties file.

Look at the following example for better understanding.

Configuration in the properties file:

driver.name = firefox

Following is the sample test where it uses the driver creation class CacheDriverFactory for creation of driver.

	@Test
	public void inbuildDriveCreationTest(){
		DefaultConfig config = DefaultConfig.getDefaultConfig();
		config.setConfigValue("driver.name", "firefox");
		
		CacheDriverFactory driverFactory = new CacheDriverFactory();
		WebDriver driver = driverFactory.getDriver();
		driver.get("http://www.google.com");		
	}

Configuring Multi-threaded driver management

TAF have an in-build driver management which allow users to manage their driver in a way that the same driver instance can be available across all tests or each thread execution can have its own instance of driver object for their tests. This can be done by setting the value of thread.based.driver to true in taf.properties file.

User defined Driver instance

It also provides the flexibility to provide your own driver creation logic by writing a class that implments the IDriverProvider interface. The path of the said class then has to be set to the property userdefined.driverclass inside the taf.properties file.

Let’s look at the following example:

Following is the customized class:

class UserDefinedDriverProvider implements IDriverProvider{
	
	DefaultConfig config = DefaultConfig.getDefaultConfig();

	@Override
	public WebDriver getDriver() {
		WebDriver driver = new FirefoxDriver();
		driver.manage().window().maximize();
		return driver;
	}
}

Following is the property that is set inside the taf.properties file:

userdefined.driverclass = com.test.automation.framework.driver.UserDefinedDriverProvider