How to use addTags method of com.tngtech.jgiven.report.model.ReportModel class

Best JGiven code snippet using com.tngtech.jgiven.report.model.ReportModel.addTags

Source:ScenarioModelBuilder.java Github

copy

Full Screen

...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 }414 if (reportModel != null) {415 this.reportModel.addTags(tags.getDeclaredTags());416 //The report model needs to declare the parent tags in a tag map, or the tags cannot be displayed.417 this.reportModel.addTags(tags.getAncestors());418 }419 if (scenarioModel != null) {420 this.scenarioModel.addTags(tags.getDeclaredTags());421 }422 }423 public ReportModel getReportModel() {424 return reportModel;425 }426 public ScenarioModel getScenarioModel() {427 return scenarioModel;428 }429 public ScenarioCaseModel getScenarioCaseModel() {430 return scenarioCaseModel;431 }432}...

Full Screen

Full Screen

Source:MockScenarioModelBuilder.java Github

copy

Full Screen

...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 }313 }314 }315 public void setReportModel(ReportModel reportModel) {316 this.reportModel = reportModel;317 }318 public ReportModel getReportModel() {319 return reportModel;320 }321 public ScenarioModel getScenarioModel() {322 return scenarioModel;323 }324 public ScenarioCaseModel getScenarioCaseModel() {325 return scenarioCaseModel;...

Full Screen

Full Screen

Source:ReportModel.java Github

copy

Full Screen

...109 }110 public synchronized void addTag(Tag tag) {111 this.tagMap.put(tag.toIdString(), tag);112 }113 public synchronized void addTags(Iterable<Tag> tags) {114 tags.forEach(this::addTag);115 }116 public synchronized Tag getTagWithId(String tagId) {117 Tag tag = this.tagMap.get(tagId);118 AssertionUtil.assertNotNull(tag, "Could not find tag with id " + tagId);119 return tag;120 }121 public synchronized Map<String, Tag> getTagMap() {122 return tagMap;123 }124 public synchronized void setTagMap(Map<String, Tag> tagMap) {125 this.tagMap = tagMap;126 }127 public synchronized void addScenarioModelOrMergeWithExistingOne(ScenarioModel scenarioModel) {...

Full Screen

Full Screen

addTags

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.model.ReportModel;2public class Example {3 public static void main(String[] args) {4 ReportModel reportModel = new ReportModel();5 reportModel.addTags("tag1", "tag2");6 }7}

Full Screen

Full Screen

addTags

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.model.ReportModel;2import com.tngtech.jgiven.report.model.ReportTag;3import com.tngtech.jgiven.report.model.ScenarioTag;4public class AddTagsToScenario {5 public static void main(String[] args) {6 ReportModel reportModel = new ReportModel();7 ReportTag reportTag = new ReportTag();8 ScenarioTag scenarioTag = new ScenarioTag();9 scenarioTag.setName("Tag1");10 reportTag.addScenarioTag(scenarioTag);11 reportModel.addTags(reportTag);12 System.out.println(reportModel.getTags());13 }14}15import com.tngtech.jgiven.report.model.ReportModel;16import com.tngtech.jgiven.report.model.ReportTag;17import com.tngtech.jgiven.report.model.ScenarioTag;18public class AddTagsToScenario {19 public static void main(String[] args) {20 ReportModel reportModel = new ReportModel();21 ReportTag reportTag = new ReportTag();22 ScenarioTag scenarioTag = new ScenarioTag();23 scenarioTag.setName("Tag1");24 reportTag.addScenarioTag(scenarioTag);25 reportModel.addTags(reportTag);26 reportModel.addTags(reportTag);27 System.out.println(reportModel.getTags());28 }29}30import com.tngtech.jgiven.report.model.ReportModel;31import com.tngtech.jgiven.report.model.ReportTag;32import com.tngtech.jgiven.report.model.ScenarioTag;33public class AddTagsToScenario {34 public static void main(String[] args) {35 ReportModel reportModel = new ReportModel();36 ReportTag reportTag = new ReportTag();37 ScenarioTag scenarioTag = new ScenarioTag();38 scenarioTag.setName("Tag1");39 reportTag.addScenarioTag(scenarioTag);40 reportModel.addTags(reportTag);41 reportModel.addTags(reportTag);42 reportModel.addTags(reportTag);43 System.out.println(reportModel.getTags());44 }45}

Full Screen

Full Screen

addTags

Using AI Code Generation

copy

Full Screen

1public class TestClass {2 public void testMethod() {3 ReportModel reportModel = new ReportModel();4 reportModel.addTags("tag1", "tag2");5 }6}7public class TestClass {8 public void testMethod() {9 ReportModel reportModel = new ReportModel();10 reportModel.addTags("tag1", "tag2");11 }12}13public class TestClass {14 public void testMethod() {15 ReportModel reportModel = new ReportModel();16 reportModel.addTags("tag1", "tag2");17 }18}19public class TestClass {20 public void testMethod() {21 ReportModel reportModel = new ReportModel();22 reportModel.addTags("tag1", "tag2");23 }24}25public class TestClass {26 public void testMethod() {27 ReportModel reportModel = new ReportModel();28 reportModel.addTags("tag1", "tag2");29 }30}31public class TestClass {32 public void testMethod() {33 ReportModel reportModel = new ReportModel();34 reportModel.addTags("tag1", "tag2");35 }36}37public class TestClass {38 public void testMethod() {39 ReportModel reportModel = new ReportModel();40 reportModel.addTags("tag1", "tag2");41 }42}43public class TestClass {44 public void testMethod() {

Full Screen

Full Screen

addTags

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.*;3import java.util.regex.*;4import java.io.*;5import java.util.ArrayList;6import java.util.List;7import java.util.regex.Pattern;8import com.tngtech.jgiven.report.model.ReportModel;9import com.tngtech.jgiven.report.model.ReportModel.ReportModelBuilder;10import com.tngtech.jgiven.report.model.ScenarioModel;11import com.tngtech.jgiven.report.model.Tag;12import com.tngtech.jgiven.report.model.Tags;13import com.tngtech.jgiven.report.model.TestModel;14import com.tngtech.jgiven.report.model.Word;

Full Screen

Full Screen

addTags

Using AI Code Generation

copy

Full Screen

1public class AddTags {2 public static void main(String[] args) throws Exception {3 ReportModel reportModel = ReportModel.createReportModel();4 reportModel.addTags("Tag1", "Tag2");5 reportModel.writeTo(new File("report.json"));6 }7}8public class AddTags {9 public static void main(String[] args) throws Exception {10 ReportModel reportModel = ReportModel.createReportModel();11 reportModel.addTags("Tag1", "Tag2");12 reportModel.writeTo(new File("report.json"));13 }14}15public class AddTags {16 public static void main(String[] args) throws Exception {17 ReportModel reportModel = ReportModel.createReportModel();18 reportModel.addTags("Tag1", "Tag2");19 reportModel.writeTo(new File("report.json"));20 }21}22public class AddTags {23 public static void main(String[] args) throws Exception {24 ReportModel reportModel = ReportModel.createReportModel();25 reportModel.addTags("Tag1", "Tag2");26 reportModel.writeTo(new File("report.json"));27 }28}29public class AddTags {30 public static void main(String[] args) throws Exception {31 ReportModel reportModel = ReportModel.createReportModel();32 reportModel.addTags("Tag1", "Tag2");33 reportModel.writeTo(new File("report.json"));34 }35}36public class AddTags {37 public static void main(String[] args) throws Exception {38 ReportModel reportModel = ReportModel.createReportModel();39 reportModel.addTags("Tag1", "Tag2");40 reportModel.writeTo(new File("report.json"));41 }42}

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