How to use getEnvironmentVariables method of net.serenitybdd.jbehave.SerenityStories class

Best Serenity jBehave code snippet using net.serenitybdd.jbehave.SerenityStories.getEnvironmentVariables

Source:SerenityReportingRunner.java Github

copy

Full Screen

...116 return defaultStoryFilter;117 }118 private EnvironmentVariables environmentVariablesFrom(ConfigurableEmbedder configurableEmbedder) {119 if (configurableEmbedder instanceof SerenityStories) {120 return ((SerenityStories) configurableEmbedder).getEnvironmentVariables();121 } else {122 return Injectors.getInjector().getProvider(EnvironmentVariables.class).get();123 }124 }125 @Override126 public Description getDescription() {127 if (description == null) {128 description = Description.createSuiteDescription(configurableEmbedder.getClass());129 for (Description childDescription : getDescriptions()) {130 description.addChild(childDescription);131 }132 }133 return description;134 }...

Full Screen

Full Screen

Source:SerenityStories.java Github

copy

Full Screen

...51 }52 protected SerenityStories(net.thucydides.core.webdriver.DriverConfiguration configuration) {53 this.setSystemConfiguration(configuration);54 }55 public EnvironmentVariables getEnvironmentVariables() {56 if (environmentVariables == null) {57 environmentVariables = Injectors.getInjector().getProvider(EnvironmentVariables.class).get().copy();58 }59 return environmentVariables;60 }61 @Override62 public Configuration configuration() {63 if (configuration == null) {64 net.thucydides.core.webdriver.DriverConfiguration<DriverConfiguration> thucydidesConfiguration = getSystemConfiguration();65 if (environmentVariables != null) {66 thucydidesConfiguration = thucydidesConfiguration.withEnvironmentVariables(environmentVariables);67 }68 configuration = SerenityJBehave.defaultConfiguration(thucydidesConfiguration, formats, this);69 }70 return configuration;71 }72 @Override73 public InjectableStepsFactory stepsFactory() {74 return SerenityStepFactory.withStepsFromPackage(getRootPackage(), configuration()).andClassLoader(getClassLoader());75 }76 /**77 * The class loader used to obtain the JBehave and Step implementation classes.78 * You normally don't need to worry about this, but you may need to override it if your application79 * is doing funny business with the class loaders.80 */81 public ClassLoader getClassLoader() {82 return Thread.currentThread().getContextClassLoader();83 }84 @Override85 public List<String> storyPaths() {86 Set<String> storyPaths = new HashSet<>();87 List<String> pathExpressions = getStoryPathExpressions();88 StoryFinder storyFinder = new StoryFinder();89 for (String pathExpression : pathExpressions) {90 if (absolutePath(pathExpression)) {91 storyPaths.add(pathExpression);92 }93 for (URL classpathRootUrl : allClasspathRoots()) {94 storyPaths.addAll(storyFinder.findPaths(classpathRootUrl, pathExpression, ""));95 }96 storyPaths = removeDuplicatesFrom(storyPaths);97 storyPaths = pruneGivenStoriesFrom(storyPaths);98 }99 return sorted(storyPaths);100 }101 private List<String> sorted(Set<String> storyPaths) {102 List<String> sortedStories = Lists.newArrayList(storyPaths);103 Collections.sort(sortedStories);104 return sortedStories;105 }106 private Set<String> removeDuplicatesFrom(Set<String> storyPaths) {107 Set<String> trimmedPaths = new HashSet<>();108 for(String storyPath : storyPaths) {109 if (!thereExistsALongerVersionOf(storyPath, storyPaths)) {110 trimmedPaths.add(storyPath);111 }112 }113 return trimmedPaths;114 }115 private boolean thereExistsALongerVersionOf(String storyPath, Set<String> storyPaths) {116 for(String existingPath : storyPaths) {117 if ((existingPath.endsWith("/" + storyPath)) || (existingPath.endsWith("\\" + storyPath))) {118 return true;119 }120 }121 return false;122 }123 private Set<String> pruneGivenStoriesFrom(Set<String> storyPaths) {124 List<String> filteredPaths = Lists.newArrayList(storyPaths);125 for (String skippedPrecondition : skippedPreconditions()) {126 filteredPaths = removeFrom(filteredPaths)127 .pathsNotStartingWith(skippedPrecondition)128 .and().pathsNotStartingWith("/" + skippedPrecondition)129 .filter();130 }131 return new HashSet<>(filteredPaths);132 }133 class FilterBuilder {134 private final List<String> paths;135 public FilterBuilder(List<String> paths) {136 this.paths = paths;137 }138 public FilterBuilder pathsNotStartingWith(String skippedPrecondition) {139 List<String> filteredPaths = new ArrayList<>();140 for (String path : paths) {141 if (!startsWith(skippedPrecondition, path)) {142 filteredPaths.add(path);143 }144 }145 return new FilterBuilder(filteredPaths);146 }147 public FilterBuilder and() {148 return this;149 }150 public List<String> filter() {151 return ImmutableList.copyOf(paths);152 }153 private boolean startsWith(String skippedPrecondition, String path) {154 return path.toLowerCase().startsWith(skippedPrecondition.toLowerCase());155 }156 }157 private FilterBuilder removeFrom(List<String> filteredPaths) {158 return new FilterBuilder(filteredPaths);159 }160 private List<String> skippedPreconditions() {161 return DEFAULT_GIVEN_STORY_PREFIX;162 }163 private boolean absolutePath(String pathExpression) {164 return (!pathExpression.contains("*"));165 }166 private Set<URL> allClasspathRoots() {167 try {168 Set<URL> baseRoots = new HashSet<>(Collections.list(getClassLoader().getResources(".")));169 return addGradleResourceRootsTo(baseRoots);170 } catch (IOException e) {171 throw new IllegalArgumentException("Could not load the classpath roots when looking for story files", e);172 }173 }174 private Set<URL> addGradleResourceRootsTo(Set<URL> baseRoots) throws MalformedURLException {175 Set<URL> rootsWithGradleResources = new HashSet<>(baseRoots);176 for (URL baseUrl : baseRoots) {177 String gradleResourceUrl = baseUrl.toString().replace("/build/classes/", "/build/resources/");178 rootsWithGradleResources.add(new URL(gradleResourceUrl));179 }180 return rootsWithGradleResources;181 }182 /**183 * The root package on the classpath containing the JBehave stories to be run.184 */185 protected String getRootPackage() {186 return RootPackage.forPackage(getClass().getPackage());187 }188 protected List<String> getStoryPathExpressions() {189 return Lists.newArrayList(Splitter.on(';').trimResults().omitEmptyStrings().split(getStoryPath()));190 }191 /**192 * The root package on the classpath containing the JBehave stories to be run.193 */194 protected String getStoryPath() {195 return (StringUtils.isEmpty(storyFolder)) ? storyNamePattern : storyFolder + "/" + storyNamePattern;196 }197 /**198 * Define the folder on the class path where the stories should be found199 */200 public void findStoriesIn(String storyFolder) {201 this.storyFolder = storyFolder;202 }203 public void useFormats(Format... formats) {204 this.formats = Arrays.asList(formats);205 }206 public void findStoriesCalled(String storyNames) {207 Set<String> storyPathElements = new StoryPathFinder(getEnvironmentVariables(), storyNames).findAllElements();208 storyNamePattern = Joiner.on(";").join(storyPathElements);209 }210 private String storyFilter;211 public void matchStories(String storyFilter) {212 this.storyFilter = storyFilter;213 }214 public String getStoryFilter() {215 return storyFilter;216 }217 /**218 * Use this to override the default ThucydidesWebdriverIntegration configuration - for testing purposes only.219 */220 protected void setSystemConfiguration(net.thucydides.core.webdriver.DriverConfiguration systemConfiguration) {221 this.systemConfiguration = systemConfiguration;...

Full Screen

Full Screen

Source:WhenRunningJBehaveStoriesWithSuccess.java Github

copy

Full Screen

...108 run(stories);109 }110 @Test111 public void a_test_running_a_slow_story_should_not_fail_if_it_does_not_timeout() {112 systemConfiguration.getEnvironmentVariables().setProperty("story.timeout.in.secs", "100");113 SerenityStories stories = new ABehaviorContainingSlowTests(systemConfiguration);114 runStories(stories);115 }116 final class AnotherStorySample extends SerenityStories {117 public AnotherStorySample() {118 super(environmentVariables);119 findStoriesCalled("stories/samples/*Behavior.story");120 }121 }122 @Test123 public void test_should_count_not_merge_main_step() {124 // Given125 SerenityStories story = new ASingleStoryWithGivenSample();126 // When...

Full Screen

Full Screen

Source:WhenRunningASelectionOfJBehaveStories.java Github

copy

Full Screen

...58 }59 @Test60 public void environment_specific_stories_should_be_executed_if_the_corresponding_environment_variable_is_set() {61 // Given62 systemConfiguration.getEnvironmentVariables().setProperty("metafilter", "+environment uat");63 SerenityStories uatStory = new ASampleBehaviorForUatOnly(systemConfiguration);64// uatStory.setSystemConfiguration(systemConfiguration);65 uatStory.setEnvironmentVariables(environmentVariables);66 // When67 run(uatStory);68 // Then69 List<TestOutcome> outcomes = loadTestOutcomes();70 assertThat(outcomes.size(), is(1));71 assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS));72 }73 @Test74 public void should_be_possible_to_define_multiple_metafilters() {75 // Given76 systemConfiguration.getEnvironmentVariables().setProperty("metafilter", "+environment uat, +speed fast");77 SerenityStories allStories = new SerenityStories(systemConfiguration);78 allStories.setSystemConfiguration(systemConfiguration);79 allStories.setEnvironmentVariables(environmentVariables);80 // When81 run(allStories);82 // Then83 List<TestOutcome> outcomes = loadTestOutcomes();84 assertThat(excludeSkippedAndIgnored(outcomes).size(), is(4));85 }86 @Test87 public void should_be_possible_to_define_metafilters_in_annotations() {88 // Given89 SerenityStories allStories = new WithAnAnnotatedMetafilter();90 allStories.setSystemConfiguration(systemConfiguration);91 allStories.setEnvironmentVariables(environmentVariables);92 // When93 run(allStories);94 // Then95 List<TestOutcome> outcomes = loadTestOutcomes();96 assertThat(excludeSkippedAndIgnored(outcomes).size(), is(2));97 }98 @Test99 public void system_property_metafilters_should_override_annotations() {100 // Given101 systemConfiguration.getEnvironmentVariables().setProperty("metafilter", "+environment uat, +speed fast");102 SerenityStories allStories = new WithAnAnnotatedMetafilter();103 allStories.setSystemConfiguration(systemConfiguration);104 allStories.setEnvironmentVariables(environmentVariables);105 // When106 run(allStories);107 // Then108 List<TestOutcome> outcomes = loadTestOutcomes();109 assertThat(excludeSkippedAndIgnored(outcomes).size(), is(4));110 }111 @Test112 public void should_be_possible_to_define_groovy_metafilters() {113 // Given114 systemConfiguration.getEnvironmentVariables().setProperty("webdriver.driver", "htmlunit");115 systemConfiguration.getEnvironmentVariables().setProperty("metafilter", "groovy:('a'=='b')");116 SerenityStories allStories = new SerenityStories(systemConfiguration);117 allStories.setSystemConfiguration(systemConfiguration);118 allStories.setEnvironmentVariables(environmentVariables);119 // When120 run(allStories);121 // Then122 List<TestOutcome> outcomes = loadTestOutcomes();123 assertThat(excludeSkippedAndIgnored(outcomes).size(), is(0));124 }125 @Test126 public void environment_specific_stories_should_not_be_executed_if_a_filter_excludes_it() {127 systemConfiguration.getEnvironmentVariables().setProperty("metafilter", "-environment uat");128 // Given129 SerenityStories uatStory = new ASampleBehaviorForUatOnly(systemConfiguration);130 // When131 run(uatStory);132 // Then133 List<TestOutcome> outcomes = loadTestOutcomes();134 assertThat(outcomes.size(), is(0));135 }136 final class AnotherStorySample extends SerenityStories {137 public AnotherStorySample() {138 super(environmentVariables);139 findStoriesCalled("stories/samples/*Behavior.story");140 }141 }...

Full Screen

Full Screen

Source:RunTestSuite.java Github

copy

Full Screen

...89 logger.info(" SCREEN:");90 logger.info(" WIDTH: " + driver.manage().window().getSize().width);91 logger.info(" HEIGHT: " + driver.manage().window().getSize().height);92 logger.info(" ENVARS: ");93 for(String key : getSystemConfiguration().getEnvironmentVariables().getKeys()){94 logger.info(" " + key + ": " + getSystemConfiguration().getEnvironmentVariables().getProperty(key));95 }96 }97 @AfterStories98 public void afterStories() {99 }100 @BeforeScenario101 public void setupProfile() throws IOException, URISyntaxException, InterruptedException {102 // all code for setting up Browser profile belongs in here - for example:103 /*104 * org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();105 * proxy.setHttpProxy("localhost:3128"); FirefoxProfile profile = new106 * FirefoxProfile(); profile.setPreference("network.proxy.type", 1);107 * profile.setPreference("network.proxy.http", "localhost");108 * profile.setPreference("network.proxy.http_port", 3128);...

Full Screen

Full Screen

Source:WhenRunningJBehaveStoriesWithIgnored.java Github

copy

Full Screen

...21 run(stories);22 }23 @Test24 public void a_test_running_a_failing_story_should_not_fail_if_ignore_failures_in_stories_is_set_to_true() {25 systemConfiguration.getEnvironmentVariables().setProperty("ignore.failures.in.stories", "true");26 SerenityStories stories = new AFailingBehavior();27 stories.setSystemConfiguration(systemConfiguration);28 runStories(stories);29 }30 @Test31 public void should_mark_scenarios_with_failing_assumption_as_skipped() {32 // Given33 SerenityStories stories = new ABehaviorWithAFailingAssumption(environmentVariables);34 // When35 run(stories);36 // Then37 List<TestOutcome> outcomes = loadTestOutcomes();38 assertThat(outcomes.size(), is(2));39 assertThat(outcomes.get(0).getResult(), is(IGNORED));...

Full Screen

Full Screen

Source:AcceptanceTestSuite.java Github

copy

Full Screen

...9 private String storiesToRun;10 public AcceptanceTestSuite() {}11 @Override12 public List<String> storyPaths() {13 storiesToRun = getEnvironmentVariables().getProperty(STORIES_PATTERN_KEY);14 System.out.println("stories to run" + storiesToRun);15 if(storiesToRun == null) {16 return super.storyPaths();17 }18 else {19 findStoriesCalled(storiesToRun);20 return super.storyPaths();21 }22 }23}...

Full Screen

Full Screen

Source:runnerClass.java Github

copy

Full Screen

...7 public runnerClass() {8 9 findStoriesCalled("*.story");10 11 EnvironmentVariables envVar = getEnvironmentVariables();12 commonUtilities.setEnvironment(envVar);13 14 String platform = commonUtilities.getEnvironmetVariable("PLATFORM");15 16 if (platform.equalsIgnoreCase("mobile")) {17 commonUtilities.startAppiumServer();18 }19 20 21}22 }...

Full Screen

Full Screen

getEnvironmentVariables

Using AI Code Generation

copy

Full Screen

1public class SerenityStories extends SerenityStory {2 public Configuration configuration() {3 return super.configuration()4 .useStoryReporterBuilder(new StoryReporterBuilder()5 .withFormats(Format.CONSOLE, Format.HTML)6 .withRelativeDirectory("target/site/serenity")7 .withViewResources(new ViewResource("/custom-reports.css"))8 .withDefaultFormats()9 .withFormats(Format.HTML, Format.XML));10 }11 public InjectableStepsFactory stepsFactory() {12 return new InstanceStepsFactory(configuration(), new MySteps());13 }14 public List<String> storyPaths() {15 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");16 }17 public List<CandidateSteps> candidateSteps() {18 return new InstanceStepsFactory(configuration(), new MySteps()).createCandidateSteps();19 }20 public List<String> metaFilters() {21 return Arrays.asList("-skip");22 }23 public List<String> storyPaths() {24 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");25 }26 public List<CandidateSteps> candidateSteps() {27 return new InstanceStepsFactory(configuration(), new MySteps()).createCandidateSteps();28 }29 public List<String> metaFilters() {30 return Arrays.asList("-skip");31 }32 public InjectableStepsFactory stepsFactory() {33 return new InstanceStepsFactory(configuration(), new MySteps());34 }35 public Configuration configuration() {36 return super.configuration()37 .useStoryReporterBuilder(new StoryReporterBuilder()38 .withFormats(Format.CONSOLE, Format.HTML)39 .withRelativeDirectory("target/site/serenity")40 .withViewResources(new ViewResource("/custom-reports.css"))41 .withDefaultFormats()42 .withFormats(Format.HTML, Format.XML));43 }44 public List<String> storyPaths() {45 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");46 }47 public List<CandidateSteps> candidateSteps() {48 return new InstanceStepsFactory(configuration(), new MySteps()).createCandidateSteps();49 }50 public List<String> metaFilters() {51 return Arrays.asList("-skip");52 }

Full Screen

Full Screen

getEnvironmentVariables

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.jbehave.SerenityStories;2import org.jbehave.core.configuration.Configuration;3import org.jbehave.core.configuration.MostUsefulConfiguration;4import org.jbehave.core.configuration.ParameterControls;5import org.jbehave.core.configuration.spring.SpringStoryControls;6import org.jbehave.core.embedder.Embedder;7import org.jbehave.core.embedder.MetaFilter;8import org.jbehave.core.embedder.StoryControls;9import org.jbehave.core.embedder.StoryManager;10import org.jbehave.core.failures.BatchFailures;11import org.jbehave.core.i18n.LocalizedKeywords;12import org.jbehave.core.io.LoadFromClasspath;13import org.jbehave.core.io.StoryLoader;14import org.jbehave.core.io.UnderscoredCamelCaseResolver;15import org.jbehave.core.junit.JUnitStory;16import org.jbehave.core.junit.JUnitStoryReporter;17import org.jbehave.core.junit.JUnitStoryReporterBuilder;18import org.jbehave.core.junit.JUnitStories;19import org.jbehave.core.junit.JUnitStoryRunner;20import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner;21import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.ConfigurableEmbedder;22import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.ConfigurableEmbedderBuilder;23import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.ConfigurableStoryReporterBuilder;24import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.StoryLoaderBuilder;25import org.jbehave.core.model.ExamplesTableFactory;26import org.jbehave.core.model.Story;27import org.jbehave.core.parsers.RegexStoryParser;28import org.jbehave.core.parsers.StoryParser;29import org.jbehave.core.reporters.FilePrintStreamFactory.ResolveToSimpleName;30import org.jbehave.core.reporters.Format;31import org.jbehave.core.reporters.StoryReporterBuilder;32import org.jbehave.core.steps.CandidateSteps;33import org.jbehave.core.steps.ParameterConverters;34import org.jbehave.core.steps.ParameterConverters.EnumConverter;35import org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter;36import org.jbehave.core.steps.ParameterConverters.ParameterNotFound;37import org.jbehave.core.steps.ParameterConverters.ParameterNotFoundConverter;38import org.jbehave.core.steps

Full Screen

Full Screen

getEnvironmentVariables

Using AI Code Generation

copy

Full Screen

1public class SerenityStories extends JUnitStory {2 public Configuration configuration() {3 Properties systemProperties = System.getProperties();4 Properties environmentVariables = getEnvironmentVariables().getProperties();5 Configuration configuration = super.configuration();6 configuration.useStoryLoader(new LoadFromClasspath(this.getClass()));7 configuration.useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass())));8 return configuration;9 }10}11public class SerenityStories extends JUnitStory {12 public Configuration configuration() {13 Properties systemProperties = System.getProperties();14 Properties environmentVariables = getEnvironmentVariables().getProperties();15 Configuration configuration = super.configuration();16 configuration.useStoryLoader(new LoadFromClasspath(this.getClass()));17 configuration.useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass())));18 return configuration;19 }20}21public class SerenityStories extends JUnitStory {22 public Configuration configuration() {23 Properties systemProperties = System.getProperties();24 Properties environmentVariables = getEnvironmentVariables().getProperties();25 Configuration configuration = super.configuration();26 configuration.useStoryLoader(new LoadFromClasspath(this.getClass()));27 configuration.useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass())));28 return configuration;29 }30}31public class SerenityStories extends JUnitStory {32 public Configuration configuration() {33 Properties systemProperties = System.getProperties();34 Properties environmentVariables = getEnvironmentVariables().getProperties();35 Configuration configuration = super.configuration();36 configuration.useStoryLoader(new LoadFromClasspath(this.getClass()));37 configuration.useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(this.getClass())));38 return configuration;39 }40}41public class SerenityStories extends JUnitStory {42 public Configuration configuration() {43 Properties systemProperties = System.getProperties();

Full Screen

Full Screen

getEnvironmentVariables

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.jbehave.SerenityStories;2import net.thucydides.core.util.EnvironmentVariables;3import net.thucydides.core.util.SystemEnvironmentVariables;4import org.jbehave.core.configuration.Configuration;5import org.jbehave.core.configuration.MostUsefulConfiguration;6import org.jbehave.core.configuration.spring.SpringStoryControls;7import org.jbehave.core.embedder.Embedder;8import org.jbehave.core.embedder.EmbedderControls;9import org.jbehave.core.embedder.MetaFilter;10import org.jbehave.core.embedder.MetaFilter.AllowMetaFilter;11import org.jbehave.core.embedder.MetaFilter.MetaByProperty;12import org.jbehave.core.embedder.MetaFilter.MetaByPropertyFilter;13import org.jbehave.core.embedder.MetaFilter.MetaByTag;14import org.jbehave.core.embedder.MetaFilter.MetaByTagFilter;15import org.jbehave.core.embedder.MetaFilter.MetaByTags;16import org.jbehave.core.embedder.MetaFilter.MetaByTagsFilter;17import org.jbehave.core.embedder.MetaFilter.MetaByTagsInMap;18import org.jbehave.core.embedder.MetaFilter.MetaByTagsInMapFilter;19import org.jbehave.core.embedder.MetaFilter.MetaByTagsInMapWithNoFilter;20import org.jbehave.core.embedder.MetaFilter.MetaByTagsInMapWithNoFilterFilter;21import org.jbehave.core.embedder.MetaFilter.MetaByTagsWithNoFilter;22import org.jbehave.core.embedder.MetaFilter.MetaByTagsWithNoFilterFilter;23import org.jbehave.core.embedder.MetaFilter.MetaByTagsWithNoMeta;24import org.jbehave.core.embedder.MetaFilter.MetaByTagsWithNoMeta

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful