How to use ScenarioOutlineDescription class of net.serenitybdd.cucumber.formatting package

Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription

Source:SerenityReporter.java Github

copy

Full Screen

...14import net.serenitybdd.core.Serenity;15import net.serenitybdd.core.SerenityListeners;16import net.serenitybdd.core.SerenityReports;17import net.serenitybdd.cucumber.CucumberWithSerenity;18import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription;19import net.thucydides.core.guice.Injectors;20import net.thucydides.core.model.DataTable;21import net.thucydides.core.model.*;22import net.thucydides.core.model.TestStep;23import net.thucydides.core.model.stacktrace.RootCauseAnalyzer;24import net.thucydides.core.reports.ReportService;25import net.thucydides.core.steps.*;26import net.thucydides.core.util.Inflector;27import net.thucydides.core.webdriver.Configuration;28import net.thucydides.core.webdriver.ThucydidesWebDriverSupport;29import org.jetbrains.annotations.NotNull;30import org.junit.internal.AssumptionViolatedException;31import org.slf4j.Logger;32import org.slf4j.LoggerFactory;33import java.io.File;34import java.util.*;35import java.util.stream.Collectors;36import static cucumber.runtime.formatter.TaggedScenario.*;37import static java.util.stream.Collectors.toList;38import static org.apache.commons.lang3.StringUtils.isEmpty;39import static org.apache.commons.lang3.StringUtils.isNotEmpty;40/**41 * Cucumber Formatter for Serenity.42 *43 * @author L.Carausu (liviu.carausu@gmail.com)44 */45public class SerenityReporter implements Plugin, ConcurrentEventListener {46 private static final String OPEN_PARAM_CHAR = "\uff5f";47 private static final String CLOSE_PARAM_CHAR = "\uff60";48 private static final String SCENARIO_OUTLINE_NOT_KNOWN_YET = "";49 private Configuration systemConfiguration;50 private final List<BaseStepListener> baseStepListeners;51 private final static String FEATURES_ROOT_PATH = "features";52 private FeatureFileLoader featureLoader = new FeatureFileLoader();53 private LineFilters lineFilters;54 private List<Tag> scenarioTags;55 private static final Logger LOGGER = LoggerFactory.getLogger(SerenityReporter.class);56 private ManualScenarioChecker manualScenarioDateChecker;57 private ThreadLocal<ScenarioContext> localContext = ThreadLocal.withInitial(ScenarioContext::new);58 private ScenarioContext getContext() {59 return localContext.get();60 }61 /**62 * Constructor automatically called by cucumber when class is specified as plugin63 * in @CucumberOptions.64 */65 public SerenityReporter() {66 this.systemConfiguration = Injectors.getInjector().getInstance(Configuration.class);67 this.manualScenarioDateChecker = new ManualScenarioChecker(systemConfiguration.getEnvironmentVariables());68 baseStepListeners = Collections.synchronizedList(new ArrayList<>());69 lineFilters = LineFilters.forCurrentContext();70 }71 public SerenityReporter(Configuration systemConfiguration, ResourceLoader resourceLoader) {72 this.systemConfiguration = systemConfiguration;73 this.manualScenarioDateChecker = new ManualScenarioChecker(systemConfiguration.getEnvironmentVariables());74 baseStepListeners = Collections.synchronizedList(new ArrayList<>());75 lineFilters = LineFilters.forCurrentContext();76 }77 private FeaturePathFormatter featurePathFormatter = new FeaturePathFormatter();78 private StepEventBus getStepEventBus(String featurePath) {79 String prefixedPath = featurePathFormatter.featurePathWithPrefixIfNecessary(featurePath);80 return StepEventBus.eventBusFor(prefixedPath);81 }82 private void setStepEventBus(String featurePath) {83 String prefixedPath = featurePathFormatter.featurePathWithPrefixIfNecessary(featurePath);84 StepEventBus.setCurrentBusToEventBusFor(prefixedPath);85 }86 private void initialiseListenersFor(String featurePath) {87 if (getStepEventBus(featurePath).isBaseStepListenerRegistered()) {88 return;89 }90 SerenityListeners listeners = new SerenityListeners(getStepEventBus(featurePath), systemConfiguration);91 baseStepListeners.add(listeners.getBaseStepListener());92 }93 private EventHandler<TestSourceRead> testSourceReadHandler = this::handleTestSourceRead;94 private EventHandler<TestCaseStarted> caseStartedHandler = this::handleTestCaseStarted;95 private EventHandler<TestCaseFinished> caseFinishedHandler = this::handleTestCaseFinished;96 private EventHandler<TestStepStarted> stepStartedHandler = this::handleTestStepStarted;97 private EventHandler<TestStepFinished> stepFinishedHandler = this::handleTestStepFinished;98 private EventHandler<TestRunStarted> runStartedHandler = this::handleTestRunStarted;99 private EventHandler<TestRunFinished> runFinishedHandler = this::handleTestRunFinished;100 private EventHandler<WriteEvent> writeEventHandler = this::handleWrite;101 private void handleTestRunStarted(TestRunStarted event) {102 }103 @Override104 public void setEventPublisher(EventPublisher publisher) {105 publisher.registerHandlerFor(TestSourceRead.class, testSourceReadHandler);106 publisher.registerHandlerFor(TestRunStarted.class, runStartedHandler);107 publisher.registerHandlerFor(TestRunFinished.class, runFinishedHandler);108 publisher.registerHandlerFor(TestCaseStarted.class, caseStartedHandler);109 publisher.registerHandlerFor(TestCaseFinished.class, caseFinishedHandler);110 publisher.registerHandlerFor(TestStepStarted.class, stepStartedHandler);111 publisher.registerHandlerFor(TestStepFinished.class, stepFinishedHandler);112 publisher.registerHandlerFor(WriteEvent.class, writeEventHandler);113 }114 private void handleTestSourceRead(TestSourceRead event) {115 featureLoader.addTestSourceReadEvent(event.uri, event);116 String featurePath = event.uri;117 featureFrom(featurePath).ifPresent(118 feature -> {119 getContext().setFeatureTags(feature.getTags());120 resetEventBusFor(featurePath);121 initialiseListenersFor(featurePath);122 configureDriver(feature, featurePath);123 Story userStory = userStoryFrom(feature, relativeUriFrom(event.uri));124 getStepEventBus(event.uri).testSuiteStarted(userStory);125 }126 );127 }128 private void resetEventBusFor(String featurePath) {129 StepEventBus.clearEventBusFor(featurePath);130 }131 private String relativeUriFrom(String fullPathUri) {132 String featuresRoot = File.separatorChar + FEATURES_ROOT_PATH + File.separatorChar;133 if (fullPathUri.contains(featuresRoot)) {134 return fullPathUri.substring(fullPathUri.lastIndexOf(featuresRoot) + FEATURES_ROOT_PATH.length() + 2);135 } else {136 return fullPathUri;137 }138 }139 private Optional<Feature> featureFrom(String featureFileUri) {140 String defaultFeatureId = new File(featureFileUri).getName().replace(".feature", "");141 String defaultFeatureName = Inflector.getInstance().humanize(defaultFeatureId);142 parseGherkinIn(featureFileUri);143 if (isEmpty(featureLoader.getFeatureName(featureFileUri))) {144 return Optional.empty();145 }146 Feature feature = featureLoader.getFeature(featureFileUri);147 if (feature.getName().isEmpty()) {148 feature = featureLoader.featureWithDefaultName(feature, defaultFeatureName);149 }150 return Optional.of(feature);151 }152 private void parseGherkinIn(String featureFileUri) {153 try {154 featureLoader.getFeature(featureFileUri);155 } catch (Throwable ignoreParsingErrors) {156 LOGGER.warn("Could not parse the Gherkin in feature file " + featureFileUri + ": file ignored");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()));...

Full Screen

Full Screen

Source:ScenarioOutlineDescription.java Github

copy

Full Screen

...3import gherkin.ast.Step;4import gherkin.ast.TableCell;5import gherkin.ast.TableRow;6import java.util.stream.Collectors;7public class ScenarioOutlineDescription {8 private final ScenarioDefinition scenario;9 public ScenarioOutlineDescription(ScenarioDefinition scenario) {10 this.scenario = scenario;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()...

Full Screen

Full Screen

ScenarioOutlineDescription

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription;2import net.thucydides.core.model.TestOutcome;3import net.thucydides.core.reports.adaptors.xunit.model.TestCase;4import net.thucydides.core.reports.adaptors.xunit.model.TestSuite;5import net.thucydides.core.reports.adaptors.xunit.model.TestSuites;6import net.thucydides.core.reports.adaptors.xunit.model.TestSuitesFactory;7import net.thucydides.core.reports.xml.XMLTestOutcomeReporter;8import net.thucydides.core.util.EnvironmentVariables;9import org.apache.commons.lang3.StringUtils;10import java.io.File;11import java.io.IOException;12import java.util.ArrayList;13import java.util.List;14public class CustomXMLTestOutcomeReporter extends XMLTestOutcomeReporter {15 public CustomXMLTestOutcomeReporter(EnvironmentVariables environmentVariables) {16 super(environmentVariables);17 }18 protected TestSuites createTestSuites(TestOutcome testOutcome) {19 TestSuitesFactory factory = new TestSuitesFactory();20 TestSuite testSuite = factory.createTestSuiteFor(testOutcome);21 TestCase testCase = factory.createTestCaseFor(testOutcome);22 testCase.setClassName(testOutcome.getTestSource());23 testCase.setName(testOutcome.getTitle());24 testCase.setDurationMillis(testOutcome.getDuration().in(TimeUnit.MILLISECONDS));25 testCase.setStdOut(testOutcome.getTestFailureCause());26 testCase.setStdErr(testOutcome.getTestFailureCause());27 if (testOutcome.isDataDriven()) {28 testCase.setName(testOutcome.getStoryTitle());29 testCase.setClassName(testOutcome.getStoryTitle());30 List<ScenarioOutlineDescription> scenarioOutlineDescriptions = new ArrayList<>();31 for (String scenarioTitle : testOutcome.getScenarioTitles()) {32 scenarioOutlineDescriptions.add(new ScenarioOutlineDescription(scenarioTitle));33 }34 testCase.setScenarioOutlineDescriptions(scenarioOutlineDescriptions);35 }36 testSuite.addTestCase(testCase);37 TestSuites testSuites = new TestSuites();38 testSuites.addTestSuite(testSuite);39 return testSuites;40 }41 public void generateReportsFor(TestOutcome testOutcome, File outputDirectory) throws IOException {42 TestSuites testSuites = createTestSuites(testOutcome);43 String reportName = getReportName(testOutcome);44 File reportFile = new File(outputDirectory, reportName);45 testSuites.writeTo(reportFile);46 }

Full Screen

Full Screen

ScenarioOutlineDescription

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.formatting.ScenarioOutlineDescription2import net.thucydides.core.model.TestOutcome3import net.thucydides.core.model.TestResult4import net.thucydides.core.model.TestStep5import java.util.stream.Collectors6class ScenarioOutlineDescription {7 def static String description(TestOutcome testOutcome) {8 def exampleRow = scenarioOutlineExamples.getExampleRow(scenarioOutlineExample)9 def exampleValues = exampleRow.getValues()10 def parameterNames = scenarioOutline.getParameters()11 def parameterValues = exampleValues.stream().map({ it.toString() }).collect(Collectors.toList())12 def description = scenarioOutline.getDescription()13 def descriptionWithParameters = replaceParameters(description, parameterNames, parameterValues)14 }15 def static String replaceParameters(String description, List<String> parameterNames, List<String> parameterValues) {16 for (int i = 0; i < parameterNames.size(); i++) {17 result = result.replaceAll("<" + parameterNames.get(i) + ">", parameterValues.get(i))18 }19 }20}21import net.serenitybdd.cucumber.CucumberWithSerenity22import net.thucydides.core.model.TestOutcome23import net.thucydides.core.model.TestResult24import net.thucydides.core.model.TestStep25import org.junit.runner.RunWith26@RunWith(CucumberWithSerenity.class)27@CucumberOptions(28public class TestRunner {29 public void afterScenario(Scenario scenario) {30 TestOutcome testOutcome = Serenity.getCurrentSession().get(TestOutcome.class);31 String description = ScenarioOutlineDescription.description(testOutcome);32 testOutcome.setDescription(description);33 }34}

Full Screen

Full Screen

ScenarioOutlineDescription

Using AI Code Generation

copy

Full Screen

1package com.automationpractice.stepdefinitions;2import cucumber.api.java.en.Given;3import cucumber.api.java.en.Then;4import cucumber.api.java.en.When;5import net.serenitybdd.cucumber.CucumberWithSerenity;6import net.serenitybdd.cucumber.CucumberWithSerenity.ScenarioOutlineDescription;7import net.thucydides.core.annotations.Steps;8import com.automationpractice.steps.LoginSteps;9public class LoginStepDefinitions {10LoginSteps loginSteps;11@Given("^I am on the login page$")12public void i_am_on_the_login_page() {13loginSteps.openLoginPage();14}15@When("^I enter valid credentials$")16public void i_enter_valid_credentials() {17loginSteps.enterValidCredentials();18}19@Then("^I should be logged into the application$")20public void i_should_be_logged_into_the_application() {21loginSteps.verifyLogin();22}23@When("^I enter invalid credentials$")24public void i_enter_invalid_credentials() {25loginSteps.enterInvalidCredentials();26}27@Then("^I should see an error message$")28public void i_should_see_an_error_message() {29loginSteps.verifyErrorMessage();30}31@When("^I enter valid credentials and click on \"([^\"]*)\"$")32public void i_enter_valid_credentials_and_click_on(ScenarioOutlineDescription button) {33loginSteps.enterValidCredentialsAndClickOn(button);34}35@Then("^I should see \"([^\"]*)\" page$")36public void i_should_see_page(ScenarioOutlineDescription page) {37loginSteps.verifyPage(page);38}39}40package com.automationpractice.steps;41import com.automationpractice.pages.LoginPage;42import com.automationpractice.pages.MyAccountPage;43import net.thucydides.core.annotations.Step;44import net.thucydides.core.annotations.Steps;45public class LoginSteps {46LoginPage loginPage;47MyAccountPage myAccountPage;48public void openLoginPage() {49loginPage.open();50}51public void enterValidCredentials() {52loginPage.enterCredentials("

Full Screen

Full Screen

ScenarioOutlineDescription

Using AI Code Generation

copy

Full Screen

1import cucumber.api.java.en.Given;2import cucumber.api.java.en.Then;3import cucumber.api.java.en.When;4import cucumber.api.java.en.And;5public class StepDefinitions {6 @Given("^the user is on the login page$")7 public void the_user_is_on_the_login_page() throws Throwable {8 throw new PendingException();9 }10 @When("^the user enters correct credentials$")11 public void the_user_enters_correct_credentials() throws Throwable {12 throw new PendingException();13 }14 @Then("^the user should be able to login successfully$")15 public void the_user_should_be_able_to_login_successfully() throws Throwable {16 throw new PendingException();17 }18 @Given("^the user is on the home page$")19 public void the_user_is_on_the_home_page() throws Throwable {20 throw new PendingException();21 }22 @When("^the user clicks on the logout button$")23 public void the_user_clicks_on_the_logout_button() throws Throwable {24 throw new PendingException();25 }26 @Then("^the user should be able to logout successfully$")27 public void the_user_should_be_able_to_logout_successfully() throws Throwable {28 throw new PendingException();29 }30 @And("^the user should be able to see the welcome message$")31 public void the_user_should_be_able_to_see_the_welcome_message() throws Throwable {32 throw new PendingException();33 }34 @And("^the user should be able to see the login page$")35 public void the_user_should_be_able_to_see_the_login_page() throws Throwable {36 throw new PendingException();37 }38}

Full Screen

Full Screen

ScenarioOutlineDescription

Using AI Code Generation

copy

Full Screen

1package com.automationpractice.steps;2import cucumber.api.java.en.Given;3import net.serenitybdd.cucumber.CucumberWithSerenity;4import net.serenitybdd.cucumber.suiteslicing.CucumberScenarioOutlineDescription;5import net.thucydides.core.annotations.Steps;6import org.junit.runner.RunWith;7@RunWith(CucumberWithSerenity.class)8public class StepDefinitions {9 private ScenarioSteps scenarioSteps;10 @Given("^I am on the automation practice website$")11 public void iAmOnTheAutomationPracticeWebsite() {12 scenarioSteps.iAmOnTheAutomationPracticeWebsite();13 }14 @Given("^I add a \"([^\"]*)\" to the cart$")15 public void iAddAToTheCart(String item) {16 scenarioSteps.iAddAToTheCart(item);17 }18 @Given("^I proceed to checkout$")19 public void iProceedToCheckout() {20 scenarioSteps.iProceedToCheckout();21 }22 @Given("^I proceed to checkout with \"([^\"]*)\"$")23 public void iProceedToCheckoutWith(String item) {24 scenarioSteps.iProceedToCheckoutWith(item);25 }26 @Given("^I sign in with \"([^\"]*)\" and \"([^\"]*)\"$")27 public void iSignInWithAnd(String email, String password) {28 scenarioSteps.iSignInWithAnd(email, password);29 }30 @Given("^I sign out$")31 public void iSignOut() {32 scenarioSteps.iSignOut();33 }34 @Given("^I update the quantity of \"([^\"]*)\" to \"([^\"]*)\"$")35 public void iUpdateTheQuantityOfTo(String item, String quantity) {36 scenarioSteps.iUpdateTheQuantityOfTo(item, quantity);37 }38 @Given("^I verify that the \"([^\"]*)\" is in the cart$")39 public void iVerifyThatTheIsInTheCart(String item) {40 scenarioSteps.iVerifyThatTheIsInTheCart(item);41 }42 @Given("^I verify that the total is \"([^\"]*)\"$")43 public void iVerifyThatTheTotalIs(String total) {44 scenarioSteps.iVerifyThatTheTotalIs(total);45 }46 @Given("^I verify that the total is \"([^\"]*)\" with \"([^\"]*)\"$")47 public void iVerifyThatTheTotalIsWith(String total, String item) {

Full Screen

Full Screen

ScenarioOutlineDescription

Using AI Code Generation

copy

Full Screen

1import net.thucydides.core.model.TestOutcome;2import java.util.List;3public class CustomFormatter extends ScenarioOutlineDescription {4 public CustomFormatter() {5 super();6 }7 public void scenarioOutline(List<String> tags, String keyword, String name, String description, String uri, Integer line) {8 super.scenarioOutline(tags, keyword, name, description, uri, line);9 }10 public void examples(String name, String description, List<ExamplesTableRow> examplesTableRows) {11 super.examples(name, description, examplesTableRows);12 }13 public void example(Map<String, String> example) {14 super.example(example);15 }16 public void after(TestOutcome testOutcome) {17 super.after(testOutcome);18 }19}20import net.thucydides.core.model.TestOutcome;21import java.util.List;22public class CustomFormatter extends ScenarioOutlineDescription {23 public CustomFormatter() {24 super();25 }26 public void scenarioOutline(List<String> tags, String keyword, String name, String description, String uri, Integer line) {27 super.scenarioOutline(tags, keyword, name, description, uri, line);28 }29 public void examples(String name, String description, List<ExamplesTableRow> examplesTableRows) {30 super.examples(name, description, examplesTableRows);31 }32 public void example(Map<String, String> example) {33 super.example(example);34 }35 public void after(TestOutcome testOutcome) {36 super.after(testOutcome);37 }38}

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run Serenity Cucumber automation tests on LambdaTest cloud grid

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

Most used methods in ScenarioOutlineDescription

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful