How to use ParameterizedTestsOutcomeAggregator class of net.serenitybdd.junit.runners package

Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.ParameterizedTestsOutcomeAggregator

Source:WhenRunningADataDrivenTestScenario.java Github

copy

Full Screen

1package net.serenitybdd.junit.runners.integration;2import net.serenitybdd.junit.runners.ParameterizedTestsOutcomeAggregator;3import net.serenitybdd.junit.runners.SerenityParameterizedRunner;4import net.serenitybdd.junit.runners.SerenityRunner;5import net.thucydides.core.ThucydidesSystemProperty;6import net.thucydides.core.annotations.Managed;7import net.thucydides.core.annotations.ManagedPages;8import net.thucydides.core.annotations.Steps;9import net.thucydides.core.annotations.WithTag;10import net.thucydides.core.batches.BatchManager;11import net.thucydides.core.batches.BatchManagerProvider;12import net.thucydides.core.configuration.SystemPropertiesConfiguration;13import net.thucydides.core.configuration.WebDriverConfiguration;14import net.thucydides.core.model.TestOutcome;15import net.thucydides.core.model.TestResult;16import net.thucydides.core.model.TestStep;17import net.thucydides.core.pages.Pages;18import net.thucydides.core.util.EnvironmentVariables;19import net.thucydides.core.util.MockEnvironmentVariables;20import net.thucydides.core.webdriver.Configuration;21import net.thucydides.core.webdriver.DriverConfiguration;22import net.thucydides.core.webdriver.WebDriverFactory;23import net.thucydides.junit.annotations.Concurrent;24import net.thucydides.junit.annotations.TestData;25import net.thucydides.junit.rules.QuietThucydidesLoggingRule;26import net.thucydides.junit.rules.SaveWebdriverSystemPropertiesRule;27import net.thucydides.samples.*;28import org.apache.commons.io.FileUtils;29import org.hamcrest.Description;30import org.hamcrest.Matcher;31import org.hamcrest.TypeSafeMatcher;32import org.junit.Before;33import org.junit.Rule;34import org.junit.Test;35import org.junit.rules.TemporaryFolder;36import org.junit.runner.RunWith;37import org.junit.runner.notification.RunNotifier;38import org.mockito.MockitoAnnotations;39import org.openqa.selenium.WebDriver;40import java.io.File;41import java.io.FilenameFilter;42import java.io.IOException;43import java.nio.file.Paths;44import java.util.ArrayList;45import java.util.Arrays;46import java.util.Collection;47import java.util.List;48import static net.thucydides.core.steps.stepdata.StepData.withTestDataFrom;49import static org.hamcrest.MatcherAssert.assertThat;50import static org.hamcrest.Matchers.containsString;51import static org.hamcrest.Matchers.is;52public class WhenRunningADataDrivenTestScenario {53 @Rule54 public TemporaryFolder tempFolder = new TemporaryFolder();55 @Rule56 public SaveWebdriverSystemPropertiesRule saveWebdriverSystemPropertiesRule = new SaveWebdriverSystemPropertiesRule();57 @Rule58 public QuietThucydidesLoggingRule quietThucydidesLoggingRule = new QuietThucydidesLoggingRule();59 MockEnvironmentVariables environmentVariables;60 Configuration configuration;61 @Before62 public void initMocks() {63 MockitoAnnotations.initMocks(this);64 environmentVariables = new MockEnvironmentVariables();65 configuration = new SystemPropertiesConfiguration(environmentVariables);66 }67 @Test68 public void a_data_driven_test_driver_should_run_one_test_per_row_of_data() throws Throwable {69 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenScenario.class);70 runner.run(new RunNotifier());71 List<TestOutcome> executedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).getTestOutcomesForAllParameterSets();72 assertThat(executedScenarios.size(), is(36));73 }74 @Test75 public void manual_data_driven_tests_should_be_allowed() throws Throwable {76 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(AddDifferentSortsOfTodos.class);77 runner.run(new RunNotifier());78 List<TestOutcome> executedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).getTestOutcomesForAllParameterSets();79 assertThat(executedScenarios.size(), is(4));80 }81 @Test82 public void a_data_driven_test_driver_should_aggregate_test_outcomes() throws Throwable {83 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenScenario.class);84 runner.run(new RunNotifier());85 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();86 assertThat(aggregatedScenarios.size(), is(3));87 assertThat(aggregatedScenarios.get(0).getStepCount(), is(12));88 assertThat(aggregatedScenarios.get(1).getStepCount(), is(12));89 }90 @Test91 public void a_data_driven_test_driver_should_record_a_sample_scenario() throws Throwable {92 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenScenario.class);93 runner.run(new RunNotifier());94 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();95 assertThat(aggregatedScenarios.get(0).getDataDrivenSampleScenario(), containsString("Step with parameters: <Parameter 1>, <Parameter 2>\n" +96 "Step that succeeds\n" +97 "Another step that succeeds"));98 }99 @Test100 public void a_data_driven_test_driver_should_record_a_table_of_example() throws Throwable {101 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleSingleDataDrivenScenario.class);102 runner.run(new RunNotifier());103 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();104 assertThat(aggregatedScenarios.size(), is(1));105 assertThat(aggregatedScenarios.get(0).getStepCount(), is(15));106 }107 @Test108 public void a_data_driven_test_with_a_failing_assumption_should_be_ignored() throws Throwable {109 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleSingleDataDrivenScenarioWithFailingAssumption.class);110 runner.run(new RunNotifier());111 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();112 assertThat(aggregatedScenarios.size(), is(1));113 assertThat(aggregatedScenarios.get(0).getStepCount(), is(15));114 for (TestStep step : aggregatedScenarios.get(0).getTestSteps()) {115 assertThat(step.getResult(), is(TestResult.IGNORED));116 }117 }118 @Test119 public void a_data_driven_test_driver_should_aggregate_test_outcomes_without_steps() throws Throwable {120 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SimpleSuccessfulParametrizedTestSample.class);121 runner.run(new RunNotifier());122 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();123 assertThat(aggregatedScenarios.size(), is(2));124 assertThat(aggregatedScenarios.get(0).getStepCount(), is(3));125 assertThat(aggregatedScenarios.get(1).getStepCount(), is(3));126 }127 @Test128 public void data_driven_tests_should_pass_even_if_no_steps_are_called() throws Throwable {129 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SimpleSuccessfulParametrizedTestSample.class);130 runner.run(new RunNotifier());131 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();132 assertThat(aggregatedScenarios.get(0).getResult(), is(TestResult.SUCCESS));133 assertThat(aggregatedScenarios.get(1).getResult(), is(TestResult.SUCCESS));134 }135 @Test136 public void an_ignored_data_driven_test_should_have_result_status_as_ignored() throws Throwable {137 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenIgnoredScenario.class);138 runner.run(new RunNotifier());139 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();140 assertThat(aggregatedScenarios.size(), is(1));141 assertThat(aggregatedScenarios.get(0).getResult(), is(TestResult.IGNORED));142 }143 @Test144 public void an_ignored_data_driven_test_should_have_a_step_for_each_row() throws Throwable {145 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenIgnoredScenario.class);146 runner.run(new RunNotifier());147 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();148 assertThat(aggregatedScenarios.size(), is(1));149 assertThat(aggregatedScenarios.get(0).getTestSteps().size(), is(10));150 }151 @Test152 public void a_pending_data_driven_test_should_have_result_status_as_pending() throws Throwable {153 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenPendingScenario.class);154 runner.run(new RunNotifier());155 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();156 assertThat(aggregatedScenarios.size(), is(1));157 assertThat(aggregatedScenarios.get(0).getResult(), is(TestResult.PENDING));158 }159 @Test160 public void a_pending_data_driven_test_should_have_a_test_step_for_each_row() throws Throwable {161 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenPendingScenario.class);162 runner.run(new RunNotifier());163 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();164 assertThat(aggregatedScenarios.size(), is(1));165 assertThat(aggregatedScenarios.get(0).getTestSteps().size(), is(10));166 }167 @Test168 public void a_data_driven_test_should_also_be_able_to_use_data_from_a_CSV_file() throws Throwable {169 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleCSVDataDrivenScenario.class);170 runner.run(new RunNotifier());171 List<TestOutcome> executedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).getTestOutcomesForAllParameterSets();172 assertThat(executedScenarios.size(), is(24));173 }174 @Test175 public void a_separate_json_report_should_be_generated_for_each_scenario() throws Throwable {176 File outputDirectory = tempFolder.newFolder("thucydides");177 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),178 outputDirectory.getAbsolutePath());179 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleDataDrivenScenario.class);180 runner.run(new RunNotifier());181 File[] reports = reload(outputDirectory).listFiles(new JSONFileFilter());182 assertThat(reports.length, is(3));183 }184 @Test185 public void a_separate_json_report_should_be_generated_for_each_scenario_when_using_data_from_a_CSV_file() throws Throwable {186 File outputDirectory = tempFolder.newFolder("thucydides");187 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),188 outputDirectory.getAbsolutePath());189 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleCSVDataDrivenScenario.class);190 runner.run(new RunNotifier());191 File[] reports = reload(outputDirectory).listFiles(new JSONFileFilter());192 assertThat(reports.length, is(2));193 }194 @Test195 public void json_report_contents_should_reflect_the_test_data_from_the_csv_file() throws Throwable {196 File outputDirectory = tempFolder.newFolder("thucydides");197 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),198 outputDirectory.getAbsolutePath());199 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleCSVDataDrivenScenario.class);200 runner.run(new RunNotifier());201 List<String> reportContents = contentsOf(reload(outputDirectory).listFiles(new JSONFileFilter()));202 assertThat(reportContents, hasItemContainsString("Jack Black"));203 assertThat(reportContents, hasItemContainsString("Joe Smith"));204 }205 private Matcher<? super List<String>> hasItemContainsString(String expectedValue) {206 return new HasItemContainsString(expectedValue);207 }208 private static class HasItemContainsString extends TypeSafeMatcher<List<String>> {209 private final String expectedValue;210 private HasItemContainsString(String expectedValue) {211 this.expectedValue = expectedValue;212 }213 @Override214 protected boolean matchesSafely(List<String> values) {215 return values.stream()216 .anyMatch(value -> value.contains(expectedValue));217 }218 public void describeTo(Description description) {219 description.appendText("Expecting a list containing a string that contains ").appendValue(expectedValue);220 }221 }222 @Test223 public void when_test_data_is_provided_for_a_step_a_single_test_should_be_executed() throws Throwable {224 File outputDirectory = tempFolder.newFolder("thucydides");225 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),226 outputDirectory.getAbsolutePath());227 SerenityRunner runner = getNormalTestRunnerUsing(SamplePassingScenarioWithTestSpecificData.class);228 runner.run(new RunNotifier());229 List reportContents = contentsOf(reload(outputDirectory).listFiles(new JSONFileFilter()));230 assertThat(reportContents.size(), is(1));231 }232 @Test233 public void when_a_step_fails_for_a_row_the_other_rows_should_be_executed() throws Throwable {234 File outputDirectory = tempFolder.newFolder("thucydides");235 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),236 outputDirectory.getAbsolutePath());237 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithTestSpecificDataAndAFailingTestSample.class);238 runner.run(new RunNotifier());239 List<TestOutcome> executedSteps = runner.getTestOutcomes();240 assertThat(executedSteps.size(), is(1));241 TestOutcome testOutcome1 = executedSteps.get(0);242 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();243 assertThat(dataDrivenSteps.size(), is(12));244 }245 @Test246 public void when_a_step_is_skipped_for_a_row_the_other_rows_should_be_executed() throws Throwable {247 File outputDirectory = tempFolder.newFolder("thucydides");248 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),249 outputDirectory.getAbsolutePath());250 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithTestSpecificDataAndAFailingTestSample.class);251 runner.run(new RunNotifier());252 List<TestOutcome> executedSteps = runner.getTestOutcomes();253 assertThat(executedSteps.size(), is(1));254 TestOutcome testOutcome1 = executedSteps.get(0);255 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();256 assertThat(dataDrivenSteps.size(), is(12));257 }258 @Test259 public void browser_should_be_restarted_periodically_if_requested() throws Throwable {260 File outputDirectory = tempFolder.newFolder("thucydides");261 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(), outputDirectory.getAbsolutePath());262 environmentVariables.setProperty("thucydides.restart.browser.frequency", "5");263 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleSingleSessionDataDrivenScenario.class);264 runner.run(new RunNotifier());265 }266 @Test267 public void when_a_step_fails_for_a_row_the_other_rows_should_not_be_skipped() throws Throwable {268 File outputDirectory = tempFolder.newFolder("thucydides");269 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),270 outputDirectory.getAbsolutePath());271 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithTestSpecificDataAndAFailingTestSample.class);272 runner.run(new RunNotifier());273 List<TestOutcome> executedSteps = runner.getTestOutcomes();274 assertThat(executedSteps.size(), is(1));275 TestOutcome testOutcome1 = executedSteps.get(0);276 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();277 assertThat(dataDrivenSteps.size(), is(12));278 assertThat(dataDrivenSteps.get(1).getResult(), is(TestResult.FAILURE));279 assertThat(dataDrivenSteps.get(2).getResult(), is(TestResult.SUCCESS));280 }281 @Test282 public void when_a_parameterized_test_fails_outside_a_step_a_failure_should_be_recorded() throws Throwable {283 File outputDirectory = tempFolder.newFolder("thucydides");284 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),285 outputDirectory.getAbsolutePath());286 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleDataDrivenScenarioWithExternalFailure.class);287 runner.run(new RunNotifier());288 List<TestOutcome> executedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).getTestOutcomesForAllParameterSets();289 assertThat(executedScenarios.size(), is(10));290 assertThat(executedScenarios.get(0).getResult(), is(TestResult.SUCCESS));291 assertThat(executedScenarios.get(1).getResult(), is(TestResult.FAILURE));292 assertThat(executedScenarios.get(2).getResult(), is(TestResult.SUCCESS));293 }294 @Test295 public void when_a_step_fails_with_an_error_for_a_row_the_other_rows_should_be_executed() throws Throwable {296 File outputDirectory = tempFolder.newFolder("thucydides");297 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),298 outputDirectory.getAbsolutePath());299 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithTestSpecificDataAndABreakingTestSample.class);300 runner.run(new RunNotifier());301 List<TestOutcome> executedSteps = runner.getTestOutcomes();302 assertThat(executedSteps.size(), is(1));303 TestOutcome testOutcome1 = executedSteps.get(0);304 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();305 assertThat(dataDrivenSteps.size(), is(12));306 assertThat(dataDrivenSteps.get(1).getResult(), is(TestResult.ERROR));307 assertThat(dataDrivenSteps.get(2).getResult(), is(TestResult.SUCCESS));308 }309 @RunWith(SerenityRunner.class)310 public static class ScenarioWithTestSpecificDataSample {311 @Managed(driver = "htmlunit")312 public WebDriver webdriver;313 @ManagedPages(defaultUrl = "http://www.google.com")314 public Pages pages;315 @Steps316 public SampleScenarioSteps steps;317 @Test318 public void check_each_row() throws Throwable {319 withTestDataFrom("test-data/simple-data.csv").run(steps).data_driven_test_step();320 }321 }322 @RunWith(SerenityRunner.class)323 public static class ScenarioWithNestedTestSpecificDataSample {324 @Managed(driver = "htmlunit")325 public WebDriver webdriver;326 @ManagedPages(defaultUrl = "http://www.google.com")327 public Pages pages;328 @Steps329 public NestedDatadrivenSteps steps;330 @Test331 public void check_each_row() throws Throwable {332 steps.check_each_row();333 }334 }335 @RunWith(SerenityRunner.class)336 public static class ScenarioWithDeeplyNestedTestSpecificDataSample {337 @Managed(driver = "htmlunit")338 public WebDriver webdriver;339 @ManagedPages(defaultUrl = "http://www.google.com")340 public Pages pages;341 @Steps342 public NestedDatadrivenSteps steps;343 @Test344 public void happy_day_scenario() throws Throwable {345 steps.do_something();346 steps.run_data_driven_tests();347 steps.do_something_else();348 }349 }350 @RunWith(SerenityRunner.class)351 public static class ScenarioWithTestSpecificDataAndAFailingTestSample {352 @Managed(driver = "htmlunit")353 public WebDriver webdriver;354 @ManagedPages(defaultUrl = "http://www.google.com")355 public Pages pages;356 @Steps357 public SampleScenarioSteps steps;358 @Test359 public void happy_day_scenario() throws Throwable {360 withTestDataFrom("test-data/simple-data.csv").run(steps).data_driven_test_step_that_fails();361 }362 }363 @RunWith(SerenityRunner.class)364 public static class ScenarioWithTestSpecificDataAndASkippedTestSample {365 @Managed(driver = "htmlunit")366 public WebDriver webdriver;367 @ManagedPages(defaultUrl = "http://www.google.com")368 public Pages pages;369 @Steps370 public SampleScenarioSteps steps;371 @Test372 public void happy_day_scenario() throws Throwable {373 withTestDataFrom("test-data/simple-data.csv").run(steps).data_driven_test_step_that_is_skipped();374 }375 }376 @RunWith(SerenityRunner.class)377 public static class ScenarioWithTestSpecificDataAndABreakingTestSample {378 @Managed(driver = "htmlunit")379 public WebDriver webdriver;380 @ManagedPages(defaultUrl = "http://www.google.com")381 public Pages pages;382 @Steps383 public SampleScenarioSteps steps;384 @Test385 public void happy_day_scenario() throws Throwable {386 withTestDataFrom("test-data/simple-data.csv").run(steps).data_driven_test_step_that_breaks();387 }388 }389 @Test390 public void when_test_data_is_provided_for_a_step_then_a_step_should_be_reported_for_each_data_row() throws Throwable {391 File outputDirectory = tempFolder.newFolder("thucydides");392 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),393 outputDirectory.getAbsolutePath());394 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithTestSpecificDataSample.class);395 runner.run(new RunNotifier());396 List<TestOutcome> executedSteps = runner.getTestOutcomes();397 assertThat(executedSteps.size(), is(1));398 TestOutcome testOutcome1 = executedSteps.get(0);399 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();400 assertThat(dataDrivenSteps.size(), is(12));401 }402 @Test403 public void when_test_data_is_provided_for_a_nested_step_then_a_step_should_be_reported_for_each_data_row() throws Throwable {404 File outputDirectory = tempFolder.newFolder("thucydides");405 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),406 outputDirectory.getAbsolutePath());407 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithNestedTestSpecificDataSample.class);408 runner.run(new RunNotifier());409 List<TestOutcome> executedSteps = runner.getTestOutcomes();410 assertThat(executedSteps.size(), is(1));411 TestOutcome testOutcome1 = executedSteps.get(0);412 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps().get(0).getChildren();413 assertThat(dataDrivenSteps.size(), is(12));414 }415 @Test416 public void when_test_data_is_provided_for_a_deeply_nested_step_then_a_step_should_be_reported_for_each_data_row() throws Throwable {417 File outputDirectory = tempFolder.newFolder("thucydides");418 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),419 outputDirectory.getAbsolutePath());420 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithDeeplyNestedTestSpecificDataSample.class);421 runner.run(new RunNotifier());422 List<TestOutcome> executedSteps = runner.getTestOutcomes();423 assertThat(executedSteps.size(), is(1));424 TestOutcome testOutcome1 = executedSteps.get(0);425 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();426 assertThat(dataDrivenSteps.size(), is(3));427 }428 @Test429 public void test_step_data_should_appear_in_the_step_titles() throws Throwable {430 File outputDirectory = tempFolder.newFolder("thucydides");431 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),432 outputDirectory.getAbsolutePath());433 SerenityRunner runner = getNormalTestRunnerUsing(ScenarioWithTestSpecificDataSample.class);434 runner.run(new RunNotifier());435 List<TestOutcome> executedSteps = runner.getTestOutcomes();436 TestOutcome testOutcome1 = executedSteps.get(0);437 List<TestStep> dataDrivenSteps = testOutcome1.getTestSteps();438 TestStep step1 = dataDrivenSteps.get(0);439 TestStep setNameStep1 = step1.getFlattenedSteps().get(0);440 TestStep step2 = dataDrivenSteps.get(1);441 TestStep setNameStep2 = step2.getFlattenedSteps().get(0);442 assertThat(setNameStep1.getDescription(), containsString("Joe Smith"));443 assertThat(setNameStep2.getDescription(), containsString("Jack Black"));444 }445 @Test446 public void running_a_simple_parameterized_test_should_produce_an_outcome_per_data_row() throws Throwable {447 File outputDirectory = tempFolder.newFolder("thucydides");448 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),449 outputDirectory.getAbsolutePath());450 SerenityParameterizedRunner runner = getTestRunnerUsing(SimpleSuccessfulParametrizedTestSample.class);451 runner.run(new RunNotifier());452 List<String> reportContents = contentsOf(reload(outputDirectory).listFiles(new JSONFileFilter()));453 assertThat(reportContents.size(), is(2));454 }455 @Test456 public void when_the_Concurrent_annotation_is_used_tests_should_be_run_in_parallel() throws Throwable {457 File outputDirectory = tempFolder.newFolder("thucydides");458 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),459 outputDirectory.getAbsolutePath());460 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleParallelDataDrivenScenario.class);461 runner.run(new RunNotifier());462 List<String> reportContents = contentsOf(reload(outputDirectory).listFiles(new JSONFileFilter()));463 assertThat(reportContents, hasItemContainsString("Step with parameters: a, 1"));464 assertThat(reportContents, hasItemContainsString("Step with parameters: b, 2"));465 assertThat(reportContents, hasItemContainsString("Step with parameters: c, 3"));466 }467 @Test468 public void the_Concurrent_annotation_indicates_that_tests_should_be_run_in_parallel() throws Throwable {469 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleParallelDataDrivenScenario.class);470 assertThat(runner.runTestsInParallelFor(SampleParallelDataDrivenScenario.class), is(true));471 assertThat(runner.runTestsInParallelFor(SampleDataDrivenScenario.class), is(false));472 }473 @Test474 public void by_default_the_number_of_threads_is_2_times_the_number_of_CPU_cores() throws Throwable {475 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleParallelDataDrivenScenario.class);476 int threadCount = runner.getThreadCountFor(SampleParallelDataDrivenScenario.class);477 int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();478 assertThat(threadCount, is(AVAILABLE_PROCESSORS * 2));479 }480 @RunWith(SerenityParameterizedRunner.class)481 @Concurrent(threads = "7")482 public static final class ParallelDataDrivenScenarioWithSpecifiedThreadCountSample {483 @TestData484 public static Collection testData() {485 return Arrays.asList(new Object[][]{});486 }487 @Test488 public void foo() {489 }490 }491 @Test492 public void the_number_of_threads_can_be_overridden_in_the_concurrent_annotation() throws Throwable {493 SerenityParameterizedRunner runner494 = getTestRunnerUsing(ParallelDataDrivenScenarioWithSpecifiedThreadCountSample.class);495 int threadCount = runner.getThreadCountFor(ParallelDataDrivenScenarioWithSpecifiedThreadCountSample.class);496 assertThat(threadCount, is(7));497 }498 @Test499 public void the_number_of_threads_can_be_overridden_with_a_system_property() throws Throwable {500 environmentVariables.setProperty("thucydides.concurrent.threads", "4");501 SerenityParameterizedRunner runner502 = getTestRunnerUsing(ParallelDataDrivenScenarioWithSpecifiedThreadCountSample.class);503 int threadCount = runner.getThreadCountFor(ParallelDataDrivenScenarioWithSpecifiedThreadCountSample.class);504 assertThat(threadCount, is(4));505 }506 @RunWith(SerenityParameterizedRunner.class)507 @Concurrent(threads = "7x")508 public static final class ParallelDataDrivenScenarioWithRelativeThreadCountSample {509 @TestData510 public static Collection testData() {511 return Arrays.asList(new Object[][]{});512 }513 @Test514 public void foo() {515 }516 }517 @Test518 public void the_number_of_threads_can_be_overridden_in_the_concurrent_annotation_using_a_relative_value() throws Throwable {519 SerenityParameterizedRunner runner520 = getTestRunnerUsing(ParallelDataDrivenScenarioWithRelativeThreadCountSample.class);521 int threadCount = runner.getThreadCountFor(ParallelDataDrivenScenarioWithRelativeThreadCountSample.class);522 int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();523 assertThat(threadCount, is(7 * AVAILABLE_PROCESSORS));524 }525 @RunWith(SerenityParameterizedRunner.class)526 @Concurrent(threads = "xxx")527 public static final class ParallelDataDrivenScenarioWithInvalidThreadCountSample {528 @TestData529 public static Collection testData() {530 return Arrays.asList(new Object[][]{});531 }532 @Test533 public void foo() {534 }535 }536 @Test(expected = IllegalArgumentException.class)537 public void if_the_thread_count_is_invalid_an_exception_should_be_thrown() throws Throwable {538 SerenityParameterizedRunner runner539 = getTestRunnerUsing(ParallelDataDrivenScenarioWithInvalidThreadCountSample.class);540 runner.getThreadCountFor(ParallelDataDrivenScenarioWithInvalidThreadCountSample.class);541 }542 private List<String> filenamesOf(File[] files) {543 List filenames = new ArrayList<String>();544 for (File file : files) {545 filenames.add(file.getName());546 }547 return filenames;548 }549 private List<String> contentsOf(File[] files) throws IOException {550 List<String> contents = new ArrayList<>();551 for (File file : files) {552 contents.add(stringContentsOf(file));553 }554 return contents;555 }556 private String stringContentsOf(File reportFile) throws IOException {557 return FileUtils.readFileToString(reportFile);558 }559 private File reload(File old) {560 return Paths.get(old.getAbsolutePath()).toFile();561 }562 @Test563 public void a_separate_html_report_should_be_generated_from_each_scenario() throws Throwable {564 File outputDirectory = tempFolder.newFolder("thucydides");565 environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_OUTPUT_DIRECTORY.getPropertyName(),566 outputDirectory.getAbsolutePath());567 SerenityParameterizedRunner runner = getTestRunnerUsing(SampleDataDrivenScenario.class);568 runner.run(new RunNotifier());569 File[] reports = reload(outputDirectory).listFiles(new HTMLFileFilter());570 assertThat(reports.length, is(3));571 }572 private class HTMLFileFilter implements FilenameFilter {573 public boolean accept(File directory, String filename) {574 return filename.endsWith(".html") && !filename.endsWith("screenshots.html");575 }576 }577 private class JSONFileFilter implements FilenameFilter {578 public boolean accept(File directory, String filename) {579 return filename.endsWith(".json") && !filename.startsWith("manifest");580 }581 }582 protected SerenityRunner getNormalTestRunnerUsing(Class<?> testClass) throws Throwable {583 DriverConfiguration configuration = new WebDriverConfiguration(environmentVariables);584 WebDriverFactory factory = new WebDriverFactory(environmentVariables);585 return new SerenityRunner(testClass, factory, configuration);586 }587 protected SerenityParameterizedRunner getTestRunnerUsing(Class<?> testClass) throws Throwable {588 return getTestRunnerUsing(testClass, environmentVariables);589 }590 protected SerenityParameterizedRunner getTestRunnerUsing(Class<?> testClass, EnvironmentVariables environmentVariables) throws Throwable {591 DriverConfiguration configuration = new WebDriverConfiguration(environmentVariables);592 WebDriverFactory factory = new WebDriverFactory(environmentVariables);593 BatchManager batchManager = new BatchManagerProvider(configuration).get();594 return new SerenityParameterizedRunner(testClass, configuration, factory, batchManager);595 }596 protected SerenityParameterizedRunner getStubbedTestRunnerUsing(Class<?> testClass) throws Throwable {597 DriverConfiguration configuration = new WebDriverConfiguration(environmentVariables);598 WebDriverFactory factory = new WebDriverFactory(environmentVariables);599 BatchManager batchManager = new BatchManagerProvider(configuration).get();600 return new SerenityParameterizedRunner(testClass, configuration, factory, batchManager) {601 @Override602 public void generateReports() {603 //do nothing604 }605 };606 }607 @Test608 public void parameterized_test_class_correct_number_of_test_methods_are_run_using_one_tag() throws Throwable {609 EnvironmentVariables environmentVariablesWithTags = environmentVariables;610 environmentVariables.setProperty("tags", "b");611 SerenityParameterizedRunner runner = getTestRunnerUsing(612 ExampleDataDrivenWithTestMethodTags.class,613 environmentVariablesWithTags614 );615 runner.run(new RunNotifier());616 List<TestOutcome> executedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).getTestOutcomesForAllParameterSets();617 assertThat(executedScenarios.size(), is(1));618 }619 @Test620 public void parameterized_test_class_correct_number_of_test_methods_are_run_using_multiple_tags() throws Throwable {621 EnvironmentVariables environmentVariablesWithTags = environmentVariables;622 environmentVariables.setProperty("tags", "a or c");623 SerenityParameterizedRunner runner = getTestRunnerUsing(624 ExampleDataDrivenWithTestMethodTags.class,625 environmentVariablesWithTags626 );627 runner.run(new RunNotifier());628 List<TestOutcome> executedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).getTestOutcomesForAllParameterSets();629 assertThat(executedScenarios.size(), is(2));630 }631 @RunWith(SerenityParameterizedRunner.class)632 public static class ExampleDataDrivenWithTestMethodTags {633 @TestData634 public static Collection<Object[]> testData() {635 List<Object[]> list = new ArrayList<>();636 list.add(new String[]{""});637 return list;638 }639 public ExampleDataDrivenWithTestMethodTags(String string) {640 }641 @Test642 @WithTag("a")...

Full Screen

Full Screen

Source:SerenityParameterizedRunner.java Github

copy

Full Screen

...24 private static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();25 private List<Runner> runners = new ArrayList<>();26 private final DriverConfiguration configuration;27 private ReportService reportService;28 private final ParameterizedTestsOutcomeAggregator parameterizedTestsOutcomeAggregator = ParameterizedTestsOutcomeAggregator.from(this);29 private TagScanner tagScanner;30 /**31 * Test runner used for testing purposes.32 *33 * @param klass The test class to run34 * @param configuration current system configuration (usually mocked)35 * @param webDriverFactory a webdriver factory (can be mocked)36 * @param batchManager a batch manager to process batched testing37 * @throws Throwable - cause anything can happen!38 */39 public SerenityParameterizedRunner(final Class<?> klass,40 DriverConfiguration configuration,41 final WebDriverFactory webDriverFactory,42 final BatchManager batchManager...

Full Screen

Full Screen

Source:ParameterizedTestsOutcomeAggregator.java Github

copy

Full Screen

...3import org.apache.commons.lang3.*;4import org.junit.runner.*;5import java.util.*;6import java.util.stream.*;7public class ParameterizedTestsOutcomeAggregator {8 private final SerenityParameterizedRunner serenityParameterizedRunner;9 private ParameterizedTestsOutcomeAggregator(SerenityParameterizedRunner serenityParameterizedRunner) {10 this.serenityParameterizedRunner = serenityParameterizedRunner;11 }12 public static ParameterizedTestsOutcomeAggregator from(SerenityParameterizedRunner serenityParameterizedRunner) {13 return new ParameterizedTestsOutcomeAggregator(serenityParameterizedRunner);14 }15 public List<TestOutcome> aggregateTestOutcomesByTestMethods() {16 List<TestOutcome> allOutcomes = getTestOutcomesForAllParameterSets();17 if (allOutcomes.isEmpty()) {18 return new ArrayList<>();19 } else {20 return aggregatedScenarioOutcomes(allOutcomes);21 }22 }23 private List<TestOutcome> aggregatedScenarioOutcomes(List<TestOutcome> allOutcomes) {24 Map<String, TestOutcome> scenarioOutcomes = new HashMap();25 for (TestOutcome testOutcome : allOutcomes) {26 final String normalizedMethodName = baseMethodName(testOutcome);27 TestOutcome scenarioOutcome = scenarioOutcomeFor(normalizedMethodName, testOutcome, scenarioOutcomes);...

Full Screen

Full Screen

Source:WhenRunningADataDrivenTestScenarioToCheckDuration.java Github

copy

Full Screen

...51 @Test52 public void a_data_driven_test_driver_should_aggregate_test_outcomes() throws Throwable {53 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing(SampleDataDrivenScenarioWithDelays.class);54 runner.run(new RunNotifier());55 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();56 for (TestOutcome test : aggregatedScenarios) {57 long duration = 0;58 for (TestStep step : test.getTestSteps()) {59 duration += step.getDuration();60 }61// assertThat("Duration of tests is invalid", test.getDuration() > 0, is(true));62 assertThat("Duration of tests invalid not propagated", test.getDuration(), is(duration));63 }64 }65 @Test66 public void a_data_driven_test_driver_should_aggregate_test_outcomes2() throws Throwable {67 SerenityParameterizedRunner runner = getStubbedTestRunnerUsing( SampleCSVDataDrivenScenarioWithDelays.class);68 runner.run(new RunNotifier());69 List<TestOutcome> aggregatedScenarios = ParameterizedTestsOutcomeAggregator.from(runner).aggregateTestOutcomesByTestMethods();70 for (TestOutcome test : aggregatedScenarios) {71 long duration = 0;72 for (TestStep step : test.getTestSteps()) {73 duration += step.getDuration();74 }75 assertThat("Duration of tests is invalid", test.getDuration() > 0, is(true));76 assertThat("Duration of tests invalid not propagated", test.getDuration(), is(duration));77 assertThat("Duration in seconds of tests invalid", test.getDurationInSeconds() > 0, is(true));78 }79 }80}...

Full Screen

Full Screen

ParameterizedTestsOutcomeAggregator

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.junit.runners.ParameterizedTestsOutcomeAggregator;2import net.thucydides.core.steps.StepEventBus;3import net.thucydides.core.steps.StepFailure;4import net.thucydides.core.steps.StepListener;5import net.thucydides.core.steps.StepResult;6import net.thucydides.core.steps.StepFailure;7import org.junit.runner.notification.Failure;8import java.util.ArrayList;9import java.util.List;10public class ParameterizedTestsOutcomeAggregator implements StepListener {11 private final List<StepFailure> failures = new ArrayList<>();12 private List<StepResult> stepResults = new ArrayList<>();13 public void testSuiteStarted(Class<?> storyClass) {14 }15 public void testSuiteStarted(Story story) {16 }17 public void testSuiteFinished() {18 }19 public void testStarted(String description) {20 }21 public void testFinished(TestOutcome result) {22 }23 public void stepStarted(ExecutedStepDescription description) {24 }25 public void skippedStepStarted(ExecutedStepDescription description) {26 }27 public void stepFailed(StepFailure failure) {28 failures.add(failure);29 }30 public void lastStepFailed(StepFailure failure) {31 }32 public void stepIgnored() {33 }34 public void stepPending() {35 }36 public void stepPending(String message) {37 }38 public void stepFinished() {39 }40 public void testFailed(TestOutcome testOutcome, Throwable cause) {41 }42 public void testIgnored() {43 }44 public void testPending() {45 }46 public void testIsManual() {47 }48 public void notifyScreenChange() {

Full Screen

Full Screen

ParameterizedTestsOutcomeAggregator

Using AI Code Generation

copy

Full Screen

1@Outcome(id = "0", expect = Expect.ACCEPTABLE, desc = "ParameterizedTests executed successfully")2@Outcome(id = "1", expect = Expect.FORBIDDEN, desc = "ParameterizedTests execution failed")3public class ParameterizedTestsOutcomeAggregator {4 @Param("1")5 int param;6 @Param("2")7 int param2;8 @Param("3")9 int param3;10 public void arbiter(TestResult result) {11 }12}13public class ParameterizedTests {14 @ParameterizedTest(name = "ParameterizedTests: {0}")15 @ValueSource(strings = {"a", "b", "c"})16 public void parameterizedTest(String str) {17 System.out.println("ParameterizedTests: " + str);18 }19}20public class ParameterizedTestsTest {21 public void test() {22 Result result = JUnitCore.runClasses(ParameterizedTests.class);23 System.out.println("ParameterizedTests execution result: " + result.wasSuccessful());24 }25}26 0.000 ±(99.9%) 0.000 ops/s [Average]27 (min, avg, max) = (0.000, 0.000, 0.000), stdev = 0.00028 CI (99.9%): [0.000, 0.000] (assumes normal distribution)29@Outcome(id = "0", expect = Expect.ACCEPTABLE, desc = "ParameterizedTests executed successfully")30@Outcome(id

Full Screen

Full Screen

ParameterizedTestsOutcomeAggregator

Using AI Code Generation

copy

Full Screen

1public class ParameterizedTestsOutcomeAggregator extends SerenityRunner {2 public void run(final RunNotifier notifier) {3 super.run(notifier);4 final List<TestOutcome> testOutcomes = getTestOutcomes();5 final List<TestOutcome> failedTestOutcomes = testOutcomes.stream()6 .filter(TestOutcome::isFailure)7 .collect(Collectors.toList());8 }9}

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.

Run Serenity JUnit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in ParameterizedTestsOutcomeAggregator

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful