From e78dd2cfdd98e23c1e69c92ebafffce27dbf7f5b Mon Sep 17 00:00:00 2001 From: John Ferguson Smart Date: Fri, 13 Feb 2015 15:01:39 +1100 Subject: [PATCH] Added support for displaying Saucelabs configuration in the build info screen. --- .../core/buildinfo/BuildInfoProvider.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/net/serenitybdd/core/buildinfo/BuildInfoProvider.java b/core/src/main/java/net/serenitybdd/core/buildinfo/BuildInfoProvider.java index c72c1c0c19..7330b58aed 100644 --- a/core/src/main/java/net/serenitybdd/core/buildinfo/BuildInfoProvider.java +++ b/core/src/main/java/net/serenitybdd/core/buildinfo/BuildInfoProvider.java @@ -7,6 +7,7 @@ import net.thucydides.core.guice.Injectors; import net.thucydides.core.guice.ThucydidesModule; import net.thucydides.core.util.EnvironmentVariables; +import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; @@ -32,6 +33,7 @@ public BuildProperties getBuildProperties() { generalProperties.put("Default Driver",ThucydidesSystemProperty.DRIVER.from(environmentVariables,"firefox")); generalProperties.put("Operating System",System.getProperty("os.name") + " version " + System.getProperty("os.version")); addRemoteDriverPropertiesTo(generalProperties); + addSaucelabsPropertiesTo(generalProperties); addCustomPropertiesTo(generalProperties); List drivers = driverCapabilityRecord.getDrivers(); @@ -43,11 +45,39 @@ public BuildProperties getBuildProperties() { private void addRemoteDriverPropertiesTo(Map buildProperties) { if (ThucydidesSystemProperty.WEBDRIVER_REMOTE_DRIVER.isDefinedIn(environmentVariables)) { buildProperties.put("Remote driver", ThucydidesSystemProperty.WEBDRIVER_REMOTE_DRIVER.from(environmentVariables)); - buildProperties.put("Remote browser version", ThucydidesSystemProperty.WEBDRIVER_REMOTE_BROWSER_VERSION.from(environmentVariables)); - buildProperties.put("Remote OS", ThucydidesSystemProperty.WEBDRIVER_REMOTE_OS.from(environmentVariables)); + if (ThucydidesSystemProperty.WEBDRIVER_REMOTE_BROWSER_VERSION.from(environmentVariables) != null) { + buildProperties.put("Remote browser version", ThucydidesSystemProperty.WEBDRIVER_REMOTE_BROWSER_VERSION.from(environmentVariables)); + } + if (ThucydidesSystemProperty.WEBDRIVER_REMOTE_OS.from(environmentVariables) != null) { + buildProperties.put("Remote OS", ThucydidesSystemProperty.WEBDRIVER_REMOTE_OS.from(environmentVariables)); + } } } + private void addSaucelabsPropertiesTo(Map buildProperties) { + if (ThucydidesSystemProperty.SAUCELABS_URL.isDefinedIn(environmentVariables)) { + buildProperties.put("Saucelabs URL", maskAPIKey(ThucydidesSystemProperty.SAUCELABS_URL.from(environmentVariables))); + if (ThucydidesSystemProperty.SAUCELABS_USER_ID.from(environmentVariables) != null) { + buildProperties.put("Saucelabs user", ThucydidesSystemProperty.SAUCELABS_USER_ID.from(environmentVariables)); + } + if (ThucydidesSystemProperty.SAUCELABS_TARGET_PLATFORM.from(environmentVariables) != null) { + buildProperties.put("Saucelabs target platform", ThucydidesSystemProperty.SAUCELABS_TARGET_PLATFORM.from(environmentVariables)); + } + if (ThucydidesSystemProperty.SAUCELABS_DRIVER_VERSION.from(environmentVariables) != null) { + buildProperties.put("Saucelabs driver version", ThucydidesSystemProperty.SAUCELABS_DRIVER_VERSION.from(environmentVariables)); + } + if (ThucydidesSystemProperty.WEBDRIVER_REMOTE_OS.from(environmentVariables) != null) { + buildProperties.put("Remote OS", ThucydidesSystemProperty.WEBDRIVER_REMOTE_OS.from(environmentVariables)); + } + } + } + + private String maskAPIKey(String url) { + int apiKeyStart = url.indexOf(":"); + int apiKeyEnd = url.indexOf("@"); + return url.substring(0,apiKeyStart + 3) + "XXXXXXXXXXXXXXXX" + url.substring(apiKeyEnd); + } + private void addCustomPropertiesTo(Map buildProperties) { List sysInfoKeys = filter(startsWith("sysinfo."), environmentVariables.getKeys());