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

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

copy

Full Screen

...49 protected SerenityStories(EnvironmentVariables environmentVariables) {50 this.environmentVariables = environmentVariables.copy();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;222 }223 protected void setEnvironmentVariables(EnvironmentVariables environmentVariables) {224 this.environmentVariables = environmentVariables;225 }226 public net.thucydides.core.webdriver.DriverConfiguration getSystemConfiguration() {227 if (systemConfiguration == null) {228 systemConfiguration = WebDriverInjectors.getInjector().getInstance(net.thucydides.core.webdriver.DriverConfiguration.class);229 }230 return systemConfiguration;231 }232 protected void useDriver(String driver) {233 getSystemConfiguration().setIfUndefined(ThucydidesSystemProperty.DRIVER.getPropertyName(), driver);234 }...

Full Screen

Full Screen
copy

Full Screen

...60 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);...

Full Screen

Full Screen
copy

Full Screen

...19 @Test20 public void should_run_before_story_methods() {21 /​/​ Given22 SerenityStories stories = new AStorySample("aPassingBehavior.story");23 stories.setSystemConfiguration(systemConfiguration);24 FixtureMethods.beforeStoryCalledCount = 0;25 /​/​ When26 run(stories);27 /​/​ Then28 assertThat(FixtureMethods.beforeStoryCalledCount, is(1));29 }30 @Test31 public void should_run_before_scenario_methods() {32 /​/​ Given33 SerenityStories stories = new AStorySample("aPassingBehaviorWithSeveralScenarios.story");34 stories.setSystemConfiguration(systemConfiguration);35 FixtureMethods.beforeScenarioCalledCount = 0;36 /​/​ When37 run(stories);38 /​/​ Then39 assertThat(FixtureMethods.beforeScenarioCalledCount, is(2));40 }41 @Test42 public void should_run_before_scenario_methods_for_lots_of_stories() {43 /​/​ Given44 SerenityStories stories = new AStorySample("*PassingBehavior.story");45 stories.setSystemConfiguration(systemConfiguration);46 FixtureMethods.beforeScenarioCalledCount = 0;47 /​/​ When48 run(stories);49 /​/​ Then50 assertThat(FixtureMethods.beforeScenarioCalledCount, is(6));51 }52 final class AnotherStorySample extends SerenityStories {53 public AnotherStorySample() {54 super(environmentVariables);55 findStoriesCalled("stories/​samples/​*Behavior.story");56 }57 }58 @Test59 public void should_not_run_given_stories_separately() {...

Full Screen

Full Screen
copy

Full Screen

...53 }54 @Test55 public void a_test_running_a_failing_story_should_fail() {56 SerenityStories stories = newStory("aFailingBehavior.story");57 stories.setSystemConfiguration(systemConfiguration);58 runStories(stories);59 List<TestOutcome> outcomes = loadTestOutcomes();60 assertThat(outcomes.size(), is(1));61 assertThat(outcomes.get(0).getResult(), is(TestResult.FAILURE));62 }63}...

Full Screen

Full Screen
copy

Full Screen

...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));40 assertThat(outcomes.get(1).getResult(), is(SUCCESS));41 }...

Full Screen

Full Screen
copy

Full Screen

...5import static org.jbehave.core.reporters.Format.TXT;6import static org.jbehave.core.reporters.Format.XML;7public class APassingWebTestSampleWithThucydidesPropertiesDefined extends SerenityStories {8 public APassingWebTestSampleWithThucydidesPropertiesDefined(DriverConfiguration systemConfiguration) {9 setSystemConfiguration(systemConfiguration);10 findStoriesCalled("aBehaviorWithSeleniumUsingADifferentBrowser.story");11 useFormats(TXT, XML, HTML);12 runSerenity().withProperty(ThucydidesSystemProperty.DRIVER).setTo("htmlunit");13 runSerenity().withProperty(ThucydidesSystemProperty.WEBDRIVER_BASE_URL).setTo("some-base-url");14 runSerenity().withProperty(ThucydidesSystemProperty.THUCYDIDES_TIMEOUT).setTo(5);15 runSerenity().withProperty(ThucydidesSystemProperty.THUCYDIDES_USE_UNIQUE_BROWSER).setTo(true);16 }17}...

Full Screen

Full Screen
copy

Full Screen

...3import net.thucydides.core.webdriver.DriverConfiguration;4public class AStorySample extends SerenityStories {5 public AStorySample(String storyName, DriverConfiguration configuration, EnvironmentVariables environmentVariables) {6 this.setEnvironmentVariables(environmentVariables);7 setSystemConfiguration(configuration);8 findStoriesCalled(storyName);9 }10}...

Full Screen

Full Screen

setSystemConfiguration

Using AI Code Generation

copy

Full Screen

1SerenityStories serenityStories = new SerenityStories();2serenityStories.setSystemConfiguration();3SerenityStories serenityStories = new SerenityStories();4serenityStories.setSystemConfiguration();5SerenityStories serenityStories = new SerenityStories();6serenityStories.setSystemConfiguration();7SerenityStories serenityStories = new SerenityStories();8serenityStories.setSystemConfiguration();9SerenityStories serenityStories = new SerenityStories();10serenityStories.setSystemConfiguration();11SerenityStories serenityStories = new SerenityStories();12serenityStories.setSystemConfiguration();13SerenityStories serenityStories = new SerenityStories();14serenityStories.setSystemConfiguration();15SerenityStories serenityStories = new SerenityStories();16serenityStories.setSystemConfiguration();17SerenityStories serenityStories = new SerenityStories();18serenityStories.setSystemConfiguration();19SerenityStories serenityStories = new SerenityStories();20serenityStories.setSystemConfiguration();

Full Screen

Full Screen

setSystemConfiguration

Using AI Code Generation

copy

Full Screen

1public class SerenityStories extends SerenityStory {2 public void setSystemConfiguration() {3 System.setProperty("webdriver.driver", "chrome");4 System.setProperty("chrome.switches", "--incognito");5 }6}

Full Screen

Full Screen

setSystemConfiguration

Using AI Code Generation

copy

Full Screen

1public class JBehaveTest extends SerenityStories {2 public JBehaveTest() {3 super();4 setSystemConfiguration("serenity.jira.username", "abc");5 setSystemConfiguration("serenity.jira.password", "abc");6 setSystemConfiguration("serenity.jira.project", "ABC");7 setSystemConfiguration("serenity.requirement.types", "Epic,Story,Theme,Defect");8 setSystemConfiguration("serenity.jira.requirement.tracking", "true");9 setSystemConfiguration("serenity.jira.requirement.tracking.level", "STORY");10 setSystemConfiguration("serenity.jira.requirement.tracking.type", "Epic");11 setSystemConfiguration("serenity.jira.requirement.tracking.filter", "project=ABC");12 setSystemConfiguration("serenity.jira.requirement.tracking.requirement.fields", "summary,description");13 setSystemConfiguration("serenity.jira.requirement.tracking.story.fields", "summary,description");14 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is blocked by");15 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "blocks");16 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is duplicated by");17 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "duplicates");18 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is related to");19 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "relates");20 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is required by");21 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "requires");22 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is tested by");23 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "tests");24 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is implemented by");25 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "implements");26 setSystemConfiguration("serenity.jira.requirement.tracking.story.link", "is a sub-task of");27 setSystemConfiguration("serenity.jira

Full Screen

Full Screen

setSystemConfiguration

Using AI Code Generation

copy

Full Screen

1public class SerenityStories extends SerenityStory {2 public SerenityStories() {3 setSystemConfiguration("webdriver.driver", "chrome");4 run();5 }6}7public class SerenityStories extends SerenityStory {8 public SerenityStories() {9 setSystemConfiguration("webdriver.driver", "chrome");10 run();11 }12}13public class SerenityStories extends SerenityStory {14 public SerenityStories() {15 setSystemConfiguration("webdriver.driver", "chrome");16 run();17 }18}

Full Screen

Full Screen

setSystemConfiguration

Using AI Code Generation

copy

Full Screen

1public class MyStory extends SerenityStories {2 public MyStory() {3 super();4 setSystemConfiguration("my.property", "value");5 }6}

Full Screen

Full Screen

setSystemConfiguration

Using AI Code Generation

copy

Full Screen

1 SerenityStories stories = new SerenityStories();2 stories.setSystemConfiguration(System.getProperties());3 SerenityStory story = new SerenityStory();4 story.setSystemConfiguration(System.getProperties());5 SerenityStory story = new SerenityStory();6 story.setSystemConfiguration(System.getProperties());7 SerenityStory story = new SerenityStory();8 story.setSystemConfiguration(System.getProperties());9 SerenityStory story = new SerenityStory();10 story.setSystemConfiguration(System.getProperties());11 SerenityStory story = new SerenityStory();12 story.setSystemConfiguration(System.getProperties());13 SerenityStory story = new SerenityStory();14 story.setSystemConfiguration(System.getProperties());15 SerenityStory story = new SerenityStory();

Full Screen

Full Screen

StackOverFlow community discussions

Questions
Discussion

Getting &quot;java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector&quot; trying to run Serenity JBheave

How do I run web tests in parallel in Selenium WebDriver, JBehave &amp; Serenity BDD framework?

Before/After Scenario not working in jbehave serenity BDD

serenity configuration via pom.xml

In my testNG integration tests can I use @factory more than once (using Jenkins and Maven for my builds)?

Serenity BDD with JBehave loading duplicate requirements

Serenity BDD: Use JBehave steps in dependency for local stories

How to resolve ambiguous delegation when using Serenity-BDD with Rest Assured

Generate serenity-jbehave-archetype and build faild on mvn Verify

Unable to use androiddriver or iosdriver in Jbehave based serenity-bdd framework?

Add dependency to pom.xml:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-engine</artifactId>
    <version>1.2.0</version>
</dependency>
https://stackoverflow.com/questions/51308551/getting-java-lang-noclassdeffounderror-org-junit-platform-engine-discoverysele

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

Six Agile Team Behaviors to Consider

Are members of agile teams different from members of other teams? Both yes and no. Yes, because some of the behaviors we observe in agile teams are more distinct than in non-agile teams. And no, because we are talking about individuals!

Pair testing strategy in an Agile environment

Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.

Scala Testing: A Comprehensive Guide

Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.

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