Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.SerenityRunner.getTestOutcomes
Source:WhenRunningADataDrivenTestScenario.java
...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")...
Source:WhenRunningANonWebTestScenario.java
...43 @Test44 public void the_test_runner_records_the_steps_as_they_are_executed() throws InitializationError {45 SerenityRunner runner = new SerenityRunner(SamplePassingNonWebScenario.class, injector);46 runner.run(new RunNotifier());47 List<TestOutcome> executedSteps = runner.getTestOutcomes();48 assertThat(executedSteps.size(), is(3));49 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("happy_day_scenario").getTitle(), is("Happy day scenario"));50 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_1").getTitle(), is("Edge case 1"));51 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_2").getTitle(), is("Edge case 2"));52 }53 @Test54 public void tests_marked_as_pending_should_be_pending() throws InitializationError {55 SerenityRunner runner = new SerenityRunner(SamplePassingNonWebScenarioWithPendingTests.class);56 runner.run(new RunNotifier());57 List<TestOutcome> executedSteps = runner.getTestOutcomes();58 assertThat(executedSteps.size(), is(3));59 assertThat(inTheTesOutcomes(executedSteps).theResultFor("happy_day_scenario"), is(TestResult.SUCCESS));60 assertThat(inTheTesOutcomes(executedSteps).theResultFor("edge_case_1"), is(TestResult.PENDING));61 assertThat(inTheTesOutcomes(executedSteps).theResultFor("edge_case_2"), is(TestResult.PENDING));62 }63 @Test64 public void tests_with_failing_assumptions_should_be_ignored() throws InitializationError {65 SerenityRunner runner = new SerenityRunner(SampleScenarioWithFailingAssumption.class);66 runner.run(new RunNotifier());67 List<TestOutcome> executedSteps = runner.getTestOutcomes();68 assertThat(executedSteps.size(), is(3));69 assertThat(inTheTesOutcomes(executedSteps).theResultFor("happy_day_scenario"), is(TestResult.IGNORED));70 }71 @Test72 public void tests_marked_as_ignored_should_be_skipped() throws InitializationError {73 SerenityRunner runner = new SerenityRunner(SamplePassingNonWebScenarioWithIgnoredTests.class);74 runner.run(new RunNotifier());75 List<TestOutcome> executedSteps = runner.getTestOutcomes();76 assertThat(executedSteps.size(), is(3));77 assertThat(inTheTesOutcomes(executedSteps).theResultFor("happy_day_scenario"), is(TestResult.SUCCESS));78 assertThat(inTheTesOutcomes(executedSteps).theResultFor("edge_case_1"), is(TestResult.IGNORED));79 assertThat(inTheTesOutcomes(executedSteps).theResultFor("edge_case_2"), is(TestResult.IGNORED));80 }81 @Test82 public void tests_marked_as_manual_should_be_skipped_and_be_flagged_as_manual_tests() throws InitializationError {83 SerenityRunner runner = new SerenityRunner(SamplePassingNonWebScenarioWithManualTests.class);84 runner.run(new RunNotifier());85 List<TestOutcome> executedSteps = runner.getTestOutcomes();86 assertThat(inTheTesOutcomes(executedSteps).theResultFor("a_manual_test"), is(TestResult.PENDING));87 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("a_manual_test").isManual(), equalTo(true));88 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("a_manual_test").getTags(),89 hasItem(TestTag.withName("manual").andType("tag")));90 }91 public static final class ATestWithNoSteps {92 @Test93 public void test_with_no_steps() {}94 }95 @Test96 public void tests_with_no_steps_should_be_marked_as_successful() throws InitializationError {97 SerenityRunner runner = new SerenityRunner(ATestWithNoSteps.class);98 runner.run(new RunNotifier());99 List<TestOutcome> executedSteps = runner.getTestOutcomes();100 assertThat(inTheTesOutcomes(executedSteps).theResultFor("test_with_no_steps"), is(TestResult.SUCCESS));101 }102 public static final class AnIgnoredTest {103 @Test104 public void previous_test() {}105 @Ignore106 @Test107 public void ignored_test() {}108 @Test109 public void following_test() {}110 }111 @Test112 public void ignored_tests_should_be_flagged_as_ignored() throws InitializationError {113 SerenityRunner runner = new SerenityRunner(AnIgnoredTest.class);114 runner.run(new RunNotifier());115 List<TestOutcome> executedSteps = runner.getTestOutcomes();116 assertThat(inTheTesOutcomes(executedSteps).theResultFor("previous_test"), is(TestResult.SUCCESS));117 assertThat(inTheTesOutcomes(executedSteps).theResultFor("ignored_test"), is(TestResult.IGNORED));118 assertThat(inTheTesOutcomes(executedSteps).theResultFor("following_test"), is(TestResult.SUCCESS));119 }120 public static final class APendingTest {121 @Test122 public void previous_test() {}123 @Pending124 @Test125 public void pending_test() {}126 @Test127 public void following_test() {}128 }129 @Test130 public void pending_tests_should_be_flagged_as_pending() throws InitializationError {131 SerenityRunner runner = new SerenityRunner(APendingTest.class);132 runner.run(new RunNotifier());133 List<TestOutcome> executedSteps = runner.getTestOutcomes();134 assertThat(inTheTesOutcomes(executedSteps).theResultFor("previous_test"), is(TestResult.SUCCESS));135 assertThat(inTheTesOutcomes(executedSteps).theResultFor("pending_test"), is(TestResult.PENDING));136 assertThat(inTheTesOutcomes(executedSteps).theResultFor("following_test"), is(TestResult.SUCCESS));137 }138 @Test139 public void tests_should_be_run_after_an_assertion_error() throws InitializationError {140 SerenityRunner runner = new SerenityRunner(SampleNonWebScenarioWithError.class);141 runner.run(new RunNotifier());142 List<TestOutcome> executedSteps = runner.getTestOutcomes();143 assertThat(executedSteps.size(), is(3));144 assertThat(inTheTesOutcomes(executedSteps).theResultFor("happy_day_scenario"), is(TestResult.FAILURE));145 assertThat(inTheTesOutcomes(executedSteps).theResultFor("edge_case_1"), is(TestResult.SUCCESS));146 assertThat(inTheTesOutcomes(executedSteps).theResultFor("edge_case_2"), is(TestResult.SUCCESS));147 }148 @Test149 public void failing_tests_with_no_steps_should_still_record_the_error() throws InitializationError {150 SerenityRunner runner = new SerenityRunner(SampleNonWebScenarioWithError.class);151 runner.run(new RunNotifier());152 List<TestOutcome> executedSteps = runner.getTestOutcomes();153 assertThat(inTheTesOutcomes(executedSteps).theResultFor("happy_day_scenario"), is(TestResult.FAILURE));154 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("happy_day_scenario").getTestFailureMessage(),155 is("Oh bother!"));156 }157 @Test158 public void the_test_runner_skips_any_tests_after_a_failure() throws Exception {159 SerenityRunner runner = new SerenityRunner(SampleTestScenario.class);160 runner.run(new RunNotifier());161 List<TestOutcome> executedScenarios = runner.getTestOutcomes();162 TestOutcome testOutcome = testOutcomeWithTitle("Happy day scenario", executedScenarios);163 List<TestStep> steps = testOutcome.getTestSteps();164 assertThat(steps.size(), is(6));165 assertThat(steps.get(0).isSuccessful(), is(true));166 assertThat(steps.get(1).isIgnored(), is(true));167 assertThat(steps.get(2).isPending(), is(true));168 assertThat(steps.get(3).isIgnored(), is(true));169 assertThat(steps.get(4).isIgnored(), is(true));170 assertThat(steps.get(5).isIgnored(), is(true));171 }172 @Test173 public void the_test_runner_records_the_name_of_the_test_scenario() throws InitializationError {174 SerenityRunner runner = new SerenityRunner(SamplePassingNonWebScenario.class);175 runner.run(new RunNotifier());176 List<TestOutcome> executedScenarios = runner.getTestOutcomes();177 assertThat(executedScenarios.size(), greaterThan(0));178 assertThat(inTheTesOutcomes(executedScenarios).theOutcomeFor("happy_day_scenario").getTitle(), is("Happy day scenario"));179 }180 @Test181 public void the_test_runner_records_each_step_of_the_test_scenario() throws InitializationError {182 SerenityRunner runner = new SerenityRunner(SamplePassingNonWebScenario.class);183 runner.run(new RunNotifier());184 List<TestOutcome> executedScenarios = runner.getTestOutcomes();185 assertThat(executedScenarios.size(), is(3));186 assertThat(inTheTesOutcomes(executedScenarios).theOutcomeFor("happy_day_scenario").getTestSteps().size(), is(4));187 assertThat(inTheTesOutcomes(executedScenarios).theOutcomeFor("edge_case_1").getTestSteps().size(), is(3));188 assertThat(inTheTesOutcomes(executedScenarios).theOutcomeFor("edge_case_2").getTestSteps().size(), is(2));189 }190 @Test191 public void the_test_runner_distinguishes_between_ignored_skipped_and_pending_steps() throws InitializationError {192 SerenityRunner runner = new SerenityRunner(SampleTestScenario.class);193 runner.run(new RunNotifier());194 List<TestOutcome> executedScenarios = runner.getTestOutcomes();195 assertThat(executedScenarios.size(), is(2));196 TestOutcome testOutcome = testOutcomeWithTitle("Happy day scenario", executedScenarios);197 TestOutcome failingTestOutcome = executedScenarios.get(1);198 TestStep succeeds = testOutcome.getTestSteps().get(0);199 TestStep ignored = testOutcome.getTestSteps().get(1);200 TestStep pending = testOutcome.getTestSteps().get(2);201 TestStep failed = failingTestOutcome.getTestSteps().get(0);202 TestStep skipped = failingTestOutcome.getTestSteps().get(1);203 assertThat(succeeds.getResult(), is(TestResult.SUCCESS));204 assertThat(ignored.getResult(), is(TestResult.IGNORED));205 assertThat(pending.getResult(), is(TestResult.PENDING));206 assertThat(failed.getResult(), is(TestResult.FAILURE));207 assertThat(skipped.getResult(), is(TestResult.SKIPPED));208 }209 @Test210 public void the_test_runner_should_not_store_screenshots_for_non_web_tests() throws Exception {211 SerenityRunner runner = new SerenityRunner(SingleNonWebTestScenario.class);212 runner.run(new RunNotifier());213 List<TestOutcome> executedScenarios = runner.getTestOutcomes();214 TestOutcome testOutcome = testOutcomeWithTitle("Happy day scenario", executedScenarios);215 List<TestStep> steps = testOutcome.getTestSteps();216 assertThat(steps.get(0).getScreenshots().size(), is(0));217 }218 @Test219 public void the_test_runner_records_each_step_with_a_nice_name_when_steps_have_parameters() throws InitializationError {220 SerenityRunner runner = new SerenityRunner(NonWebTestScenarioWithParameterizedSteps.class);221 runner.run(new RunNotifier());222 List<TestOutcome> executedScenarios = runner.getTestOutcomes();223 TestOutcome testOutcome = testOutcomeWithTitle("Happy day scenario", executedScenarios);224 TestStep firstStep = testOutcome.getTestSteps().get(0);225 assertThat(firstStep.getDescription(), containsString("Step with a parameter:"));226 assertThat(firstStep.getDescription(), containsString("proportionOf"));227 }228 @Test229 public void should_not_fail_test_if_an_exception_is_expected() throws InitializationError {230 SerenityRunner runner = new SerenityRunner(NonWebTestScenarioWithParameterizedSteps.class);231 runner.run(new RunNotifier());232 List<TestOutcome> executedScenarios = runner.getTestOutcomes();233 TestOutcome testOutcome = testOutcomeWithTitle("Should throw correct exception", executedScenarios);234 TestStep firstStep = testOutcome.getTestSteps().get(0);235 assertThat(firstStep.getResult(), is(TestResult.SUCCESS));236 }237 @Test238 public void should_report_nested_class_parameters_correctly() throws InitializationError {239 SerenityRunner runner = new SerenityRunner(NonWebTestScenarioWithParameterizedSteps.class);240 runner.run(new RunNotifier());241 List<TestOutcome> executedScenarios = runner.getTestOutcomes();242 TestOutcome testOutcome = testOutcomeWithTitle("Should handle nested object parameters", executedScenarios);243 TestStep firstStep = testOutcome.getTestSteps().get(0);244 assertThat(firstStep.getDescription(), is("a step with an object parameter called $100.00"));245 }246 @Test247 public void should_report_correctly_customized_title_for_parameter_with_comma() throws InitializationError {248 SerenityRunner runner = new SerenityRunner(NonWebTestScenarioWithParameterizedSteps.class);249 runner.run(new RunNotifier());250 List<TestOutcome> executedScenarios = runner.getTestOutcomes();251 TestOutcome testOutcome = testOutcomeWithTitle("Should be correct customized title for parameter with comma", executedScenarios);252 TestStep firstStep = testOutcome.getTestSteps().get(0);253 assertThat(firstStep.getDescription(), is("a step with two object parameters called 'Joe, Smith' and '20'"));254 }255 private TestOutcome testOutcomeWithTitle(String title, List<TestOutcome> testOutcomes) {256 for(TestOutcome testOutcome : testOutcomes) {257 if (testOutcome.getTitle().startsWith(title)) {258 return testOutcome;259 }260 };261 return null;262 }263 @Test264 public void the_test_runner_records_each_step_with_a_nice_name_when_steps_have_multiple_parameters() throws InitializationError {265 SerenityRunner runner = new SerenityRunner(NonWebTestScenarioWithParameterizedSteps.class);266 runner.run(new RunNotifier());267 List<TestOutcome> executedScenarios = runner.getTestOutcomes();268 TestOutcome testOutcome = testOutcomeWithTitle("Happy day scenario", executedScenarios);269 TestStep secondStep = testOutcome.getTestSteps().get(1);270 assertThat(secondStep.getDescription(), containsString("Step with two parameters"));271 assertThat(secondStep.getDescription(), containsString("proportionOf, 2"));272 }273 class TestableSerenityRunnerSample extends SerenityRunner {274 private final File testOutputDirectory;275 public TestableSerenityRunnerSample(final Class<?> klass, File outputDirectory) throws InitializationError {276 super(klass);277 testOutputDirectory = outputDirectory;278 }279 public TestableSerenityRunnerSample(Class<?> klass,280 WebDriverFactory webDriverFactory,281 File outputDirectory) throws InitializationError {...
Source:QualifiedTestsRunner.java
...71 this.qualifier = qualifier;72 super.useQualifier(qualifier);73 }74 @Override75 public final List<TestOutcome> getTestOutcomes() {76 return enhance(qualified(super.getTestOutcomes()));77 }78 public List<TestOutcome> enhance(List<TestOutcome> outcomes) {79 return outcomes;80 }81 private List<TestOutcome> qualified(List<TestOutcome> testOutcomes) {82 List<TestOutcome> qualifiedOutcomes = new ArrayList<>();83 if (this.test != null) {84 useQualifier(QualifierFinder.forTestCase(test).getQualifier());85 }86 for (TestOutcome outcome : testOutcomes) {87 qualifiedOutcomes.add(outcome.withQualifier(qualifier));88 }89 return qualifiedOutcomes;90 }...
Source:WhenRerunningFailedTests.java
...33 public void the_test_runner_reruns_the_failing_tests_with_multiple_failures() throws Throwable {34 environmentVariables.setProperty(ThucydidesSystemProperty.TEST_RETRY_COUNT.getPropertyName(), "3");35 SerenityRunner runner = getNormalTestRunnerUsing(SampleNonWebScenarioWithError.class);36 runner.run(new RunNotifier());37 List<TestOutcome> executedScenarios = runner.getTestOutcomes();38 assertThat(executedScenarios.size(), is(3));39 }40 @Test41 public void the_test_runner_reruns_the_failing_tests_and_eventually_succeeds() throws Throwable {42 environmentVariables.setProperty(ThucydidesSystemProperty.TEST_RETRY_COUNT.getPropertyName(), "2");43 SerenityRunner runner = getNormalTestRunnerUsing(SampleNonWebScenarioWithErrorThatEventuallyWorks.class);44 runner.run(new RunNotifier());45 List<TestOutcome> executedScenarios = runner.getTestOutcomes();46 assertThat(executedScenarios.size(), is(1));47 assertThat(executedScenarios.get(0).getResult(), is(TestResult.SUCCESS));48 assertThat(executedScenarios.get(0).getStepCount(), is(3));49 assertThat(executedScenarios.get(0).getTestSteps().get(2).getDescription(), containsString("UNSTABLE TEST"));50 assertThat(executedScenarios.get(0).getTestSteps().get(2).getDescription(), containsString("A step that fails on odd tries"));51 assertThat(executedScenarios.get(0).getTags(), hasItem(TestTag.withName("Retries: 1").andType("unstable test")));52 }53 protected SerenityRunner getNormalTestRunnerUsing(Class<?> testClass) throws Throwable {54 DriverConfiguration configuration = new WebDriverConfiguration(environmentVariables);55 WebDriverFactory factory = new WebDriverFactory(environmentVariables);56 return new SerenityRunner(testClass, factory, configuration);57 }58}...
Source:RunningTestScenariosInParallel.java
...33 }34 public void run() {35 runner.run(new RunNotifier());36 }37 public List<TestOutcome> getTestOutcomes() {38 return runner.getTestOutcomes();39 }40 }41 @Test42 public void the_test_runner_records_the_steps_as_they_are_executed() throws InitializationError, InterruptedException {43 List<ScenarioThread> threads = new ArrayList<>();44 for(int i = 0; i < 10; i++) {45 threads.add(new ScenarioThread());46 }47 for(ScenarioThread thread : threads) {48 thread.start();49 }50 for(ScenarioThread thread : threads) {51 thread.join();52 }53 for(ScenarioThread thread : threads) {54 List<TestOutcome> executedSteps = thread.getTestOutcomes();55 assertThat(executedSteps.size(), is(3));56 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("happy_day_scenario").getTitle(), is("Happy day scenario"));57 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("happy_day_scenario").getTestSteps().size(), is(4));58 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_1").getTitle(), is("Edge case 1"));59 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_1").getTestSteps().size(), is(3));60 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_2").getTitle(), is("Edge case 2"));61 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_2").getTestSteps().size(), is(2));62 }63 }64}...
Source:WhenRunningTestBatches.java
...37 @Test38 public void the_test_runner_records_the_steps_as_they_are_executed() throws InitializationError {39 SerenityRunner runner = new SerenityRunner(SamplePassingScenario.class, webDriverFactory);40 runner.run(new RunNotifier());41 List<TestOutcome> executedSteps = runner.getTestOutcomes();42 assertThat(executedSteps.size(), is(3));43 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("happy_day_scenario").getTestSteps().size(), is(4));44 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_1").getTestSteps().size(), is(3));45 assertThat(inTheTesOutcomes(executedSteps).theOutcomeFor("edge_case_2").getTestSteps().size(), is(2));46 }47}...
Source:SerenityReportExtension.java
...18 generateReports(baseStepListener);19 }20 // net.serenitybdd.junit.runners.SerenityRunner.generateReports21 protected void generateReports(BaseStepListener baseStepListener) {22 generateReportsFor(baseStepListener.getTestOutcomes());23 }24 // net.serenitybdd.junit.runners.SerenityRunner.generateReportsFor25 /**26 * @param testOutcomeResults the test results from the previous test run.27 */28 private void generateReportsFor(final List<TestOutcome> testOutcomeResults) {29 final ReportService reportService = new ReportService(getOutputDirectory(), getDefaultReporters());30 reportService.generateReportsFor(testOutcomeResults);31 reportService.generateConfigurationsReport();32 }33 /**34 * @return The default reporters applicable for standard test runs.35 */36 protected Collection<AcceptanceTestReporter> getDefaultReporters() {...
Source:WhenRunningATestScenarioWithErrrors.java
...20 @Test21 public void the_test_runner_records_the_steps_as_they_are_executed() throws InitializationError {22 SerenityRunner runner = new SerenityRunner(SampleNonWebScenarioWithError.class);23 runner.run(new RunNotifier());24 List<TestOutcome> executedScenarios = runner.getTestOutcomes();25 assertThat(executedScenarios.size(), is(3));26 }27}
getTestOutcomes
Using AI Code Generation
1import net.serenitybdd.junit.runners.SerenityRunner;2@RunWith(SerenityRunner.class)3public class TestRunner {4 public void test1() {5 System.out.println("test1");6 }7 public void test2() {8 System.out.println("test2");9 }10 public void test3() {11 System.out.println("test3");12 }13}14import net.serenitybdd.junit.runners.SerenityRunner;15@RunWith(SerenityRunner.class)16public class TestRunner {17 public void test1() {18 System.out.println("test1");19 }20 public void test2() {21 System.out.println("test2");22 }23 public void test3() {24 System.out.println("test3");25 }26}27public class TestRunner {28 public void test1() {29 System.out.println("test1");30 }31 public void test2() {32 System.out.println("test2");33 }34 public void test3() {35 System.out.println("test3");36 }37}38import net.serenitybdd.junit.runners.SerenityRunner;39@RunWith(SerenityRunner.class)40public class TestRunner {41 public void test1() {42 System.out.println("test1");43 }44 public void test2() {45 System.out.println("test2");46 }47 public void test3() {48 System.out.println("test3");49 }50}51public class TestRunner {52 public void test1() {53 System.out.println("test1");54 }55 public void test2() {56 System.out.println("test2");57 }58 public void test3() {59 System.out.println("test3");60 }61}62public class TestRunner {63 public void test1() {64 System.out.println("test1");65 }66 public void test2() {
getTestOutcomes
Using AI Code Generation
1 List<TestOutcome> testOutcomes = new SerenityRunner().getTestOutcomes();2 testOutcomes.each { testOutcome ->3 if (testOutcome.getResult().isFailure()) {4 def result = testOutcome.getResult()5 def failure = result.getFailureCause()6 def stackTrace = failure.getStackTrace()7 def exception = failure.getException()8 def message = failure.getMessage()9 def testSteps = testOutcome.getTestSteps()10 }11 }12You can try to use the attach() method of TestOutcome object. It will attach any file to the report. For example, you can add the screenshot of the failed step to the report by using the following code:13 List<TestOutcome> testOutcomes = new SerenityRunner().getTestOutcomes();14 testOutcomes.each { testOutcome ->15 if (testOutcome.getResult().isFailure()) {16 def result = testOutcome.getResult()17 def failure = result.getFailureCause()18 def stackTrace = failure.getStackTrace()19 def exception = failure.getException()20 def message = failure.getMessage()21 def testSteps = testOutcome.getTestSteps()22 testOutcome.attach(file, "image/png", "screenshot");23 }24 }
getTestOutcomes
Using AI Code Generation
1import net.serenitybdd.junit.runners.SerenityRunner;2import net.serenitybdd.core.Serenity;3public void test() {4 SerenityRunner runner = new SerenityRunner(this.getClass());5 List<TestOutcome> testOutcomes = runner.getTestOutcomes();6 TestResult testResult = Serenity.getTestResult();7}8import net.serenitybdd.junit.runners.SerenityRunner;9import net.serenitybdd.core.Serenity;10public void test() {11 SerenityRunner runner = new SerenityRunner(this.getClass());12 List<TestOutcome> testOutcomes = runner.getTestOutcomes();13 TestResult testResult = Serenity.getTestResult();14}15import net.serenitybdd.junit.runners.SerenityRunner;16import net.serenitybdd.core.Serenity;17public void test() {18 SerenityRunner runner = new SerenityRunner(this.getClass());19 List<TestOutcome> testOutcomes = runner.getTestOutcomes();20 TestResult testResult = Serenity.getTestResult();21}22import net.serenitybdd.junit.runners.SerenityRunner;23import net.serenitybdd.core.Serenity;24public void test() {
getTestOutcomes
Using AI Code Generation
1package net.serenitybdd.junit.runners;2import net.thucydides.core.model.TestOutcome;3import org.junit.runner.Description;4import org.junit.runner.notification.RunNotifier;5import java.io.File;6import java.io.IOException;7import java.util.List;8public class SerenityRunner extends SerenityRunnerBase {9 public void run(RunNotifier notifier) {10 super.run(notifier);11 List<TestOutcome> testOutcomes = getTestOutcomes();12 File file = new File("test-outcomes.json");13 for (TestOutcome testOutcome : testOutcomes) {14 try {15 testOutcome.writeTo(file);16 } catch (IOException e) {17 e.printStackTrace();18 }19 }20 }21 protected Description describeChild(Object child) {22 return super.describeChild(child);23 }24}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!