2

I am upgrading to Selenium 3 which has broken a function I wrote a long while back that retrieves OS and browser information from the WebDriver instance.

This used to get the browser version and OS name:

Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
String browserVersion = cap.getVersion();
String osName = cap.getPlatform().name().toLowerCase();

It no longer works. I get an empty string for the browser version and 'any' for the OS name. I am using a third party tool to manager the driver binaries:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>1.7.0</version>
</dependency>

This is how I create the driver instance:

    FirefoxDriverManager.getInstance().setup();

    DesiredCapabilities caps = DesiredCapabilities.firefox();
    caps.setCapability("acceptInsecureCerts", true);

    WebDriver driver = new FirefoxDriver(caps);

    WebDriver.Timeouts timeouts = driver.manage().timeouts();
    timeouts.implicitlyWait(5L, TimeUnit.SECONDS);
    driver.manage().window().maximize();

    return driver;

This isn't much different from my Selenium 2 code. The only difference is the use of the driver manager from the 3rd party tool because using Firefox requires geckodriver now.

Selena
  • 1,944
  • 5
  • 26
  • 43

1 Answers1

2

I figured this out:

    Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();

    String browserName = cap.getBrowserName();
    String browserVersion = (String)cap.getCapability("browserVersion");
    String osName = Platform.fromString((String)cap.getCapability("platformName")).name().toLowerCase();

    return browserName + browserVersion + "-" + osName;

Maybe it's the case that the names of the platform and browser version keys for the capabilities map changed and broke this functionality. In any case, I can now correctly retrieve the plaform and browser version.

Selena
  • 1,944
  • 5
  • 26
  • 43