How can I get the WebDriver version during Testrun

2019-02-27 12:17发布

I am writing on a testframework where the report should include the webdriver version of the test run. When using selenium there is the getEval("Selenium.version") method. But I find no way to read the version when using webdriver. Does anyone know a solution?

2条回答
孤傲高冷的网名
2楼-- · 2019-02-27 12:36

It's possible by reading the VERSION.txt properties file. This seems hacky, but it's what the WebDriver developers do in SeleniumServer.java:

final Properties p = new Properties();
p.load(getSeleniumResourceAsStream("/VERSION.txt"));
String rcVersion = p.getProperty("selenium.rc.version");
String rcRevision = p.getProperty("selenium.rc.revision");
String coreVersion = p.getProperty("selenium.core.version");
String coreRevision = p.getProperty("selenium.core.revision");
BuildInfo info = new BuildInfo();
String versionString = String.format("v%s%s, with Core v%s%s. Built from revision %s",
    rcVersion, rcRevision, coreVersion, coreRevision, info.getBuildRevision());

Note that this requires a static import:

import static org.openqa.selenium.browserlaunchers.LauncherUtils.getSeleniumResourceAsStream;
查看更多
对你真心纯属浪费
3楼-- · 2019-02-27 12:43

Actual path to file with version in selenium is:

/META-INF/maven/org.seleniumhq.selenium/selenium-java/pom.properties

Properties p = new Properties();
p.load(LauncherUtils.class.getResourceAsStream("/META-INF/maven/org.seleniumhq.selenium/selenium-java/pom.properties"));
p.getProperty("version");`
查看更多
登录 后发表回答