Skip to content

Commit

Permalink
issue #77: get browser version from capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
s047432 authored and s047432 committed Jan 19, 2018
1 parent 20acc9a commit 0ba916b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@
import org.apache.commons.codec.binary.Base64OutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.UselessFileDetector;
import org.openqa.selenium.support.events.EventFiringWebDriver;

Expand All @@ -59,7 +62,7 @@
/**
* Supports file upload in remote webdriver.
*/
public class CustomEventFiringWebDriver extends EventFiringWebDriver {
public class CustomEventFiringWebDriver extends EventFiringWebDriver implements HasCapabilities {

private static final Logger logger = SeleniumRobotLogger.getLogger(CustomEventFiringWebDriver.class);
private FileDetector fileDetector = new UselessFileDetector();
Expand Down Expand Up @@ -388,4 +391,9 @@ public List<Long> getDriverPids() {
public BrowserInfo getBrowserInfo() {
return browserInfo;
}

@Override
public Capabilities getCapabilities() {
return ((HasCapabilities)driver).getCapabilities();
}
}
25 changes: 15 additions & 10 deletions core/src/main/java/com/seleniumtests/driver/WebUIDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.util.Map;

import org.apache.log4j.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.WebDriverEventListener;
Expand Down Expand Up @@ -263,20 +263,24 @@ protected WebDriver handleListeners(WebDriver driver, BrowserInfo browserInfo, L
* In local mode only, display the browser version
* For remote, will use either the default one, or version specified in test context
*/
private void displayBrowserVersion() {
String version = null;
private void checkBrowserAvailable() {
if (config.getMode() == DriverMode.LOCAL && !config.getTestType().isMobile()) {
Map<BrowserType, BrowserInfo> browsers = OSUtility.getInstalledBrowsersWithVersion();
if (!browsers.containsKey(config.getBrowser())) {
throw new ConfigurationException(String.format("Browser %s is not available. Available browsers are %s",
config.getBrowser(), browsers));
}
version = browsers.get(config.getBrowser()).getVersion();
} else if (!config.getTestType().isMobile()) {
version = SeleniumTestsContextManager.getThreadContext().getWebBrowserVersion();
}
}

private void displayBrowserVersion() {
if (driver == null) {
return;
}

logger.info("Browser version is: " + version);
Capabilities caps = ((CustomEventFiringWebDriver) driver).getCapabilities();
String browserName = caps.getBrowserName();
String browserVersion = caps.getVersion();
logger.info(String.format("Browser is: %s %s", browserName, browserVersion));
}

public WebDriver createWebDriver() {
Expand All @@ -289,9 +293,10 @@ public WebDriver createWebDriver() {



displayBrowserVersion();
checkBrowserAvailable();
driver = createRemoteWebDriver();

displayBrowserVersion();

if (config.getTestType().isMobile()) {
logger.info("Finished creating appium driver");
} else {
Expand Down

0 comments on commit 0ba916b

Please sign in to comment.