-
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a page to the reports containing system and configuration prope…
…rties and browser capabilities for a given test run. The browser used for each test is also recorded and displayed as an icon on the test report pages. You can also add your own custom fields into the build information page. You do this by adding properties with the "sysinfo" prefix to your serenity.properties file. These variables take Groovy expressions, which will be evaluated when the report is run, e.g: sysinfo.theAnswer = 6*7 sysinfo.homeDir = System.getenv("HOME")
- Loading branch information
Showing
36 changed files
with
628 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# | ||
#Thu Feb 12 13:47:25 EST 2015 | ||
version= | ||
browserName=firefox |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
core/src/main/java/net/serenitybdd/core/buildinfo/BuildInfoProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package net.serenitybdd.core.buildinfo; | ||
|
||
import com.beust.jcommander.internal.Maps; | ||
import groovy.lang.Binding; | ||
import groovy.lang.GroovyShell; | ||
import net.thucydides.core.ThucydidesSystemProperty; | ||
import net.thucydides.core.guice.Injectors; | ||
import net.thucydides.core.guice.ThucydidesModule; | ||
import net.thucydides.core.util.EnvironmentVariables; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import static ch.lambdaj.Lambda.filter; | ||
import static org.hamcrest.CoreMatchers.startsWith; | ||
|
||
/** | ||
* Created by john on 12/02/15. | ||
*/ | ||
public class BuildInfoProvider { | ||
private final EnvironmentVariables environmentVariables; | ||
private final DriverCapabilityRecord driverCapabilityRecord; | ||
|
||
public BuildInfoProvider(EnvironmentVariables environmentVariables) { | ||
this.environmentVariables = environmentVariables; | ||
this.driverCapabilityRecord = Injectors.getInjector().getInstance(DriverCapabilityRecord.class); | ||
} | ||
|
||
public BuildProperties getBuildProperties() { | ||
Map<String, String> generalProperties = Maps.newHashMap(); | ||
generalProperties.put("Default Driver",ThucydidesSystemProperty.DRIVER.from(environmentVariables,"firefox")); | ||
generalProperties.put("Operating System",System.getProperty("os.name") + " version " + System.getProperty("os.version")); | ||
addRemoteDriverPropertiesTo(generalProperties); | ||
addCustomPropertiesTo(generalProperties); | ||
|
||
List<String> drivers = driverCapabilityRecord.getDrivers(); | ||
Map<String, Properties> driverPropertiesMap = driverCapabilityRecord.getDriverCapabilities(); | ||
|
||
return new BuildProperties(generalProperties, drivers, driverPropertiesMap); | ||
} | ||
|
||
private void addRemoteDriverPropertiesTo(Map<String, String> 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)); | ||
} | ||
} | ||
|
||
private void addCustomPropertiesTo(Map<String, String> buildProperties) { | ||
|
||
List<String> sysInfoKeys = filter(startsWith("sysinfo."), environmentVariables.getKeys()); | ||
for(String key : sysInfoKeys) { | ||
String simplifiedKey = key.replace("sysinfo.", ""); | ||
String expression = environmentVariables.getProperty(key); | ||
|
||
String value = evaluateGroovyExpression(expression); | ||
|
||
buildProperties.put(simplifiedKey, value); | ||
} | ||
|
||
} | ||
|
||
private String evaluateGroovyExpression(String expression) { | ||
Binding binding = new Binding(); | ||
binding.setVariable("env", environmentVariables); | ||
GroovyShell shell = new GroovyShell(binding); | ||
return shell.evaluate(expression).toString(); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/net/serenitybdd/core/buildinfo/BuildProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.serenitybdd.core.buildinfo; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Created by john on 12/02/15. | ||
*/ | ||
public class BuildProperties { | ||
|
||
private final Map<String, String> generalProperties; | ||
private final List<String> drivers; | ||
private final Map<String, Properties> driverProperties; | ||
|
||
public BuildProperties(Map<String, String> generalProperties, List<String> drivers, Map<String, Properties> driverProperties) { | ||
this.generalProperties = generalProperties; | ||
this.drivers = drivers; | ||
this.driverProperties = driverProperties; | ||
} | ||
|
||
public Map<String, String> getGeneralProperties() { | ||
return ImmutableMap.copyOf(generalProperties); | ||
} | ||
|
||
public List<String> getDrivers() { | ||
return ImmutableList.copyOf(drivers); | ||
} | ||
|
||
public Map<String, Properties> getDriverProperties() { | ||
return ImmutableMap.copyOf(driverProperties); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
core/src/main/java/net/serenitybdd/core/buildinfo/DriverCapabilityRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.serenitybdd.core.buildinfo; | ||
|
||
import org.openqa.selenium.Capabilities; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Created by john on 12/02/15. | ||
*/ | ||
public interface DriverCapabilityRecord { | ||
void registerCapabilities(String driver, Capabilities capabilities); | ||
List<String> getDrivers(); | ||
Map<String,Properties> getDriverCapabilities(); | ||
} |
90 changes: 90 additions & 0 deletions
90
core/src/main/java/net/serenitybdd/core/buildinfo/PropertyBasedDriverCapabilityRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package net.serenitybdd.core.buildinfo; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
import com.google.inject.Inject; | ||
import net.thucydides.core.webdriver.Configuration; | ||
import org.openqa.selenium.Capabilities; | ||
|
||
import java.io.*; | ||
import java.nio.file.DirectoryIteratorException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import static java.nio.file.Files.newInputStream; | ||
|
||
/** | ||
* Created by john on 12/02/15. | ||
*/ | ||
public class PropertyBasedDriverCapabilityRecord implements DriverCapabilityRecord { | ||
|
||
private Configuration configuration; | ||
|
||
@Inject | ||
public PropertyBasedDriverCapabilityRecord(Configuration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
public void registerCapabilities(String driver, Capabilities capabilities) { | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty("platform", capabilities.getPlatform().name()); | ||
for (String capability : capabilities.asMap().keySet()) { | ||
if (capabilities.getCapability(capability) instanceof String) { | ||
properties.setProperty(capability, capabilities.getCapability(capability).toString()); | ||
} | ||
} | ||
try { | ||
File browserProperties = new File(configuration.getOutputDirectory(), "browser-" + driver.toLowerCase() + ".properties"); | ||
try (Writer writer = new FileWriter(browserProperties)) { | ||
properties.store(writer, ""); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<String> getDrivers() { | ||
List<String> drivers = Lists.newArrayList(); | ||
try (DirectoryStream<Path> stream = driverCapabilityRecords()) { | ||
for (Path file : stream) { | ||
String driverName = driverNameFrom(file); | ||
drivers.add(driverName); | ||
} | ||
} catch (IOException | DirectoryIteratorException x) { | ||
System.err.println(x); | ||
} | ||
return drivers; | ||
} | ||
|
||
private String driverNameFrom(Path file) { | ||
return file.getFileName().toString().replace("browser-","").replace(".properties",""); | ||
} | ||
|
||
private DirectoryStream<Path> driverCapabilityRecords() throws IOException { | ||
Path outputDirectory = configuration.getOutputDirectory().toPath(); | ||
return Files.newDirectoryStream(outputDirectory,"browser-*.properties"); | ||
} | ||
|
||
@Override | ||
public Map<String, Properties> getDriverCapabilities() { | ||
Map<String, Properties> driverCapabilities = Maps.newHashMap(); | ||
try (DirectoryStream<Path> stream = driverCapabilityRecords()) { | ||
for (Path file : stream) { | ||
String driverName = driverNameFrom(file); | ||
Properties driverProperties = new Properties(); | ||
driverProperties.load(newInputStream(file)); | ||
driverCapabilities.put(driverName, driverProperties); | ||
} | ||
} catch (IOException | DirectoryIteratorException x) { | ||
System.err.println(x); | ||
} | ||
return driverCapabilities; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.