How to use afterStory method of net.serenitybdd.jbehave.SerenityReporter class

Best Serenity jBehave code snippet using net.serenitybdd.jbehave.SerenityReporter.afterStory

Source:SerenityReporter.java Github

copy

Full Screen

...386 private String removeSuffixFrom(String name) {387 return (name.contains(".")) ? name.substring(0, name.indexOf(".")) : name;388 }389 @Override390 public void afterStory(boolean given) {391 logger.debug("afterStory {}", given);392 shouldNestScenarios(false);393 if (given) {394 givenStoryMonitor.exitingGivenStory();395 givenStoryDone(currentStory());396 } else {397 if (isAfterStory(currentStory())) {398 generateReports();399 } else if (!isFixture(currentStory()) && (!isAStoryLevelGiven(currentStory()))) {400 StepEventBus.getEventBus().testSuiteFinished();401 clearListeners();402 }403 }404 storyStack.pop();405 }406 private boolean isAfterStory(Story currentStory) {407 return (currentStory.getName().equals(AFTER_STORIES));408 }409 private synchronized void generateReports() {410 getReportService().generateReportsFor(getAllTestOutcomes());411 }412 public List<TestOutcome> getAllTestOutcomes() {413 return baseStepListeners.stream()414 .map(BaseStepListener::getTestOutcomes)415 .flatMap(Collection::stream)416 .collect(Collectors.toList());417 }418 @Override419 public void narrative(Narrative narrative) {420 logger.debug("narrative {}", narrative);421 }422 @Override423 public void lifecyle(Lifecycle lifecycle) {424 logger.debug("lifecyle {}", lifecycle);425 }426 @Override427 public void scenarioNotAllowed(Scenario scenario, String s) {428 logger.debug("scenarioNotAllowed {}", scenario.getTitle());429 StepEventBus.getEventBus().testIgnored();430 }431 private void startScenarioCalled(Scenario scenario, Story story) {432 StepEventBus.getEventBus().setTestSource(TEST_SOURCE_JBEHAVE.getValue());433 StepEventBus.getEventBus().testStarted(scenario.getTitle(), story.getPath() + ";" + scenario.getTitle());434 activeScenarios.add(scenario);435 }436 private boolean shouldResetStepsBeforeEachScenario() {437 return systemConfiguration.getEnvironmentVariables().getPropertyAsBoolean(438 SerenityJBehaveSystemProperties.RESET_STEPS_EACH_SCENARIO.getName(), true);439 }440 private void markAsSkippedOrPendingIfAnnotatedAsSuchIn(List<String> tags) {441 if (isManual(tags)) {442 StepEventBus.getEventBus().testIsManual();443 }444 if (isSkipped(tags)) {445 StepEventBus.getEventBus().testSkipped();446 StepEventBus.getEventBus().getBaseStepListener().overrideResultTo(TestResult.SKIPPED);447 }448 if (isPending(tags)) {449 StepEventBus.getEventBus().testPending();450 StepEventBus.getEventBus().getBaseStepListener().overrideResultTo(TestResult.PENDING);451 }452 if (isIgnored(tags)) {453 StepEventBus.getEventBus().testIgnored();454 StepEventBus.getEventBus().getBaseStepListener().overrideResultTo(TestResult.IGNORED);455 }456 }457 private boolean isSkipped(List<String> tags) {458 return tags.contains("skip") || tags.contains("wip");459 }460 private boolean isPending(List<String> tags) {461 return tags.contains("pending");462 }463 private boolean isIgnored(List<String> tags) {464 return tags.contains("ignore");465 }466 private boolean isManual(List<String> tags) {467 return tags.contains("manual");468 }469 private boolean isPending(Meta metaData) {470 return metaData != null && (metaData.hasProperty(PENDING));471 }472 private boolean isManual(Meta metaData) {473 return metaData != null && (metaData.hasProperty(MANUAL));474 }475 private boolean isSkipped(Meta metaData) {476 return metaData != null && (metaData.hasProperty(WIP) || metaData.hasProperty(SKIP));477 }478 private boolean isCandidateToBeExecuted(Meta metaData) {479 return !isIgnored(metaData) && !isPending(metaData) && !isSkipped(metaData);480 }481 private boolean isIgnored(Meta metaData) {482 return metaData != null && (metaData.hasProperty(IGNORE));483 }484 @Override485 public void afterScenario() {486 Scenario scenario = currentScenario();487 logger.debug("afterScenario : {}", scenario.getTitle());488 List<String> scenarioTags = scenarioTags(scenario);489 markAsSkippedOrPendingIfAnnotatedAsSuchIn(scenarioTags);490 if (givenStoryMonitor.isInGivenStory() || shouldNestScenarios()) {491 StepEventBus.getEventBus().stepFinished();492 } else {493 if (!(isPending(scenarioTags) || isSkipped(scenarioTags) || isIgnored(scenarioTags))) {494 StepEventBus.getEventBus().testFinished(executingExamples());495 }496 activeScenarios.pop();497 }498 ThucydidesWebDriverSupport.clearStepLibraries();499 }500 @Override501 public void givenStories(GivenStories givenStories) {502 logger.debug("givenStories {}", givenStories);503 givenStoryMonitor.enteringGivenStory();504 }505 @Override506 public void givenStories(List<String> strings) {507 logger.debug("givenStories {}", strings);508 }509 int exampleCount = 0;510 @Override511 public void beforeExamples(List<String> steps, ExamplesTable table) {512 logger.debug("beforeExamples {} {}", steps, table);513 if (givenStoryMonitor.isInGivenStory()) {514 return;515 }516 exampleCount = 0;517 StepEventBus.getEventBus().useExamplesFrom(serenityTableFrom(table));518 }519 private DataTable serenityTableFrom(ExamplesTable table) {520 String scenarioOutline = scenarioOutlineFrom(currentScenario());521 return DataTable.withHeaders(table.getHeaders())522 .andScenarioOutline(scenarioOutline)523 .andMappedRows(table.getRows())524 .build();525 }526 private String scenarioOutlineFrom(Scenario scenario) {527 StringBuilder outline = new StringBuilder();528 for (String step : scenario.getSteps()) {529 outline.append(step.trim()).append(System.lineSeparator());530 }531 return outline.toString();532 }533 @Override534 public void example(Map<String, String> tableRow, int exampleIndex) {535 StepEventBus.getEventBus().clearStepFailures();536 if (givenStoryMonitor.isInGivenStory()) {537 return;538 }539 if (executingExamples()) {540 finishExample();541 }542 exampleCount++;543 startExample(tableRow);544 }545 private void startExample(Map<String, String> data) {546 StepEventBus.getEventBus().exampleStarted(data);547 }548 private void finishExample() {549 StepEventBus.getEventBus().exampleFinished();550 }551 private boolean executingExamples() {552 return (exampleCount > 0);553 }554 @Override555 public void afterExamples() {556 if (givenStoryMonitor.isInGivenStory()) {557 return;558 }559 finishExample();560 }561 @Override562 public void beforeStep(String stepTitle) {563 StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(stepTitle));564 }565 @Override566 public void successful(String title) {567 if (annotatedResultTakesPriority()) {568 processAnnotatedResult();569 } else {570 StepEventBus.getEventBus().updateCurrentStepTitle(normalized(title));571 StepEventBus.getEventBus().stepFinished();572 }573 }574 private void processAnnotatedResult() {575 TestResult forcedResult = StepEventBus.getEventBus().getForcedResult().get();576 switch (forcedResult) {577 case PENDING:578 StepEventBus.getEventBus().stepPending();579 break;580 case IGNORED:581 StepEventBus.getEventBus().stepIgnored();582 break;583 case SKIPPED:584 StepEventBus.getEventBus().stepIgnored();585 break;586 default:587 StepEventBus.getEventBus().stepIgnored();588 }589 }590 private boolean annotatedResultTakesPriority() {591 return StepEventBus.getEventBus().getForcedResult().isPresent();592 }593 @Override594 public void ignorable(String title) {595 StepEventBus.getEventBus().updateCurrentStepTitle(normalized(title));596 StepEventBus.getEventBus().stepIgnored();597 }598 @Override599 public void comment(String step) {600 StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(step));601 StepEventBus.getEventBus().stepIgnored();602 }603 @Override604 public void pending(String stepTitle) {605 StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(normalized(stepTitle)));606 StepEventBus.getEventBus().stepPending();607 }608 @Override609 public void notPerformed(String stepTitle) {610 StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(normalized(stepTitle)));611 StepEventBus.getEventBus().stepIgnored();612 }613 @Override614 public void failed(String stepTitle, Throwable cause) {615 if (!StepEventBus.getEventBus().testSuiteHasStarted()) {616 declareOutOfSuiteFailure();617 }618 if (!errorOrFailureRecordedForStep(cause.getCause())) {619 StepEventBus.getEventBus().updateCurrentStepTitle(stepTitle);620 Throwable rootCause = new RootCauseAnalyzer(cause.getCause()).getRootCause().toException();621 if (isAssumptionFailure(rootCause)) {622 StepEventBus.getEventBus().assumptionViolated(rootCause.getMessage());623 } else {624 StepEventBus.getEventBus().stepFailed(new StepFailure(ExecutedStepDescription.withTitle(normalized(stepTitle)), rootCause));625 }626 }627 }628 private void declareOutOfSuiteFailure() {629 String storyName = !storyStack.isEmpty() ? storyStack.peek().getName() : "Before or After Story";630 String storyId = !storyStack.isEmpty() ? storyStack.peek().getPath() : null;631 StepEventBus.getEventBus().testStarted(storyName, storyId);632 }633 private boolean isAssumptionFailure(Throwable rootCause) {634 return (AssumptionViolatedException.class.isAssignableFrom(rootCause.getClass()));635 }636 public List<String> processExcludedByFilter(final Story story, final Set<String> exclude) {637 final Meta storyMeta = story.getMeta();638 final List<Scenario> processing = new LinkedList<>();639 final List<String> processed = new LinkedList<>();640 if (isSkipped(storyMeta) || isIgnored(storyMeta)) { //this story should be excluded by filter641 processing.addAll(story.getScenarios());642 } else {643 for (Scenario scenario : story.getScenarios()) {644 final Meta scenarioMeta = scenario.getMeta();645 if (isSkipped(scenarioMeta) || isIgnored(scenarioMeta)) { //this scenario should be excluded by filter646 processing.add(scenario);647 }648 }649 }650 if (processing.size() > 0) {651 final Story beforeStory = new Story();652 beforeStory.namedAs(BEFORE_STORIES);653 final Story afterStory = new Story();654 afterStory.namedAs(AFTER_STORIES);655 final Narrative narrative = story.getNarrative();656 beforeStory(beforeStory, false);657 afterStory(false);658 beforeStory(story, false);659 narrative(narrative);660 for (final Scenario filtered : processing) {661 final String scenarioKey = scenarioKey(story, filtered);662 if (!exclude.contains(scenarioKey)) {663 beforeScenario(filtered);664 final List<String> steps = filtered.getSteps();665 if (ExamplesTable.EMPTY == filtered.getExamplesTable() || filtered.getExamplesTable().getRows().size() == 0) {666 for (final String step : steps) {667 beforeStep(step);668 successful(step);669 }670 } else {671 final ExamplesTable examples = filtered.getExamplesTable();672 beforeExamples(steps, examples);673 for (final Map<String, String> row : examples.getRows()) {674 example(row);675 for (final String step : steps) {676 beforeStep(step);677 successful(step);678 }679 }680 afterExamples();681 }682 afterScenario();683 processed.add(scenarioKey(story, filtered));684 }685 }686 afterStory(false);687 beforeStory(afterStory, false);688 afterStory(false);689 }690 return processed;691 }692 private String scenarioKey(final Story story, final Scenario scenario) {693 return story.getPath().concat(scenario.getTitle());694 }695 @Override696 public void failedOutcomes(String s, OutcomesTable outcomesTable) {697 logger.debug("failedOutcomes");698 }699 @Override700 public void restarted(String s, Throwable throwable) {701 logger.debug("restarted");702 }...

Full Screen

Full Screen

afterStory

Using AI Code Generation

copy

Full Screen

1public class SerenityReporter extends JUnitReportingRunner {2 public void afterStory(boolean givenStory) {3 super.afterStory(givenStory);4 if (!givenStory) {5 getEmbedder().generateCrossReference();6 }7 }8}

Full Screen

Full Screen

afterStory

Using AI Code Generation

copy

Full Screen

1public class SerenityReporter extends SerenityStories {2 public void afterStory(boolean givenStory) {3 super.afterStory(givenStory);4 if (!givenStory) {5 }6 }7}8public class SerenityReporter extends SerenityStories {9 public void afterStory(boolean givenStory) {10 super.afterStory(givenStory);11 if (!givenStory) {12 }13 }14}15public class SerenityReporter extends SerenityStories {16 public void afterStory(boolean givenStory) {17 super.afterStory(givenStory);18 if (!givenStory) {19 }20 }21}22public class SerenityReporter extends SerenityStories {23 public void afterStory(boolean givenStory) {24 super.afterStory(givenStory);25 if (!givenStory) {26 }27 }28}29public class SerenityReporter extends SerenityStories {30 public void afterStory(boolean givenStory) {31 super.afterStory(givenStory);32 if (!givenStory) {33 }34 }35}36public class SerenityReporter extends SerenityStories {37 public void afterStory(boolean givenStory) {38 super.afterStory(givenStory);39 if (!givenStory) {40 }41 }42}43public class SerenityReporter extends SerenityStories {44 public void afterStory(boolean givenStory) {45 super.afterStory(givenStory);46 if (!givenStory) {47 }48 }49}

Full Screen

Full Screen

afterStory

Using AI Code Generation

copy

Full Screen

1import org.jbehave.core.annotations.AfterStory2import net.thucydides.core.annotations.Steps3import net.serenitybdd.jbehave.SerenityReporter4import net.serenitybdd.core.pages.PageObject5import net.serenitybdd.core.pages.WebElementFacade6import net.thucydides.core.annotations.Step7import net.thucydides.core.annotations.Steps8import net.thucydides.core.annotations.WhenPageOpens9import net.thucydides.core.annotations.WithTag10import net.thucydides.core.annotations.WithTags11import net.thucydides.core.pages.PageObject12import net.thucydides.core.pages.WebElementFacade13import org.junit.Test14import org.junit.runner.RunWith15import org.openqa.selenium.By16import org.openqa.selenium.Keys17import org.openqa.selenium.WebDriver18import org.openqa.selenium.WebElement19import org.openqa.selenium.chrome.ChromeDriver20import org.openqa.selenium.firefox.FirefoxDriver21import org.openqa.selenium.interactions.Actions22import org.openqa.selenium.support.FindBy23import org.openqa.selenium.support.How24import org.openqa.selenium.support.ui.ExpectedConditions25import org.openqa.selenium.support.ui.WebDriverWait26import java.util.concurrent.TimeUnit27import static net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getPages28public class SerenityReporter extends SerenityReporter {29 public void afterStory() {30 if (getPages().getDriver().toString().contains("Chrome")) {31 try {32 getPages().getDriver().quit()33 } catch (Exception e) {34 }35 }36 }37}38public class Steps {39 public void step1() {40 }41 public void step2() {42 }43 public void step3() {44 }45}46public class MyStory {47 Steps steps;48 public void myTest() {49 steps.step1();50 steps.step2();51 steps.step3();52 }53}54public class MyStory {55 Steps steps;56 public void myTest() {57 steps.step1();58 steps.step2();59 steps.step3();60 }61}62public class Steps {

Full Screen

Full Screen

afterStory

Using AI Code Generation

copy

Full Screen

1import net.thucydides.core.annotations.Steps;2import net.serenitybdd.jbehave.SerenityReporter;3import net.serenitybdd.jbehave.model.Story;4import net.thucydides.core.steps.StepEventBus;5public class CustomSerenityReporter extends SerenityReporter {6 private CustomSteps customSteps;7 public void afterStory(boolean givenStory) {8 if (!StepEventBus.getEventBus().getBaseStepListener().isTestFailure()) {9 customSteps.afterStory();10 }11 super.afterStory(givenStory);12 }13}14package net.serenitybdd.jbehave;15import net.thucydides.core.annotations.Step;16public class CustomSteps {17 public void afterStory() {18 System.out.println("afterStory");19 }20}

Full Screen

Full Screen

afterStory

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.jbehave;2import net.thucydides.core.annotations.Steps;3import net.thucydides.core.screenshots.ScreenshotAndHtmlSource;4import net.thucydides.core.screenshots.ScreenshotKeywords;5import net.thucydides.core.steps.StepEventBus;6import net.thucydides.core.util.EnvironmentVariables;7import org.jbehave.core.model.Scenario;8import org.jbehave.core.reporters.StoryReporter;9import org.jbehave.core.steps.StepCollector.Stage;10import org.slf4j.Logger;11import org.slf4j.LoggerFactory;12import java.io.File;13import java.io.IOException;14import java.util.List;15import static org.apache.commons.lang3.StringUtils.isNotBlank;16public class SerenityReporter implements StoryReporter {17 private static final Logger LOGGER = LoggerFactory.getLogger(SerenityReporter.class);18 private final SerenityStoryReporter delegate;19 private final ScreenshotKeywords screenshotKeywords;20 public SerenityReporter(EnvironmentVariables environmentVariables) {21 screenshotKeywords = new ScreenshotKeywords(environmentVariables);22 delegate = new SerenityStoryReporter(environmentVariables);23 }24 public void beforeStory(Story story, boolean givenStory) {25 delegate.beforeStory(story, givenStory);26 }27 public void afterStory(boolean givenStory) {28 delegate.afterStory(givenStory);29 }30 public void beforeScenario(String scenarioTitle) {31 delegate.beforeScenario(scenarioTitle);32 }33 public void scenarioMeta(Meta meta) {34 delegate.scenarioMeta(meta);35 }36 public void afterScenario() {37 delegate.afterScenario();38 }39 public void givenStories(GivenStories givenStories) {40 delegate.givenStories(givenStories);41 }42 public void givenStories(List<String> storyPaths) {43 delegate.givenStories(storyPaths);44 }45 public void beforeExamples(List<String> steps, ExamplesTable table) {46 delegate.beforeExamples(steps, table);47 }48 public void example(Map<String, String> tableRow) {49 delegate.example(tableRow);50 }51 public void afterExamples() {52 delegate.afterExamples();53 }54 public void beforeStep(String step) {55 delegate.beforeStep(step);56 }57 public void successful(String step) {58 delegate.successful(step);59 }60 public void ignorable(String step) {

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful