Skip to content

Commit

Permalink
Fixed issue with multi=module support in maven
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jul 11, 2023
1 parent 6e2ed6a commit 0d4e67d
Show file tree
Hide file tree
Showing 28 changed files with 475 additions and 378 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void the_step_delay_value_can_be_defined_in_a_system_property() {

@Test
public void the_browser_restart_value_can_be_defined_in_a_system_property() {
environmentVariables.setProperty("thucydides.restart.browser.frequency", "5");
environmentVariables.setProperty("serenity.restart.browser.frequency", "5");

assertThat(configuration.getRestartFrequency(), is(5));
}
Expand All @@ -45,29 +45,30 @@ public void there_is_no_step_delay_by_default() {
@Test
public void the_unique_browser_value_can_be_defined_in_a_system_property() {
String outputDirectory = changeSeparatorIfRequired("build/reports/thucydides");
environmentVariables.setProperty("thucydides.outputDirectory", outputDirectory);

environmentVariables.setProperty("serenity.outputDirectory", outputDirectory);
configuration = new SystemPropertiesConfiguration(environmentVariables);

assertThat(configuration.getOutputDirectory().getAbsoluteFile().toString(), endsWith(outputDirectory));
}

@Test
public void the_output_directory_can_be_defined_in_a_system_property() {
environmentVariables.setProperty("thucydides.use.unique.browser", "true");
environmentVariables.setProperty("serenity.use.unique.browser", "true");

assertThat(configuration.shouldUseAUniqueBrowser(), is(true));
}

@Test
public void system_properties_cannot_be_set_if_defined() {
environmentVariables.setProperty("thucydides.use.unique.browser", "true");
configuration.setIfUndefined("thucydides.use.unique.browser", "false");
environmentVariables.setProperty("serenity.use.unique.browser", "true");
configuration.setIfUndefined("serenity.use.unique.browser", "false");

assertThat(configuration.shouldUseAUniqueBrowser(), is(true));
}

@Test
public void system_properties_can_be_set_if_undefined() {
configuration.setIfUndefined("thucydides.use.unique.browser", "false");
configuration.setIfUndefined("serenity.use.unique.browser", "false");

assertThat(configuration.shouldUseAUniqueBrowser(), is(false));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.thucydides.core.webdriver;

import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.thucydides.core.configuration.SystemPropertiesConfiguration;
import net.thucydides.core.configuration.WebDriverConfiguration;
import net.thucydides.core.steps.StepEventBus;
Expand Down Expand Up @@ -92,7 +93,8 @@ public void driver_names_should_be_case_insensitive() {

@Test
public void the_default_output_directory_can_be_overrided_via_a_system_property() {
environmentVariables.setProperty("thucydides.outputDirectory","out");
environmentVariables.setProperty("serenity.outputDirectory","out");
ConfiguredEnvironment.updateConfiguration(environmentVariables);

SystemPropertiesConfiguration config = new SystemPropertiesConfiguration(environmentVariables);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.thucydides.core.webdriver;

import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.thucydides.core.configuration.SystemPropertiesConfiguration;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.environment.MockEnvironmentVariables;
import org.apache.commons.lang3.SystemUtils;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -25,6 +27,11 @@ public void setupEnvironment() {
configuration = new SystemPropertiesConfiguration(environmentVariables);
}

@After
public void cleanup() {
ConfiguredEnvironment.reset();
}

@Test
public void the_default_output_directory_is_in_the_default_maven_site_directory() {
File outputDirectory = configuration.getOutputDirectory();
Expand All @@ -34,15 +41,15 @@ public void the_default_output_directory_is_in_the_default_maven_site_directory(

@Test
public void the_default_output_directory_can_be_overriden_if_the_maven_output_directory_is_overridden_as_a_relative_path() {
environmentVariables.setProperty("project.build.directory", "subproject");
environmentVariables.setProperty("project.build.directory", "subproject/target");
File outputDirectory = configuration.getOutputDirectory();

assertThat(outputDirectory.getPath(), is(changeSeparatorIfRequired("subproject/target/site/serenity")));
}

@Test
public void the_default_output_directory_can_be_overriden_if_the_maven_output_directory_is_overridden_as_an_absolute_path() {
environmentVariables.setProperty("project.build.directory", "/myproject/subproject");
environmentVariables.setProperty("project.build.directory", "/myproject/subproject/target");
File outputDirectory = configuration.getOutputDirectory();

assertThat(outputDirectory.getPath(), is(changeSeparatorIfRequired("/myproject/subproject/target/site/serenity")));
Expand All @@ -51,14 +58,18 @@ public void the_default_output_directory_can_be_overriden_if_the_maven_output_di
@Test
public void the_default_output_directory_can_be_overriden_if_the_maven_site_output_directory_is_overridden() {
environmentVariables.setProperty("project.reporting.OutputDirectory", "custom-reports-directory");
ConfiguredEnvironment.updateConfiguration(environmentVariables);

File outputDirectory = configuration.getOutputDirectory();

assertThat(outputDirectory.getPath(), is(changeSeparatorIfRequired("custom-reports-directory/serenity")));
}

@Test
public void the_default_output_directory_can_be_overriden_using_a_thucydides_system_property() {
environmentVariables.setProperty("thucydides.outputDirectory", "thucydides-reports");
environmentVariables.setProperty("serenity.outputDirectory", "thucydides-reports");
ConfiguredEnvironment.updateConfiguration(environmentVariables);

File outputDirectory = configuration.getOutputDirectory();

assertThat(outputDirectory.getPath(), is("thucydides-reports"));
Expand All @@ -71,7 +82,9 @@ public void an_absolute_thucydides_system_property_always_takes_priority() {

String absolutePath = (SystemUtils.IS_OS_WINDOWS)? "C:\\thucydides-reports" : "/thucydides-reports";

environmentVariables.setProperty("thucydides.outputDirectory", absolutePath);
environmentVariables.setProperty("serenity.outputDirectory", absolutePath);
ConfiguredEnvironment.updateConfiguration(environmentVariables);

File outputDirectory = configuration.getOutputDirectory();

assertThat(outputDirectory.getPath(), is(absolutePath));
Expand All @@ -81,7 +94,9 @@ public void an_absolute_thucydides_system_property_always_takes_priority() {
public void a_relative_thucydides_system_property_uses_the_maven_build_dir() {
environmentVariables.setProperty("project.build.directory", "build");
environmentVariables.setProperty("project.reporting.OutputDirectory", "custom-reports-directory");
environmentVariables.setProperty("thucydides.outputDirectory", "thucydides-reports");
environmentVariables.setProperty("serenity.outputDirectory", "thucydides-reports");
ConfiguredEnvironment.updateConfiguration(environmentVariables);

File outputDirectory = configuration.getOutputDirectory();

assertThat(outputDirectory.getPath(), Matchers.anyOf(is("build/thucydides-reports"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.cucumber.gherkin.CucumberScenarioLoader;
import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.serenitybdd.cucumber.util.PathUtils;
import net.thucydides.core.configuration.SystemPropertiesConfiguration;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.webdriver.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -16,7 +19,6 @@

import static com.google.common.collect.Lists.newArrayList;
import static java.util.stream.Collectors.toList;
import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_OUTPUT_DIRECTORY;

public class CucumberScenarioVisualiser {

Expand All @@ -30,7 +32,7 @@ public CucumberScenarioVisualiser(EnvironmentVariables environmentVariables) {


private String outputDirectory() {
return environmentVariables.getProperty(SERENITY_OUTPUT_DIRECTORY, "target/site/serenity");
return ConfiguredEnvironment.getConfiguration().getOutputDirectory().getPath();
}

public static List<VisualisableCucumberScenarios> sliceIntoForks(int forkCount, List<WeightedCucumberScenarios> slices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sealed class JsonSummaryReport {
private const val DEFAULT_TEMPLATE = "templates/json-summary.ftl"
private const val DEFAULT_SCOREBOARD_SIZE= 5

fun outputDirectory() : ReportProperty<Path> = PathReportProperty(SERENITY_OUTPUT_DIRECTORY, DEFAULT_OUTPUT_DIRECTORY)
fun outputDirectory() : ReportProperty<Path> = ConfiguredOutputDirectoryProperty()

fun reportTitle() : ReportProperty<String> = StringReportProperty(SERENITY_SUMMARY_REPORT_TITLE, DEFAULT_TITLE)

Expand All @@ -36,4 +36,4 @@ sealed class JsonSummaryReport {
fun tagTypes() : ReportProperty<List<String>> = ReportTagTypeProperty()

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ public void should_not_allow_an_incorrectly_specified_driver()
@Test
public void the_output_directory_can_be_defined_by_a_system_property() throws InitializationError {

environmentVariables.setProperty("thucydides.outputDirectory", "target" + FILE_SEPARATOR
environmentVariables.setProperty("serenity.outputDirectory", "target" + FILE_SEPARATOR
+ "reports" + FILE_SEPARATOR
+ "thucydides");
+ "serenity");

SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);

File outputDirectory = runner.getOutputDirectory();

assertThat(outputDirectory.getPath(), is("target" + FILE_SEPARATOR
+ "reports" + FILE_SEPARATOR
+ "thucydides"));
+ "serenity"));

}

Expand All @@ -126,13 +126,13 @@ public void the_output_directory_can_be_defined_by_a_system_property_using_any_s

SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);

environmentVariables.setProperty("thucydides.outputDirectory", "target/reports/thucydides");
environmentVariables.setProperty("serenity.outputDirectory", "target/reports/serenity");

File outputDirectory = runner.getOutputDirectory();

assertThat(outputDirectory.getPath(), is("target" + FILE_SEPARATOR
+ "reports" + FILE_SEPARATOR
+ "thucydides"));
+ "serenity"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SerenityGherkinCheckerMojo extends AbstractMojo {
/**
* The root directory containing the Cucumber feature files
*/
@Parameter(defaultValue = "src/test/resources/features")
@Parameter(defaultValue = "${basedir}/src/test/resources/features")
protected String featureFilesDirectory;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ public class SerenityReportMojo extends AbstractMojo {
/**
* Reports are generated here
*/
@Parameter(property = "serenity.outputDirectory")

@Parameter(property = "serenity.outputDirectory", defaultValue = "${basedir}/target/site/serenity")
public File outputDirectory;

/**
* Serenity test reports are read from here
*/
@Parameter(property = "serenity.sourceDirectory")
@Parameter(property = "serenity.sourceDirectory", defaultValue = "${basedir}/target/site/serenity")
public File sourceDirectory;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package net.serenitybdd.core.environment;

import net.thucydides.core.configuration.SystemPropertiesConfiguration;
import net.thucydides.core.environment.SystemEnvironmentVariables;
import net.thucydides.core.guice.Injectors;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.webdriver.Configuration;

public class ConfiguredEnvironment {
private static final ThreadLocal<EnvironmentVariables> testEnvironmentVariables = new ThreadLocal<>();

private static ThreadLocal<Configuration> currentConfiguration = ThreadLocal.withInitial(() -> Injectors.getInjector().getInstance(Configuration.class));

public static EnvironmentVariables getEnvironmentVariables() {
return SystemEnvironmentVariables.currentEnvironmentVariables();
}

public static Configuration getConfiguration() {
return Injectors.getInjector().getInstance(Configuration.class);
return currentConfiguration.get();
}

public static void updateConfiguration(EnvironmentVariables environmentVariables) {
currentConfiguration.set(new SystemPropertiesConfiguration(environmentVariables));
}

public static void reset() {
testEnvironmentVariables.remove();
currentConfiguration.set(Injectors.getInjector().getInstance(Configuration.class));
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package net.serenitybdd.core.model;

import net.serenitybdd.core.reporting.ReportDirectories;
import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.thucydides.core.model.TestOutcome;
import net.thucydides.core.model.TestStep;
import net.thucydides.core.screenshots.ScreenshotAndHtmlSource;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;

public class FailureDetails {
private final TestOutcome testOutcome;
Expand All @@ -31,8 +31,8 @@ public String getCompleteErrorMessage() {

public boolean pageSourceExists() {
String pageSourceLink = getPageSourceLink();
ReportDirectories reportDirectories = new ReportDirectories();
return (pageSourceLink != null) && (Files.exists(reportDirectories.getReportDirectory().resolve(pageSourceLink)));
Path reportDirectory = ConfiguredEnvironment.getConfiguration().getOutputDirectory().toPath();
return (pageSourceLink != null) && (Files.exists(reportDirectory.resolve(pageSourceLink)));
}

public String getPageSourceLink() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.thucydides.core.configuration;

import net.serenitybdd.core.environment.ConfiguredEnvironment;
import net.serenitybdd.core.strings.Joiner;
import net.thucydides.core.ThucydidesSystemProperty;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.webdriver.Configuration;

import java.io.File;
import java.nio.file.Paths;
Expand Down Expand Up @@ -63,10 +65,7 @@ private String projectMavenReportingDirectory() {
}

private String projectOutputDirectory() {
String thucydidesOutputDurectory = environmentVariables.getProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY);
String serenityOutputDurectory = environmentVariables.getProperty(ThucydidesSystemProperty.SERENITY_OUTPUT_DIRECTORY);

return (serenityOutputDurectory != null) ? serenityOutputDurectory : thucydidesOutputDurectory;
return ConfiguredEnvironment.getConfiguration().getOutputDirectory().getPath();
}

public String getHistoryDirectory() {
Expand Down
Loading

0 comments on commit 0d4e67d

Please sign in to comment.