Determining the type of Selenium driver in Java

I am working on creating a testing platform for some sites using selenium webdriver, and my goal is to have several drivers running the same tests at the same time (e.g. firefoxdriver, internetexplorerdriver and chrome reverse, working on the same time as some shared ones resources). However, I am having problems logging which driver does what. I pass in drivers for a lot of my code, but as far as I can tell, the web server does not know what type of driver it is. Is there any way to ask the webdriver element what it was created as?

+4
source share
2 answers

You can use instanceofas

  if( driver instanceof FirefoxDriver) {
    System.out.println("Firefox it is!!");
  }
  else if( driver instanceof ChromeDriver) {
    System.out.println("Chrome it is!!");
  }
  // and so on 

For more information: What is the instanceof operator that is used for?

+7
source
/******************************************************************************************
 * Name: getBrowserDetails | Description: Gets Browser Name and Version
 ******************************************************************************************/
public String getBrowserDetails() throws Exception {
    Capabilities caps = ((RemoteWebDriver)BaseTest.driver).getCapabilities();
    String browserName = caps.getBrowserName();
    String browserVersion = caps.getVersion();
    String browser = (browserName + " " + browserVersion).toUpperCase();
    return browser;
}
0
source

All Articles