Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription.getDescription
Source:SerenityReporter.java
...157 }158 }159 private Story userStoryFrom(Feature feature, String featureFileUri) {160 Story userStory = Story.withIdAndPath(TestSourcesModel.convertToId(feature.getName()), feature.getName(), featureFileUri).asFeature();161 if (!isEmpty(feature.getDescription())) {162 userStory = userStory.withNarrative(feature.getDescription());163 }164 return userStory;165 }166 private void handleTestCaseStarted(TestCaseStarted event) {167 String featurePath = event.testCase.getUri();168 getContext().currentFeaturePathIs(featurePath);169 setStepEventBus(featurePath);170 String scenarioName = event.testCase.getName();171 TestSourcesModel.AstNode astNode = featureLoader.getAstNode(getContext().currentFeaturePath(), event.testCase.getLine());172 Optional<Feature> currentFeature = featureFrom(featurePath);173 if ((astNode != null) && currentFeature.isPresent()) {174 getContext().setCurrentScenarioDefinitionFrom(astNode);175 //the sources are read in parallel, global current feature cannot be used176 String scenarioId = scenarioIdFrom(currentFeature.get().getName(), TestSourcesModel.convertToId(getContext().currentScenarioDefinition.getName()));177 boolean newScenario = !scenarioId.equals(getContext().getCurrentScenario());178 if (newScenario) {179 configureDriver(currentFeature.get(), getContext().currentFeaturePath());180 if (getContext().isAScenarioOutline()) {181 getContext().startNewExample();182 handleExamples(currentFeature.get(),183 getContext().currentScenarioOutline().getTags(),184 getContext().currentScenarioOutline().getName(),185 getContext().currentScenarioOutline().getExamples());186 }187 startOfScenarioLifeCycle(currentFeature.get(), scenarioName, getContext().currentScenarioDefinition, event.testCase.getLine());188 getContext().currentScenario = scenarioIdFrom(currentFeature.get().getName(), TestSourcesModel.convertToId(getContext().currentScenarioDefinition.getName()));189 } else {190 if (getContext().isAScenarioOutline()) {191 startExample(event.testCase.getLine());192 }193 }194 Background background = TestSourcesModel.getBackgroundForTestCase(astNode);195 if (background != null) {196 handleBackground(background);197 }198 }199 }200 private void handleTestCaseFinished(TestCaseFinished event) {201 if (getContext().examplesAreRunning()) {202 handleResult(event.result);203 finishExample();204 }205 if (event.result.is(Result.Type.FAILED) && noAnnotatedResultIdDefinedFor(event)) {206 getStepEventBus(event.testCase.getUri()).testFailed(event.result.getError());207 } else {208 getStepEventBus(event.testCase.getUri()).testFinished(getContext().examplesAreRunning());209 }210 getContext().clearStepQueue();211 }212 private boolean noAnnotatedResultIdDefinedFor(TestCaseFinished event) {213 BaseStepListener baseStepListener = getStepEventBus(event.testCase.getUri()).getBaseStepListener();214 return (baseStepListener.getTestOutcomes().isEmpty() || (latestOf(baseStepListener.getTestOutcomes()).getAnnotatedResult() == null));215 }216 private TestOutcome latestOf(List<TestOutcome> testOutcomes) {217 return testOutcomes.get(testOutcomes.size() - 1);218 }219 private List<String> createCellList(PickleRow row) {220 List<String> cells = new ArrayList<>();221 for (PickleCell cell : row.getCells()) {222 cells.add(cell.getValue());223 }224 return cells;225 }226 private void handleTestStepStarted(TestStepStarted event) {227 if (!(event.testStep instanceof HookTestStep)) {228 if (event.testStep instanceof PickleStepTestStep) {229 PickleStepTestStep pickleTestStep = (PickleStepTestStep) event.testStep;230 TestSourcesModel.AstNode astNode = featureLoader.getAstNode(getContext().currentFeaturePath(), pickleTestStep.getStepLine());231 if (astNode != null) {232 Step step = (Step) astNode.node;233 if (!getContext().isAddingScenarioOutlineSteps()) {234 getContext().queueStep(step);235 getContext().queueTestStep(event.testStep);236 }237 if (getContext().isAScenarioOutline()) {238 int lineNumber = event.getTestCase().getLine();239 getContext().stepEventBus().updateExampleLineNumber(lineNumber);240 }241 Step currentStep = getContext().getCurrentStep();242 String stepTitle = stepTitleFrom(currentStep, pickleTestStep);243 getContext().stepEventBus().stepStarted(ExecutedStepDescription.withTitle(stepTitle));244 getContext().stepEventBus().updateCurrentStepTitle(normalized(stepTitle));245 }246 }247 }248 }249 private void handleWrite(WriteEvent event) {250 getContext().stepEventBus().stepStarted(ExecutedStepDescription.withTitle(event.text));251 getContext().stepEventBus().stepFinished();252 }253 private void handleTestStepFinished(TestStepFinished event) {254 if (!(event.testStep instanceof HookTestStep)) {255 handleResult(event.result);256 }257 }258 private void handleTestRunFinished(TestRunFinished event) {259 generateReports();260 assureTestSuiteFinished();261 }262 private ReportService getReportService() {263 return SerenityReports.getReportService(systemConfiguration);264 }265 private void configureDriver(Feature feature, String featurePath) {266 getStepEventBus(featurePath).setUniqueSession(systemConfiguration.shouldUseAUniqueBrowser());267 List<String> tags = getTagNamesFrom(feature.getTags());268 String requestedDriver = getDriverFrom(tags);269 String requestedDriverOptions = getDriverOptionsFrom(tags);270 if (isNotEmpty(requestedDriver)) {271 ThucydidesWebDriverSupport.useDefaultDriver(requestedDriver);272 ThucydidesWebDriverSupport.useDriverOptions(requestedDriverOptions);273 }274 }275 private List<String> getTagNamesFrom(List<Tag> tags) {276 List<String> tagNames = new ArrayList<>();277 for (Tag tag : tags) {278 tagNames.add(tag.getName());279 }280 return tagNames;281 }282 private String getDriverFrom(List<String> tags) {283 String requestedDriver = null;284 for (String tag : tags) {285 if (tag.startsWith("@driver:")) {286 requestedDriver = tag.substring(8);287 }288 }289 return requestedDriver;290 }291 private String getDriverOptionsFrom(List<String> tags) {292 String requestedDriver = null;293 for (String tag : tags) {294 if (tag.startsWith("@driver-options:")) {295 requestedDriver = tag.substring(16);296 }297 }298 return requestedDriver;299 }300 private void handleExamples(Feature currentFeature, List<Tag> scenarioOutlineTags, String id, List<Examples> examplesList) {301 String featureName = currentFeature.getName();302 List<Tag> currentFeatureTags = currentFeature.getTags();303 getContext().doneAddingScenarioOutlineSteps();304 initializeExamples();305 for (Examples examples : examplesList) {306 if (examplesAreNotExcludedByTags(examples, scenarioOutlineTags, currentFeatureTags)307 && lineFilters.examplesAreNotExcluded(examples, getContext().currentFeaturePath())) {308 List<TableRow> examplesTableRows = examples309 .getTableBody()310 .stream()311 .filter(tableRow -> lineFilters.tableRowIsNotExcludedBy(tableRow, getContext().currentFeaturePath()))312 .collect(Collectors.toList());313 List<String> headers = getHeadersFrom(examples.getTableHeader());314 List<Map<String, String>> rows = getValuesFrom(examplesTableRows, headers);315 Map<Integer, Integer> lineNumbersOfEachRow = new HashMap<>();316 for (int i = 0; i < examplesTableRows.size(); i++) {317 TableRow tableRow = examplesTableRows.get(i);318 lineNumbersOfEachRow.put(i, tableRow.getLocation().getLine());319 addRow(exampleRows(), headers, tableRow);320 if (examples.getTags() != null) {321 exampleTags().put(examplesTableRows.get(i).getLocation().getLine(), examples.getTags());322 }323 }324 String scenarioId = scenarioIdFrom(featureName, id);325 boolean newScenario = !getContext().hasScenarioId(scenarioId);326 String exampleTableName = trim(examples.getName());327 String exampleTableDescription = trim(examples.getDescription());328 if (newScenario) {329 getContext().setTable(330 dataTableFrom(SCENARIO_OUTLINE_NOT_KNOWN_YET,331 headers,332 rows,333 exampleTableName,334 exampleTableDescription,335 lineNumbersOfEachRow));336 } else {337 getContext().addTableRows(headers,338 rows,339 exampleTableName,340 exampleTableDescription,341 lineNumbersOfEachRow);342 }343 getContext().addTableTags(tagsIn(examples));344 getContext().currentScenarioId = scenarioId;345 }346 }347 }348 @NotNull349 private List<TestTag> tagsIn(Examples examples) {350 return examples.getTags().stream().map(tag -> TestTag.withValue(tag.getName().substring(1))).collect(Collectors.toList());351 }352 private boolean examplesAreNotExcludedByTags(Examples examples, List<Tag> scenarioOutlineTags, List<Tag> currentFeatureTags) {353 if (testRunHasFilterTags()) {354 return examplesMatchFilter(examples, scenarioOutlineTags, currentFeatureTags);355 }356 return true;357 }358 private boolean examplesMatchFilter(Examples examples, List<Tag> scenarioOutlineTags, List<Tag> currentFeatureTags) {359 List<Tag> allExampleTags = getExampleAllTags(examples, scenarioOutlineTags, currentFeatureTags);360 List<String> allTagsForAnExampleScenario = allExampleTags.stream().map(Tag::getName).collect(Collectors.toList());361 String TagValuesFromCucumberOptions = getCucumberRuntimeTags().get(0);362 TagExpressionParser parser = new TagExpressionParser();363 Expression expressionNode = parser.parse(TagValuesFromCucumberOptions);364 return expressionNode.evaluate(allTagsForAnExampleScenario);365 }366 private boolean testRunHasFilterTags() {367 List<String> tagFilters = getCucumberRuntimeTags();368 return (tagFilters != null) && tagFilters.size() > 0;369 }370 private List<String> getCucumberRuntimeTags() {371 if (CucumberWithSerenity.currentRuntimeOptions() == null) {372 return new ArrayList<>();373 } else {374 return CucumberWithSerenity.currentRuntimeOptions().getTagFilters();375 }376 }377 private List<Tag> getExampleAllTags(Examples examples, List<Tag> scenarioOutlineTags, List<Tag> currentFeatureTags) {378 List<Tag> exampleTags = examples.getTags();379 List<Tag> allTags = new ArrayList<>();380 if (exampleTags != null)381 allTags.addAll(exampleTags);382 if (scenarioOutlineTags != null)383 allTags.addAll(scenarioOutlineTags);384 if (currentFeatureTags != null)385 allTags.addAll(currentFeatureTags);386 return allTags;387 }388 private List<String> getHeadersFrom(TableRow headerRow) {389 return headerRow.getCells().stream().map(TableCell::getValue).collect(Collectors.toList());390 }391 private List<Map<String, String>> getValuesFrom(List<TableRow> examplesTableRows, List<String> headers) {392 List<Map<String, String>> rows = new ArrayList<>();393 for (int row = 0; row < examplesTableRows.size(); row++) {394 Map<String, String> rowValues = new HashMap<>();395 int column = 0;396 List<String> cells = examplesTableRows.get(row).getCells().stream().map(TableCell::getValue).collect(Collectors.toList());397 for (String cellValue : cells) {398 String columnName = headers.get(column++);399 rowValues.put(columnName, cellValue);400 }401 rows.add(rowValues);402 }403 return rows;404 }405 private void addRow(Map<Integer, Map<String, String>> exampleRows,406 List<String> headers,407 TableRow currentTableRow) {408 Map<String, String> row = new LinkedHashMap<>();409 for (int j = 0; j < headers.size(); j++) {410 List<String> cells = currentTableRow.getCells().stream().map(TableCell::getValue).collect(Collectors.toList());411 row.put(headers.get(j), cells.get(j));412 }413 exampleRows().put(currentTableRow.getLocation().getLine(), row);414 }415 private String scenarioIdFrom(String featureId, String scenarioIdOrExampleId) {416 return (featureId != null && scenarioIdOrExampleId != null) ? String.format("%s;%s", featureId, scenarioIdOrExampleId) : "";417 }418 private void initializeExamples() {419 getContext().setExamplesRunning(true);420 }421 private Map<Integer, Map<String, String>> exampleRows() {422 if (getContext().exampleRows == null) {423 getContext().exampleRows = Collections.synchronizedMap(new HashMap<>());424 }425 return getContext().exampleRows;426 }427 private Map<Integer, List<Tag>> exampleTags() {428 if (getContext().exampleTags == null) {429 getContext().exampleTags = Collections.synchronizedMap(new HashMap<>());430 }431 return getContext().exampleTags;432 }433 private DataTable dataTableFrom(String scenarioOutline,434 List<String> headers,435 List<Map<String, String>> rows,436 String name,437 String description,438 Map<Integer, Integer> lineNumbersOfEachRow) {439 return DataTable.withHeaders(headers)440 .andScenarioOutline(scenarioOutline)441 .andMappedRows(rows, lineNumbersOfEachRow)442 .andTitle(name)443 .andDescription(description)444 .build();445 }446 private DataTable addTableRowsTo(DataTable table, List<String> headers,447 List<Map<String, String>> rows,448 String name,449 String description) {450 table.startNewDataSet(name, description);451 for (Map<String, String> row : rows) {452 table.appendRow(rowValuesFrom(headers, row));453 }454 return table;455 }456 private List<String> rowValuesFrom(List<String> headers, Map<String, String> row) {457 return headers.stream()458 .map(header -> row.get(header))459 .collect(toList());460 }461 private void startOfScenarioLifeCycle(Feature feature, String scenarioName, ScenarioDefinition scenario, Integer currentLine) {462 boolean newScenario = !scenarioIdFrom(TestSourcesModel.convertToId(feature.getName()), TestSourcesModel.convertToId(scenario.getName())).equals(getContext().currentScenario);463 getContext().currentScenario = scenarioIdFrom(TestSourcesModel.convertToId(feature.getName()), TestSourcesModel.convertToId(scenario.getName()));464 if (getContext().examplesAreRunning()) {465 if (newScenario) {466 startScenario(feature, scenario, scenario.getName());467 getContext().stepEventBus().useExamplesFrom(getContext().getTable());468 getContext().stepEventBus().useScenarioOutline(ScenarioOutlineDescription.from(scenario).getDescription());469 } else {470 getContext().stepEventBus().addNewExamplesFrom(getContext().getTable());471 }472 startExample(currentLine);473 } else {474 startScenario(feature, scenario, scenarioName);475 }476 }477 private void startScenario(Feature currentFeature, ScenarioDefinition scenarioDefinition, String scenarioName) {478 getContext().stepEventBus().setTestSource(TestSourceType.TEST_SOURCE_CUCUMBER.getValue());479 getContext().stepEventBus().testStarted(scenarioName,480 scenarioIdFrom(TestSourcesModel.convertToId(currentFeature.getName()), TestSourcesModel.convertToId(scenarioName)));481 getContext().stepEventBus().addDescriptionToCurrentTest(scenarioDefinition.getDescription());482 getContext().stepEventBus().addTagsToCurrentTest(convertCucumberTags(currentFeature.getTags()));483 if (isScenario(scenarioDefinition)) {484 getContext().stepEventBus().addTagsToCurrentTest(convertCucumberTags(((Scenario) scenarioDefinition).getTags()));485 } else if (isScenarioOutline(scenarioDefinition)) {486 getContext().stepEventBus().addTagsToCurrentTest(convertCucumberTags(((ScenarioOutline) scenarioDefinition).getTags()));487 }488 registerFeatureJiraIssues(currentFeature.getTags());489 List<Tag> tags = getTagsOfScenarioDefinition(scenarioDefinition);490 registerScenarioJiraIssues(tags);491 scenarioTags = tagsForScenario(scenarioDefinition);492 updateResultFromTags(scenarioTags);493 }494 private List<Tag> tagsForScenario(ScenarioDefinition scenarioDefinition) {495 List<Tag> scenarioTags = new ArrayList<>(getContext().featureTags);496 scenarioTags.addAll(getTagsOfScenarioDefinition(scenarioDefinition));497 return scenarioTags;498 }499 private boolean isScenario(ScenarioDefinition scenarioDefinition) {500 return scenarioDefinition instanceof Scenario;501 }502 private boolean isScenarioOutline(ScenarioDefinition scenarioDefinition) {503 return scenarioDefinition instanceof ScenarioOutline;504 }505 private List<Tag> getTagsOfScenarioDefinition(ScenarioDefinition scenarioDefinition) {506 List<Tag> tags = new ArrayList<>();507 if (isScenario(scenarioDefinition)) {508 tags = ((Scenario) scenarioDefinition).getTags();509 } else if (isScenarioOutline(scenarioDefinition)) {510 tags = ((ScenarioOutline) scenarioDefinition).getTags();511 }512 return tags;513 }514 private void registerFeatureJiraIssues(List<Tag> tags) {515 List<String> issues = extractJiraIssueTags(tags);516 if (!issues.isEmpty()) {517 getContext().stepEventBus().addIssuesToCurrentStory(issues);518 }519 }520 private void registerScenarioJiraIssues(List<Tag> tags) {521 List<String> issues = extractJiraIssueTags(tags);522 if (!issues.isEmpty()) {523 getContext().stepEventBus().addIssuesToCurrentTest(issues);524 }525 }526 private List<TestTag> convertCucumberTags(List<Tag> cucumberTags) {527 cucumberTags = completeManualTagsIn(cucumberTags);528 return cucumberTags.stream()529 .map(tag -> TestTag.withValue(tag.getName().substring(1)))530 .collect(toList());531 }532 private List<Tag> completeManualTagsIn(List<Tag> cucumberTags) {533 if (unqualifiedManualTag(cucumberTags).isPresent() && doesNotContainResultTag(cucumberTags)) {534 List<Tag> updatedTags = Lists.newArrayList(cucumberTags);535 updatedTags.add(new Tag(unqualifiedManualTag(cucumberTags).get().getLocation(), "@manual:pending"));536 return updatedTags;537 } else {538 return cucumberTags;539 }540 }541 private boolean doesNotContainResultTag(List<Tag> tags) {542 return !tags.stream().noneMatch(tag -> tag.getName().startsWith("@manual:"));543 }544 private Optional<Tag> unqualifiedManualTag(List<Tag> tags) {545 return tags.stream().filter(tag -> tag.getName().equalsIgnoreCase("@manual")).findFirst();546 }547 private List<String> extractJiraIssueTags(List<Tag> cucumberTags) {548 List<String> issues = new ArrayList<>();549 for (Tag tag : cucumberTags) {550 if (tag.getName().startsWith("@issue:")) {551 String tagIssueValue = tag.getName().substring("@issue:".length());552 issues.add(tagIssueValue);553 }554 if (tag.getName().startsWith("@issues:")) {555 String tagIssuesValues = tag.getName().substring("@issues:".length());556 issues.addAll(Arrays.asList(tagIssuesValues.split(",")));557 }558 }559 return issues;560 }561 private void startExample(Integer lineNumber) {562 Map<String, String> data = exampleRows().get(lineNumber);563 getContext().stepEventBus().clearStepFailures();564 getContext().stepEventBus().exampleStarted(data);565 if (exampleTags().containsKey(lineNumber)) {566 List<Tag> currentExampleTags = exampleTags().get(lineNumber);567 getContext().stepEventBus().addTagsToCurrentTest(convertCucumberTags(currentExampleTags));568 }569 }570 private void finishExample() {571 getContext().stepEventBus().exampleFinished();572 getContext().exampleCount--;573 if (getContext().exampleCount == 0) {574 getContext().setExamplesRunning(false);575 setTableScenarioOutline();576 } else {577 getContext().setExamplesRunning(true);578 }579 }580 private void setTableScenarioOutline() {581 List<Step> steps = getContext().currentScenarioDefinition.getSteps();582 StringBuffer scenarioOutlineBuffer = new StringBuffer();583 for (Step step : steps) {584 scenarioOutlineBuffer.append(step.getKeyword()).append(step.getText()).append("\n\r");585 }586 String scenarioOutline = scenarioOutlineBuffer.toString();587 if (getContext().getTable() != null) {588 getContext().getTable().setScenarioOutline(scenarioOutline);589 }590 }591 private void handleBackground(Background background) {592 getContext().waitingToProcessBackgroundSteps = true;593 String backgroundName = background.getName();594 if (backgroundName != null) {595 getContext().stepEventBus().setBackgroundTitle(backgroundName);596 }597 String backgroundDescription = background.getDescription();598 if (backgroundDescription == null) {599 backgroundDescription = "";600 }601 getContext().stepEventBus().setBackgroundDescription(backgroundDescription);602 }603 private void assureTestSuiteFinished() {604 getContext().clearStepQueue();605 getContext().clearTestStepQueue();606 Optional.ofNullable(getContext().currentFeaturePath()).ifPresent(607 featurePath -> {608 getStepEventBus(featurePath).testSuiteFinished();609 getStepEventBus(featurePath).dropAllListeners();610 getStepEventBus(featurePath).clear();611 StepEventBus.clearEventBusFor(featurePath);612 }613 );614 Serenity.done();615 getContext().clearTable();616 getContext().currentScenarioId = null;617 }618 private void handleResult(Result result) {619 Step currentStep = getContext().nextStep();620 cucumber.api.TestStep currentTestStep = getContext().nextTestStep();621 recordStepResult(result, currentStep, currentTestStep);622 if (getContext().noStepsAreQueued()) {623 recordFinalResult();624 }625 }626 private void recordStepResult(Result result, Step currentStep, cucumber.api.TestStep currentTestStep) {627 if (getContext().stepEventBus().currentTestIsSuspended()) {628 getContext().stepEventBus().stepIgnored();629 } else if (Result.Type.PASSED.equals(result.getStatus())) {630 getContext().stepEventBus().stepFinished();631 } else if (Result.Type.FAILED.equals(result.getStatus())) {632 failed(stepTitleFrom(currentStep, currentTestStep), result.getError());633 } else if (Result.Type.SKIPPED.equals(result.getStatus())) {634 getContext().stepEventBus().stepIgnored();635 } else if (Result.Type.PENDING.equals(result.getStatus())) {636 getContext().stepEventBus().stepPending();637 } else if (Result.Type.UNDEFINED.equals(result.getStatus())) {638 getContext().stepEventBus().stepPending();639 }640 }641 private void recordFinalResult() {642 if (getContext().waitingToProcessBackgroundSteps) {643 getContext().waitingToProcessBackgroundSteps = false;644 } else {645 updateResultFromTags(scenarioTags);646 }647 }648 private void updateResultFromTags(List<Tag> scenarioTags) {649 if (isManual(scenarioTags)) {650 updateManualResultsFrom(scenarioTags);651 } else if (isPending(scenarioTags)) {652 getContext().stepEventBus().testPending();653 } else if (isSkippedOrWIP(scenarioTags)) {654 getContext().stepEventBus().testSkipped();655 updateCurrentScenarioResultTo(TestResult.SKIPPED);656 } else if (isIgnored(scenarioTags)) {657 getContext().stepEventBus().testIgnored();658 updateCurrentScenarioResultTo(TestResult.IGNORED);659 }660 }661 private void updateManualResultsFrom(List<Tag> scenarioTags) {662 getContext().stepEventBus().testIsManual();663 manualResultDefinedIn(scenarioTags).ifPresent(664 testResult ->665 UpdateManualScenario.forScenario(getContext().currentScenarioDefinition.getDescription())666 .inContext(getContext().stepEventBus().getBaseStepListener(), systemConfiguration.getEnvironmentVariables())667 .updateManualScenario(testResult, scenarioTags)668 );669 }670 private void updateCurrentScenarioResultTo(TestResult pending) {671 getContext().stepEventBus().getBaseStepListener().overrideResultTo(pending);672 }673 private void failed(String stepTitle, Throwable cause) {674 if (!errorOrFailureRecordedForStep(stepTitle, cause)) {675 if (!isEmpty(stepTitle)) {676 getContext().stepEventBus().updateCurrentStepTitle(stepTitle);677 }678 Throwable rootCause = new RootCauseAnalyzer(cause).getRootCause().toException();679 if (isAssumptionFailure(rootCause)) {680 getContext().stepEventBus().assumptionViolated(rootCause.getMessage());681 } else {682 getContext().stepEventBus().stepFailed(new StepFailure(ExecutedStepDescription.withTitle(normalized(currentStepTitle())), rootCause));683 }684 }685 }686 private String currentStepTitle() {687 return getContext().stepEventBus().getCurrentStep().isPresent()688 ? getContext().stepEventBus().getCurrentStep().get().getDescription() : "";689 }690 private boolean errorOrFailureRecordedForStep(String stepTitle, Throwable cause) {691 if (!latestTestOutcome().isPresent()) {692 return false;693 }694 if (!latestTestOutcome().get().testStepWithDescription(stepTitle).isPresent()) {695 return false;696 }697 Optional<TestStep> matchingTestStep = latestTestOutcome().get().testStepWithDescription(stepTitle);698 if (matchingTestStep.isPresent() && matchingTestStep.get().getException() != null) {699 return (matchingTestStep.get().getException().getOriginalCause() == cause);700 }701 return false;702 }...
Source:ScenarioOutlineDescription.java
...11 }12 public static ScenarioOutlineDescription from(ScenarioDefinition scenario) {13 return new ScenarioOutlineDescription(scenario);14 }15 public String getDescription() {16 return scenario.getSteps().stream().map(17 step -> stepToString(step)18 ).collect(Collectors.joining(System.lineSeparator()));19 }20 private String stepToString(Step step) {21 String phrase = step.getKeyword() + step.getText();22 if ((step.getArgument() != null) && (step.getArgument().getClass().isAssignableFrom(gherkin.ast.DataTable.class))) {23 gherkin.ast.DataTable table = (gherkin.ast.DataTable) step.getArgument();24 String tableAsString = "";25 for (TableRow row : table.getRows()) {26 tableAsString += "|";27 tableAsString += row.getCells().stream()28 .map(TableCell::getValue)29 .collect(Collectors.joining(" | "));...
getDescription
Using AI Code Generation
1import net.serenitybdd.cucumber.CucumberWithSerenity2import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription3import java.util.regex.Pattern4import static net.serenitybdd.cucumber.CucumberWithSerenity.toHtml5public class SerenityRunner extends CucumberWithSerenity {6 public SerenityRunner(Class clazz) throws Throwable {7 super(clazz);8 }9 protected String scenarioOutlineDescription(String description, String keyword, String name, Integer line) {10 return ScenarioOutlineDescription.getDescription(description, keyword, name, line);11 }12}13import net.serenitybdd.cucumber.CucumberWithSerenity14import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription15import java.util.regex.Pattern16import static net.serenitybdd.cucumber.CucumberWithSerenity.toHtml17public class SerenityRunner extends CucumberWithSerenity {18 public SerenityRunner(Class clazz) throws Throwable {19 super(clazz);20 }21 protected String scenarioOutlineDescription(String description, String keyword, String name, Integer line) {22 String scenarioOutlineDescription = ScenarioOutlineDescription.getDescription(description, keyword, name, line);23 return scenarioOutlineDescription.isEmpty() ? super.scenarioOutlineDescription(description, keyword, name, line) : scenarioOutlineDescription;24 }25}26import net.serenitybdd.cucumber.CucumberWithSerenity27import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription28import java.util.regex
getDescription
Using AI Code Generation
1package steps;2import cucumber.api.java.en.Then;3import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription;4import net.thucydides.core.annotations.Steps;5public class StepDefinitions {6 private MySteps mySteps;7 @Then("I do something")8 public void iDoSomething() {9 mySteps.doSomething(ScenarioOutlineDescription.getDescription());10 }11}12package net.serenitybdd.cucumber.formatting;13import cucumber.runtime.model.CucumberScenarioOutline;14import gherkin.formatter.model.ScenarioOutline;15public class ScenarioOutlineDescription {16 public static String getDescription() {17 return getScenarioOutline().getDescription();18 }19 private static CucumberScenarioOutline getScenarioOutline() {20 return (CucumberScenarioOutline) CucumberScenarioOutline.getThreadLocal();21 }22}23package steps;24import net.thucydides.core.annotations.Step;25public class MySteps {26 public void doSomething(String description) {27 System.out.println(description);28 }29}
getDescription
Using AI Code Generation
1 if (features.getFeatureCount() > 0) {2 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);3 if (description != null) {4 testOutcome.setDescription(description);5 }6 }7 if (features.getFeatureCount() > 0) {8 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);9 if (description != null) {10 testOutcome.setDescription(description);11 }12 }13 if (features.getFeatureCount() > 0) {14 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);15 if (description != null) {16 testOutcome.setDescription(description);17 }18 }19 if (features.getFeatureCount() > 0) {20 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);21 if (description != null) {22 testOutcome.setDescription(description);23 }24 }25 if (features.getFeatureCount() > 0) {26 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);27 if (description != null) {28 testOutcome.setDescription(description);29 }30 }31 if (features.getFeatureCount() > 0) {32 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);33 if (description != null) {34 testOutcome.setDescription(description);35 }36 }37 if (features.getFeatureCount() > 0) {38 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);39 if (description != null) {40 testOutcome.setDescription(description);41 }42 }43 if (features.getFeatureCount() > 0) {44 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);45 if (description != null) {46 testOutcome.setDescription(description);47 }48 }49 if (features.getFeatureCount() > 0) {50 String description = ScenarioOutlineDescription.getDescription(currentFeature, scenario);51 if (description
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!!