How to use addStep method of com.tngtech.jgiven.report.model.ScenarioCaseModel class

Best JGiven code snippet using com.tngtech.jgiven.report.model.ScenarioCaseModel.addStep

Source:ScenarioModelBuilder.java Github

copy

Full Screen

...92 method.getParameterAnnotations());93 setArguments(parameterFormattingUtil.toStringList(formatter, getValues(namedArguments)));94 setCaseDescription(testClass, method, namedArguments);95 }96 private void addStepMethod(Method paramMethod, List<NamedArgument> arguments, InvocationMode mode,97 boolean hasNestedSteps) {98 StepModel stepModel = createStepModel(paramMethod, arguments, mode);99 if (parentSteps.empty()) {100 getCurrentScenarioCase().addStep(stepModel);101 } else {102 parentSteps.peek().addNestedStep(stepModel);103 }104 if (hasNestedSteps) {105 parentSteps.push(stepModel);106 discrepancyOnLayer.push(0);107 }108 currentStep = stepModel;109 }110 StepModel createStepModel(Method paramMethod, List<NamedArgument> arguments, InvocationMode mode) {111 StepModel stepModel = new StepModel();112 stepModel.setName(getDescription(paramMethod));113 ExtendedDescription extendedDescriptionAnnotation = paramMethod.getAnnotation(ExtendedDescription.class);114 if (extendedDescriptionAnnotation != null) {115 stepModel.setExtendedDescription(extendedDescriptionAnnotation.value());116 }117 List<NamedArgument> nonHiddenArguments =118 filterHiddenArguments(arguments, paramMethod.getParameterAnnotations());119 ParameterFormattingUtil parameterFormattingUtil = new ParameterFormattingUtil(configuration);120 List<ObjectFormatter<?>> formatters =121 parameterFormattingUtil.getFormatter(paramMethod.getParameterTypes(), getNames(arguments),122 paramMethod.getParameterAnnotations());123 new StepFormatter(stepModel.getName(), nonHiddenArguments, formatters).buildFormattedWords()124 .forEach(sentenceBuilder::addWord);125 stepModel.setWords(sentenceBuilder.getWords());126 sentenceBuilder.clear();127 stepModel.setStatus(mode.toStepStatus());128 return stepModel;129 }130 private List<NamedArgument> filterHiddenArguments(List<NamedArgument> arguments,131 Annotation[][] parameterAnnotations) {132 List<NamedArgument> result = Lists.newArrayList();133 for (int i = 0; i < parameterAnnotations.length; i++) {134 if (!AnnotationUtil.isHidden(parameterAnnotations[i])) {135 result.add(arguments.get(i));136 }137 }138 return result;139 }140 @Override141 public void introWordAdded(String value) {142 sentenceBuilder.addIntroWord(value);143 }144 private void addToSentence(String value, boolean joinToPreviousWord, boolean joinToNextWord) {145 if (!sentenceBuilder.hasWords() && currentStep != null && joinToPreviousWord) {146 currentStep.getLastWord().addSuffix(value);147 } else {148 sentenceBuilder.addWord(value, joinToPreviousWord, joinToNextWord);149 }150 }151 private void addStepComment(List<NamedArgument> arguments) {152 if (arguments == null || arguments.size() != 1) {153 throw new JGivenWrongUsageException("A step comment method must have exactly one parameter.");154 }155 if (!(arguments.get(0).getValue() instanceof String)) {156 throw new JGivenWrongUsageException("The step comment method parameter must be a string.");157 }158 if (currentStep == null) {159 throw new JGivenWrongUsageException("A step comment must be added after the corresponding step, "160 + "but no step has been executed yet.");161 }162 stepCommentUpdated((String) arguments.get(0).getValue());163 }164 @Override165 public void stepCommentUpdated(String comment) {166 currentStep.setComment(comment);167 }168 private ScenarioCaseModel getCurrentScenarioCase() {169 if (scenarioCaseModel == null) {170 scenarioStarted("A Scenario");171 }172 return scenarioCaseModel;173 }174 private void incrementDiscrepancy() {175 int discrepancyOnCurrentLayer = discrepancyOnLayer.pop();176 discrepancyOnCurrentLayer++;177 discrepancyOnLayer.push(discrepancyOnCurrentLayer);178 }179 private void decrementDiscrepancy() {180 if (discrepancyOnLayer.peek() > 0) {181 int discrepancyOnCurrentLayer = discrepancyOnLayer.pop();182 discrepancyOnCurrentLayer--;183 discrepancyOnLayer.push(discrepancyOnCurrentLayer);184 }185 }186 @Override187 public void stepMethodInvoked(Method method, List<NamedArgument> arguments, InvocationMode mode,188 boolean hasNestedSteps) {189 if (method.isAnnotationPresent(IntroWord.class)) {190 introWordAdded(getDescription(method));191 incrementDiscrepancy();192 } else if (method.isAnnotationPresent(FillerWord.class)) {193 FillerWord fillerWord = method.getAnnotation(FillerWord.class);194 addToSentence(getDescription(method), fillerWord.joinToPreviousWord(), fillerWord.joinToNextWord());195 incrementDiscrepancy();196 } else if (method.isAnnotationPresent(StepComment.class)) {197 addStepComment(arguments);198 incrementDiscrepancy();199 } else {200 addTags(method.getAnnotations());201 addTags(method.getDeclaringClass().getAnnotations());202 addStepMethod(method, arguments, mode, hasNestedSteps);203 }204 }205 public void setMethodName(String methodName) {206 scenarioModel.setTestMethodName(methodName);207 }208 public void setArguments(List<String> arguments) {209 scenarioCaseModel.setExplicitArguments(arguments);210 }211 public void setParameterNames(List<String> parameterNames) {212 scenarioModel.setExplicitParameters(removeUnderlines(parameterNames));213 }214 private static List<String> removeUnderlines(List<String> parameterNames) {215 List<String> result = Lists.newArrayListWithCapacity(parameterNames.size());216 for (String paramName : parameterNames) {217 result.add(WordUtil.fromSnakeCase(paramName));218 }219 return result;220 }221 private String getDescription(Method paramMethod) {222 if (paramMethod.isAnnotationPresent(Hidden.class)) {223 return "";224 }225 Description description = paramMethod.getAnnotation(Description.class);226 if (description != null) {227 return description.value();228 }229 As as = paramMethod.getAnnotation(As.class);230 AsProvider provider = as != null231 ? ReflectionUtil.newInstance(as.provider())232 : new DefaultAsProvider();233 return provider.as(as, paramMethod);234 }235 public void setStatus(ExecutionStatus status) {236 scenarioCaseModel.setStatus(status);237 }238 private void setException(Throwable throwable) {239 scenarioCaseModel.setErrorMessage(throwable.getClass().getName() + ": " + throwable.getMessage());240 scenarioCaseModel.setStackTrace(getStackTrace(throwable, FILTER_STACK_TRACE));241 }242 private List<String> getStackTrace(Throwable exception, boolean filterStackTrace) {243 StackTraceElement[] stackTraceElements = exception.getStackTrace();244 ArrayList<String> stackTrace = new ArrayList<>(stackTraceElements.length);245 outer:246 for (StackTraceElement element : stackTraceElements) {247 if (filterStackTrace) {248 for (String filter : STACK_TRACE_FILTER) {249 if (element.getClassName().contains(filter)) {250 continue outer;251 }252 }253 }254 stackTrace.add(element.toString());255 }256 return stackTrace;257 }258 @Override259 public void stepMethodFailed(Throwable t) {260 if (currentStep != null) {261 currentStep.setStatus(StepStatus.FAILED);262 }263 }264 @Override265 public void stepMethodFinished(long durationInNanos, boolean hasNestedSteps) {266 if (hasNestedSteps && !parentSteps.isEmpty()) {267 currentStep = parentSteps.peek();268 }269 if (currentStep != null) {270 if (discrepancyOnLayer.empty() || discrepancyOnLayer.peek() == 0) {271 currentStep.setDurationInNanos(durationInNanos);272 }273 if (hasNestedSteps) {274 if (currentStep.getStatus() != StepStatus.FAILED) {275 currentStep.setStatus(getStatusFromNestedSteps(currentStep.getNestedSteps()));276 }277 parentSteps.pop();278 discrepancyOnLayer.pop();279 }280 }281 if (!hasNestedSteps && !parentSteps.isEmpty()) {282 currentStep = parentSteps.peek();283 }284 decrementDiscrepancy();285 }286 private StepStatus getStatusFromNestedSteps(List<StepModel> nestedSteps) {287 StepStatus status = StepStatus.PASSED;288 for (StepModel nestedModel : nestedSteps) {289 StepStatus nestedStatus = nestedModel.getStatus();290 switch (nestedStatus) {291 case FAILED:292 return StepStatus.FAILED;293 case PENDING:294 status = StepStatus.PENDING;295 break;296 default:297 }298 }299 return status;300 }301 @Override302 public void scenarioFailed(Throwable e) {303 setStatus(ExecutionStatus.FAILED);304 setException(e);305 }306 private void setCaseDescription(Class<?> testClass, Method method, List<NamedArgument> namedArguments) {307 CaseAs annotation = null;308 if (method.isAnnotationPresent(CaseAs.class)) {309 annotation = method.getAnnotation(CaseAs.class);310 } else if (testClass.isAnnotationPresent(CaseAs.class)) {311 annotation = testClass.getAnnotation(CaseAs.class);312 }313 if (annotation != null) {314 CaseAsProvider caseDescriptionProvider = ReflectionUtil.newInstance(annotation.provider());315 String value = annotation.value();316 List<?> values;317 if (annotation.formatValues()) {318 values = scenarioCaseModel.getExplicitArguments();319 } else {320 values = getValues(namedArguments);321 }322 String caseDescription = caseDescriptionProvider.as(value, scenarioModel.getExplicitParameters(), values);323 scenarioCaseModel.setDescription(caseDescription);324 }325 }326 private List<Object> getValues(List<NamedArgument> namedArguments) {327 List<Object> result = Lists.newArrayList();328 for (NamedArgument a : namedArguments) {329 result.add(a.value);330 }331 return result;332 }333 private List<String> getNames(List<NamedArgument> namedArguments) {334 List<String> result = Lists.newArrayList();335 for (NamedArgument a : namedArguments) {336 result.add(a.name);337 }338 return result;339 }340 private void readConfiguration(Class<?> testClass) {341 configuration = ConfigurationUtil.getConfiguration(testClass);342 }343 private void readAnnotations(Class<?> testClass, Method method) {344 String scenarioDescription = method.getName();345 if (method.isAnnotationPresent(Description.class)) {346 scenarioDescription = method.getAnnotation(Description.class).value();347 } else if (method.isAnnotationPresent(As.class)) {348 As as = method.getAnnotation(As.class);349 AsProvider provider = ReflectionUtil.newInstance(as.provider());350 scenarioDescription = provider.as(as, method);351 }352 scenarioStarted(scenarioDescription);353 if (method.isAnnotationPresent(ExtendedDescription.class)) {354 scenarioModel.setExtendedDescription(method.getAnnotation(ExtendedDescription.class).value());355 }356 if (method.isAnnotationPresent(Pending.class)357 || method.getDeclaringClass().isAnnotationPresent(Pending.class)) {358 scenarioCaseModel.setStatus(ExecutionStatus.SCENARIO_PENDING);359 }360 if (scenarioCaseModel.getCaseNr() == 1) {361 addTags(testClass.getAnnotations());362 addTags(method.getAnnotations());363 }364 }365 @Override366 public void scenarioFinished() {367 AssertionUtil.assertTrue(scenarioStartedNanos > 0, "Scenario has no start time");368 long durationInNanos = System.nanoTime() - scenarioStartedNanos;369 scenarioCaseModel.setDurationInNanos(durationInNanos);370 scenarioModel.addDurationInNanos(durationInNanos);371 reportModel.addScenarioModelOrMergeWithExistingOne(scenarioModel);372 }373 @Override374 public void attachmentAdded(Attachment attachment) {375 currentStep.addAttachment(attachment);376 }377 @Override378 public void extendedDescriptionUpdated(String extendedDescription) {379 currentStep.setExtendedDescription(extendedDescription);380 }381 @Override382 public void stepNameUpdated(String newStepName) {383 List<Word> newWords = Lists.newArrayList();384 for (Word word : currentStep.getWords()) {385 if (word.isIntroWord()) {386 newWords.add(word);387 }388 }389 newWords.add(new Word(newStepName));390 currentStep.setWords(newWords);391 currentStep.setName(newStepName);392 }393 @Override394 public void sectionAdded(String sectionTitle) {395 StepModel stepModel = new StepModel();396 stepModel.setName(sectionTitle);397 stepModel.addWords(new Word(sectionTitle));398 stepModel.setIsSectionTitle(true);399 getCurrentScenarioCase().addStep(stepModel);400 }401 @Override402 public void tagAdded(Class<? extends Annotation> annotationClass, String... values) {403 addTags(tagCreator.toTags(annotationClass, values));404 }405 private void addTags(Annotation... annotations) {406 for (Annotation annotation : annotations) {407 addTags(tagCreator.toTags(annotation));408 }409 }410 private void addTags(ResolvedTags tags) {411 if (tags.isEmpty()) {412 return;413 }...

Full Screen

Full Screen

Source:MockScenarioModelBuilder.java Github

copy

Full Screen

...106 scenarioModel.addCase(scenarioCaseModel);107 scenarioModel.setDescription(readableDescription);108 }109 @Override110 public void addStepMethod(111 Method paramMethod,112 List<NamedArgument> arguments,113 InvocationMode mode,114 boolean hasNestedSteps115 ) {116 ExtendedStepModel stepModel = stepModelFactory.create(paramMethod, arguments, mode, introWord);117 DescriptionData description = DescriptionData.of(stepModel);118 descriptionQueue.add(description);119 if (introWord != null) {120 introWord = null;121 }122 if (!paramMethod.isAnnotationPresent(InlineWithNext.class)) {123 stepModel.setDescription(descriptionQueue.join());124 if (parentSteps.empty()) {125 getCurrentScenarioCase().addStep(stepModel);126 } else {127 parentSteps.peek()128 .addNestedStep(stepModel);129 }130 if (hasNestedSteps) {131 parentSteps.push(stepModel);132 }133 currentStep = stepModel;134 }135 }136 @Override137 public void introWordAdded(String value) {138 introWord = new Word();139 introWord.setIntroWord(true);140 introWord.setValue(value);141 }142 @Override143 public void stepCommentAdded(List<NamedArgument> arguments) {144 if (currentStep == null) {145 throw new JGivenWrongUsageException("A step comment must be added after the corresponding step, "146 + "but no step has been executed yet.");147 }148 currentStep.setComment(stepCommentFactory.create(arguments));149 }150 private ScenarioCaseModel getCurrentScenarioCase() {151 if (scenarioCaseModel == null) {152 scenarioStarted("A Scenario");153 }154 return scenarioCaseModel;155 }156 @Override157 public void stepMethodInvoked(158 Method method,159 List<NamedArgument> arguments,160 InvocationMode mode,161 boolean hasNestedSteps162 ) {163 if (method.isAnnotationPresent(IntroWord.class)) {164 introWordAdded(descriptionFactory.create(currentScenarioState.getCurrentStage(), method));165 } else if (method.isAnnotationPresent(StepComment.class)) {166 stepCommentAdded(arguments);167 } else {168 addTags(method.getAnnotations());169 addTags(method.getDeclaringClass()170 .getAnnotations());171 addStepMethod(method, arguments, mode, hasNestedSteps);172 }173 }174 @Override175 public void stepMethodFailed(Throwable t) {176 if (currentStep != null) {177 currentStep.setStatus(StepStatus.FAILED);178 }179 }180 @Override181 public void stepMethodFinished(182 long durationInNanos,183 boolean hasNestedSteps184 ) {185 if (hasNestedSteps && !parentSteps.isEmpty()) {186 currentStep = parentSteps.peek();187 }188 if (currentStep != null) {189 currentStep.setDurationInNanos(durationInNanos);190 if (hasNestedSteps) {191 if (currentStep.getStatus() != StepStatus.FAILED) {192 currentStep.inheritStatusFromNested();193 }194 parentSteps.pop();195 }196 }197 if (!hasNestedSteps && !parentSteps.isEmpty()) {198 currentStep = parentSteps.peek();199 }200 }201 @Override202 public void scenarioFailed(Throwable e) {203 scenarioCaseModel.setException(e, getStackTrace(e));204 }205 private List<String> getStackTrace(Throwable throwable) {206 if (FILTER_STACK_TRACE) {207 return ExceptionUtils.getFilteredStackTrace(throwable, STACK_TRACE_FILTER);208 } else {209 return ExceptionUtils.getStackTrace(throwable);210 }211 }212 @Override213 public void scenarioStarted(214 Class<?> testClass,215 Method method,216 List<NamedArgument> namedArguments217 ) {218 readConfiguration(testClass);219 readAnnotations(testClass, method);220 scenarioModel.setClassName(testClass.getName());221 scenarioModel.setExplicitParametersWithoutUnderline(ArgumentUtils.getNames(namedArguments));222 scenarioModel.setTestMethodName(method.getName());223 List<ObjectFormatter<?>> formatter = formatterFactory.create(method.getParameters(), namedArguments);224 List<String> arguments = ParameterFormatterUtils.toStringList(formatter, ArgumentUtils.getValues(namedArguments));225 scenarioCaseModel.setExplicitArguments(arguments);226 setCaseDescription(testClass, method, namedArguments);227 }228 private void readConfiguration(Class<?> testClass) {229 configuration = ConfigurationUtil.getConfiguration(testClass);230 initializeDependentOnConfiguration();231 }232 private void readAnnotations(233 Class<?> testClass,234 Method method235 ) {236 String scenarioDescription = descriptionFactory.create(currentScenarioState.getCurrentStage(), method);237 scenarioStarted(scenarioDescription);238 if (method.isAnnotationPresent(ExtendedDescription.class)) {239 scenarioModel.setExtendedDescription(method.getAnnotation(ExtendedDescription.class)240 .value());241 }242 if (method.isAnnotationPresent(NotImplementedYet.class) || method.isAnnotationPresent(Pending.class)) {243 scenarioCaseModel.setStatus(ExecutionStatus.SCENARIO_PENDING);244 }245 if (scenarioCaseModel.isFirstCase()) {246 addTags(testClass.getAnnotations());247 addTags(method.getAnnotations());248 }249 }250 private void setCaseDescription(251 Class<?> testClass,252 Method method,253 List<NamedArgument> namedArguments254 ) {255 CaseDescription caseDescription = caseDescriptionFactory.create(method, testClass, scenarioCaseModel, namedArguments);256 if (caseDescription != null) {257 String description = caseDescriptionFactory.create(caseDescription, scenarioCaseModel.getExplicitArguments());258 scenarioCaseModel.setDescription(description);259 }260 }261 public void addTags(Annotation... annotations) {262 for (Annotation annotation : annotations) {263 addTags(annotationTagExtractor.extract(annotation));264 }265 }266 private void addTags(List<Tag> tags) {267 if (!tags.isEmpty()) {268 if (reportModel != null) {269 this.reportModel.addTags(tags);270 }271 if (scenarioModel != null) {272 this.scenarioModel.addTags(tags);273 }274 }275 }276 @Override277 public void scenarioFinished() {278 AssertionUtil.assertTrue(scenarioStartedNanos > 0, "Scenario has no start time");279 long durationInNanos = System.nanoTime() - scenarioStartedNanos;280 scenarioCaseModel.setDurationInNanos(durationInNanos);281 scenarioModel.addDurationInNanos(durationInNanos);282 reportModel.addScenarioModelOrMergeWithExistingOne(scenarioModel);283 }284 @Override285 public void attachmentAdded(Attachment attachment) {286 currentStep.setAttachment(attachment);287 }288 @Override289 public void extendedDescriptionUpdated(String extendedDescription) {290 currentStep.setExtendedDescription(extendedDescription);291 }292 @Override293 public void sectionAdded(String sectionTitle) {294 StepModel stepModel = new StepModel();295 stepModel.setName(sectionTitle);296 stepModel.addWords(new Word(sectionTitle));297 stepModel.setIsSectionTitle(true);298 getCurrentScenarioCase().addStep(stepModel);299 }300 @Override301 public void tagAdded(302 Class<? extends Annotation> annotationClass,303 String... values304 ) {305 TagConfiguration tagConfig = annotationTagExtractor.toTagConfiguration(annotationClass);306 List<Tag> tags = AnnotationTagUtils.toTags(tagConfig, null);307 if (!tags.isEmpty()) {308 if (values.length > 0) {309 addTags(AnnotationTagUtils.getExplodedTags(Iterables.getOnlyElement(tags), values, null, tagConfig));310 } else {311 addTags(tags);312 }...

Full Screen

Full Screen

Source:GivenReportModel.java Github

copy

Full Screen

...52 for (String param : scenarioModel.getExplicitParameters()) {53 scenarioCaseModel.addExplicitArguments("arg" + scenarioCaseModel.getCaseNr() + i++);54 }55 scenarioCaseModel56 .addStep(new StepModel("something_happens", Arrays.asList(Word.introWord("given"), new Word("something"))));57 i = 0;58 for (String arg : scenarioCaseModel.getExplicitArguments()) {59 String argumentName = "stepArg" + i++;60 scenarioCaseModel.addStep(new StepModel("something_happens", asList(Word.introWord("when"),61 Word.argWord(argumentName, arg, (String) null))));62 }63 }64 public SELF a_report_model_with_name(String name) {65 a_report_model();66 reportModel.setClassName(name);67 for (ScenarioModel model : reportModel.getScenarios()) {68 model.setClassName(name);69 }70 return self();71 }72 public SELF the_report_has_$_scenarios(int n) {73 reportModel.getScenarios().clear();74 for (int i = 0; i < n; i++) {75 createScenarioModel("something should happen " + i, "something_should_happen_" + i);76 }77 return self();78 }79 public ReportModel getReportModel() {80 return reportModel;81 }82 public SELF parameters(String... params) {83 return the_scenario_has_parameters(params);84 }85 public SELF the_scenario_has_parameters(String... params) {86 reportModel.getLastScenarioModel().addParameterNames(params);87 return self();88 }89 public SELF the_scenario_has_a_duration_of_$_nano_seconds(long durationInNanos) {90 reportModel.getLastScenarioModel().setDurationInNanos(durationInNanos);91 return self();92 }93 public SELF the_step_$_has_a_duration_of_$_nano_seconds(int step, long durationInNanos) {94 reportModel.getLastScenarioModel().getCase(0).getStep(step).setDurationInNanos(durationInNanos);95 return self();96 }97 public SELF the_scenario_has_$_cases(int ncases) {98 ScenarioModel scenarioModel = reportModel.getLastScenarioModel();99 scenarioModel.clearCases();100 for (int i = 0; i < ncases; i++) {101 scenarioModel.addCase(new ScenarioCaseModel());102 }103 return self();104 }105 public SELF the_scenario_has_$_default_cases(int ncases) {106 reportModel.getLastScenarioModel().clearCases();107 for (int i = 0; i < ncases; i++) {108 addDefaultCase(reportModel.getLastScenarioModel());109 }110 return self();111 }112 public SELF case_$_of_scenario_$_has_failed(int caseNr, int scenarioNr) {113 getCase(scenarioNr, caseNr).setStatus(ExecutionStatus.FAILED);114 return self();115 }116 public SELF case_$_fails_with_error_message(int ncase, String errorMessage) {117 getCase(ncase).setErrorMessage(errorMessage);118 getCase(ncase).setStatus(ExecutionStatus.FAILED);119 return self();120 }121 public SELF case_$_has_arguments(int ncase, String... args) {122 getCase(ncase).setExplicitArguments(Arrays.asList(args));123 return self();124 }125 public SELF case_$_has_description(int ncase, String description) {126 getCase(ncase).setDescription(description);127 return self();128 }129 public SELF all_cases_have_a_step_$_with_argument(String name, String arg) {130 int i = 1;131 for (ScenarioCaseModel caseModel : reportModel.getLastScenarioModel().getScenarioCases()) {132 case_$_has_a_step_$_with_argument(i++, name, arg);133 }134 return self();135 }136 public SELF case_$_has_step_$(int ncase, String name) {137 getCase(ncase).addStep(new StepModel(name, Arrays.asList(Word.introWord("when"), new Word(name))));138 return self();139 }140 public SELF case_$_has_a_step_$_with_argument(int i, String name, String arg) {141 return case_$_has_a_when_step_$_with_argument(i, name, arg);142 }143 private ScenarioCaseModel getCase(int scenarioNr, int caseNr) {144 return reportModel.getScenarios().get(scenarioNr - 1).getCase(caseNr - 1);145 }146 private ScenarioCaseModel getCase(int ncase) {147 return reportModel.getLastScenarioModel().getScenarioCases().get(ncase - 1);148 }149 public SELF step_$_is_named(int i, String name) {150 getCase(1).getStep(i - 1).getWords().get(1).setValue(name);151 return self();152 }153 public SELF step_$_of_case_$_has_status(int stepNr, int caseNr, StepStatus status) {154 getCase(caseNr).getStep(stepNr - 1).setStatus(status);155 return self();156 }157 public SELF step_$_has_status(int stepNr, StepStatus status) {158 return step_$_of_case_$_has_status(stepNr, 1, status);159 }160 public SELF step_$_has_a_duration_of_$_nano_seconds(int i, long durationInNanos) {161 getCase(1).getStep(i - 1).setDurationInNanos(durationInNanos);162 return self();163 }164 public SELF case_$_has_a_when_step_$_with_argument(int ncase, String name, String arg) {165 return case_$_has_a_when_step_$_with_argument_$_and_argument_name_$(ncase, name, arg, "argName");166 }167 public SELF case_$_has_a_when_step_$_with_argument_$_and_argument_name_$(int ncase, @Quoted String name,168 @Quoted String arg,169 @Quoted String argName) {170 lastArgWord = Word.argWord(argName, arg, arg);171 getCase(ncase)172 .addStep(173 new StepModel(name,174 Arrays.asList(Word.introWord("when"), new Word(name), lastArgWord)));175 return self();176 }177 public SELF formatted_value(@Quoted String formattedValue) {178 lastArgWord.getArgumentInfo().setFormattedValue(formattedValue);179 return self();180 }181 public SELF the_first_scenario_has_tag(@Quoted String name) {182 return scenario_$_has_tag_$_with_value_$(1, name, null);183 }184 public SELF scenario_$_has_tag_$_with_value_$(int i, String name, String value) {185 latestTag = new Tag(name, value).setPrependType(true);186 latestTag.setType(name);...

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import com.tngtech.jgiven.report.model.StepModel;3import org.junit.Test;4import static org.assertj.core.api.Assertions.assertThat;5public class ScenarioCaseModelTest {6 public void testAddStepMethod() {7 ScenarioCaseModel scenarioCaseModel = new ScenarioCaseModel();8 StepModel stepModel = new StepModel();9 scenarioCaseModel.addStep(stepModel);10 assertThat(scenarioCaseModel.getSteps()).contains(stepModel);11 }12}13package com.tngtech.jgiven.report.model;14import com.tngtech.jgiven.report.model.StepModel;15import org.junit.Test;16import static org.assertj.core.api.Assertions.assertThat;17public class ScenarioCaseModelTest {18 public void testAddStepMethod() {19 ScenarioCaseModel scenarioCaseModel = new ScenarioCaseModel();20 StepModel stepModel = new StepModel();21 scenarioCaseModel.addStep(stepModel);22 assertThat(scenarioCaseModel.getSteps()).contains(stepModel);23 }24}25package com.tngtech.jgiven.report.model;26import com.tngtech.jgiven.report.model.StepModel;27import org.junit.Test;28import static org.assertj.core.api.Assertions.assertThat;29public class ScenarioCaseModelTest {30 public void testAddStepMethod() {31 ScenarioCaseModel scenarioCaseModel = new ScenarioCaseModel();32 StepModel stepModel = new StepModel();33 scenarioCaseModel.addStep(stepModel);34 assertThat(scenarioCaseModel.getSteps()).contains(stepModel);35 }36}37package com.tngtech.jgiven.report.model;38import com.tngtech.jgiven.report.model.StepModel;39import org.junit.Test;40import static org.assertj.core.api.Assertions.assertThat;41public class ScenarioCaseModelTest {42 public void testAddStepMethod() {43 ScenarioCaseModel scenarioCaseModel = new ScenarioCaseModel();44 StepModel stepModel = new StepModel();45 scenarioCaseModel.addStep(stepModel);46 assertThat(scenarioCaseModel.getSteps()).contains(step

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.ArrayList;3import java.util.List;4import com.tngtech.jgiven.impl.util.ReflectionUtil;5import com.tngtech.jgiven.report.model.ExecutionStatus;6public class ScenarioCaseModel {7 private List<StepModel> steps = new ArrayList<StepModel>();8 private ExecutionStatus status = ExecutionStatus.UNDEFINED;9 public void addStep(StepModel stepModel) {10 steps.add(stepModel);11 }12 public void setStatus(ExecutionStatus status) {13 this.status = status;14 }15 public ExecutionStatus getStatus() {16 return status;17 }18 public List<StepModel> getSteps() {19 return steps;20 }21 public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {22 ScenarioCaseModel scenarioCaseModel = new ScenarioCaseModel();23 StepModel stepModel = new StepModel();24 stepModel.setStatus(ExecutionStatus.FAILED);25 stepModel.setDescription("Step description");26 scenarioCaseModel.addStep(stepModel);27 scenarioCaseModel.setStatus(ExecutionStatus.FAILED);28 System.out.println(scenarioCaseModel.getSteps().get(0).getStatus());29 System.out.println(scenarioCaseModel.getStatus());30 }31}

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.ArrayList;3import java.util.List;4public class ScenarioCaseModel {5 public void addStep(StepModel stepModel) {6 steps.add(stepModel);7 }8 private List<StepModel> steps = new ArrayList<StepModel>();9}10package com.tngtech.jgiven.report.model;11import java.util.ArrayList;12import java.util.List;13public class ScenarioCaseModel {14 public static void main(String[] args) {15 ScenarioCaseModel scm = new ScenarioCaseModel();16 StepModel sm = new StepModel();17 scm.addStep(sm);18 System.out.println("Step added successfully");19 }20}

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.examples;2import java.io.IOException;3import org.junit.Test;4import com.tngtech.jgiven.Stage;5import com.tngtech.jgiven.annotation.ExpectedScenarioState;6import com.tngtech.jgiven.annotation.ProvidedScenarioState;7import com.tngtech.jgiven.annotation.ScenarioRule;8import com.tngtech.jgiven.junit.SimpleScenarioTest;9import com.tngtech.jgiven.report.model.ScenarioCaseModel;10import com.tngtech.jgiven.report.model.StepModel;11import com.tngtech.jgiven.report.model.TagModel;12public class AddStepWithArguments extends SimpleScenarioTest<AddStepWithArguments.AddStepWithArgumentsSteps> {13 public void addStepWithArguments() throws IOException {

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.example;2import com.tngtech.jgiven.Stage;3import com.tngtech.jgiven.annotation.ExpectedScenarioState;4import com.tngtech.jgiven.report.model.ScenarioCaseModel;5import com.tngtech.jgiven.report.model.StepModel;6public class WhenStage extends Stage<WhenStage> {7 ScenarioCaseModel scenarioCaseModel;8 public WhenStage a_step_is_added() {9 StepModel stepModel = new StepModel();10 stepModel.setDescription("This is a step");11 scenarioCaseModel.addStep(stepModel);12 return self();13 }14}15package com.tngtech.jgiven.example;16import com.tngtech.jgiven.Stage;17import com.tngtech.jgiven.annotation.ExpectedScenarioState;18import com.tngtech.jgiven.report.model.ScenarioCaseModel;19import com.tngtech.jgiven.report.model.StepModel;20public class WhenStage extends Stage<WhenStage> {21 ScenarioCaseModel scenarioCaseModel;22 public WhenStage a_step_is_added() {23 StepModel stepModel = new StepModel();24 stepModel.setDescription("This is a step");25 scenarioCaseModel.addStep(stepModel);26 return self();27 }28}29package com.tngtech.jgiven.example;30import com.tngtech.jgiven.Stage;31import com.tngtech.jgiven.annotation.ExpectedScenarioState;32import com.tngtech.jgiven.report.model.ScenarioCaseModel;33import com.tngtech.jgiven.report.model.StepModel;34public class WhenStage extends Stage<WhenStage> {35 ScenarioCaseModel scenarioCaseModel;36 public WhenStage a_step_is_added() {37 StepModel stepModel = new StepModel();38 stepModel.setDescription("This is a step");39 scenarioCaseModel.addStep(stepModel);40 return self();41 }42}

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import com.tngtech.jgiven.report.model.StepModel;3import com.tngtech.jgiven.report.model.ScenarioCaseModel;4import com.tngtech.jgiven.report.model.ScenarioModel;5public class ScenarioCaseModelAddStep {6 public static void main(String[] args) {7 ScenarioCaseModel caseModel = new ScenarioCaseModel();8 caseModel.addStep(new StepModel());

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.ArrayList;3import java.util.List;4import com.tngtech.jgiven.annotation.ExpectedScenarioState;5import com.tngtech.jgiven.annotation.ScenarioState;6import com.tngtech.jgiven.report.model.ReportModelBuilder;7import com.tngtech.jgiven.report.model.ReportModel;8import com.tngtech.jgiven.report.model.ScenarioCaseModel;9import com.tngtech.jgiven.report.model.StepModel;10import com.tngtech.jgiven.report.model.Word;11import com.tngtech.jgiven.report.model.WordType;12import com.tngtech.jgiven.report.text.TextFormatter;13import

Full Screen

Full Screen

addStep

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import com.tngtech.jgiven.impl.ScenarioModelBuilder;3import com.tngtech.jgiven.impl.ScenarioModelBuilderBase;4import com.tngtech.jgiven.impl.StageModelBuilder;5import com.tngtech.jgiven.report.model.ScenarioCaseModel.ScenarioCaseModelBuilder;6public class ScenarioCaseModelBuilder extends ScenarioModelBuilderBase<ScenarioCaseModelBuilder, ScenarioCaseModel> {7 private ScenarioCaseModel scenarioCaseModel;8 public ScenarioCaseModelBuilder(ScenarioCaseModel scenarioCaseModel) {9 super(scenarioCaseModel);10 this.scenarioCaseModel = scenarioCaseModel;11 }12 public ScenarioCaseModelBuilder addStep(StepModel stepModel) {13 scenarioCaseModel.addStep(stepModel);14 return this;15 }16}17package com.tngtech.jgiven.report.model;18import com.tngtech.jgiven.impl.ScenarioModelBuilder;19import com.tngtech.jgiven.impl.ScenarioModelBuilderBase;20import com.tngtech.jgiven.impl.StageModelBuilder;21import com.tngtech.jgiven.report.model.ScenarioCaseModel.ScenarioCaseModelBuilder;22public class ScenarioModelBuilder extends ScenarioModelBuilderBase<ScenarioModelBuilder, ScenarioModel> {23 private ScenarioModel scenarioModel;24 public ScenarioModelBuilder(ScenarioModel scenarioModel) {25 super(scenarioModel);26 this.scenarioModel = scenarioModel;27 }28 public ScenarioModelBuilder addStep(StepModel stepModel) {29 scenarioModel.addStep(stepModel);30 return this;31 }32}

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