-
-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved Browserstack session name support
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
...y-browserstack/src/main/java/net/serenitybdd/plugins/browserstack/BuildNameGenerator.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,42 @@ | ||
package net.serenitybdd.plugins.browserstack; | ||
|
||
import net.serenitybdd.core.Serenity; | ||
import net.thucydides.model.ThucydidesSystemProperty; | ||
import net.thucydides.model.util.EnvironmentVariables; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* Get a build name from the environment variables, or generate one if not provided. | ||
* It can be defined externally by setting the BROWSERSTACK_BUILD_NAME environment variable. | ||
* The build name is used to group test results in BrowserStack. | ||
*/ | ||
public class BuildNameGenerator { | ||
private final EnvironmentVariables environmentVariables; | ||
|
||
BuildNameGenerator(EnvironmentVariables environmentVariables) { | ||
this.environmentVariables = environmentVariables; | ||
} | ||
|
||
public static BuildNameGenerator forEnvironmentVariables(EnvironmentVariables environmentVariables) { | ||
return new BuildNameGenerator(environmentVariables); | ||
} | ||
|
||
public String getBuildName() { | ||
return this.environmentVariables.optionalProperty("BROWSERSTACK_BUILD_NAME") | ||
.orElseGet(() -> this.environmentVariables.optionalProperty("BROWSERSTACK_BUILD_NAME") | ||
.orElse(defaultBuildName())); | ||
} | ||
|
||
private String defaultBuildName() { | ||
|
||
String currentDirectoryName = Paths.get("").toAbsolutePath().toFile().getName(); | ||
String currentProjectName = ThucydidesSystemProperty.SERENITY_PROJECT_NAME.from(environmentVariables,currentDirectoryName); | ||
String date = Serenity.getTestSuiteStartTime().format(DateTimeFormatter.BASIC_ISO_DATE) | ||
+ "-" + Serenity.getTestSuiteStartTime().format(DateTimeFormatter.ofPattern("HHmmss")); | ||
return currentProjectName + " - " + date; | ||
} | ||
} |
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