How to use image method of com.tngtech.jgiven.attachment.MediaType class

Best JGiven code snippet using com.tngtech.jgiven.attachment.MediaType.image

Source:Html5AttachmentGenerator.java Github

copy

Full Screen

...13import com.tngtech.jgiven.report.model.ReportModelVisitor;14import com.tngtech.jgiven.report.model.StepModel;15import java.awt.*;16import java.awt.geom.AffineTransform;17import java.awt.image.AffineTransformOp;18import java.awt.image.BufferedImage;19import java.io.*;20import java.util.List;21import java.util.Set;22import javax.imageio.ImageIO;23import org.apache.batik.transcoder.TranscoderException;24import org.apache.batik.transcoder.TranscoderInput;25import org.apache.batik.transcoder.TranscoderOutput;26import org.apache.batik.transcoder.image.PNGTranscoder;27import org.slf4j.Logger;28import org.slf4j.LoggerFactory;29class Html5AttachmentGenerator extends ReportModelVisitor {30 private static final Logger log = LoggerFactory.getLogger(Html5AttachmentGenerator.class);31 private static final String ATTACHMENT_DIRNAME = "attachments";32 public static final int MINIMAL_THUMBNAIL_SIZE = 20;33 private File attachmentsDir;34 private String subDir;35 private final Multiset<String> fileCounter = HashMultiset.create();36 private final Set<String> usedFileNames = Sets.newHashSet();37 private String htmlSubDir;38 public Html5AttachmentGenerator() {39 }40 @VisibleForTesting41 public Html5AttachmentGenerator(File attachmentsDir) {42 this.attachmentsDir = attachmentsDir;43 }44 public void generateAttachments(File targetDir, ReportModel model) {45 subDir = ATTACHMENT_DIRNAME + File.separatorChar + model.getClassName().replace('.', File.separatorChar);46 htmlSubDir = subDir.replace(File.separatorChar, '/');47 attachmentsDir = new File(targetDir, subDir);48 if (!attachmentsDir.exists() && !attachmentsDir.mkdirs()) {49 throw new JGivenInstallationException("Could not create directory " + attachmentsDir);50 }51 model.accept(this);52 }53 @Override54 public void visit(StepModel stepModel) {55 List<AttachmentModel> attachments = stepModel.getAttachments();56 for (AttachmentModel attachment : attachments) {57 writeAttachment(attachment);58 }59 }60 private void writeAttachment(AttachmentModel attachment) {61 String mimeType = attachment.getMediaType();62 MediaType mediaType = MediaType.parse(mimeType);63 File targetFile = writeFile(attachment, mediaType);64 attachment.setValue(htmlSubDir + "/" + targetFile.getName());65 log.debug("Attachment written to " + targetFile);66 }67 private String getExtension(MediaType mediaType) {68 if (mediaType.is(MediaType.SVG_UTF_8)) {69 return "svg";70 }71 if (mediaType.is(MediaType.ICO)) {72 return "ico";73 }74 if (mediaType.is(MediaType.BMP)) {75 return "bmp";76 }77 return mediaType.subtype();78 }79 File getTargetFile(String fileName, String extension) {80 if (fileName == null) {81 fileName = "attachment";82 }83 int count = fileCounter.count(fileName);84 fileCounter.add(fileName);85 String suffix = "";86 if (count > 0) {87 count += 1;88 suffix = String.valueOf(count);89 }90 String fileNameWithExtension = fileName + suffix + "." + extension;91 while (usedFileNames.contains(fileNameWithExtension)) {92 fileCounter.add(fileName);93 count++;94 suffix = String.valueOf(count);95 fileNameWithExtension = fileName + suffix + "." + extension;96 }97 usedFileNames.add(fileNameWithExtension);98 return new File(attachmentsDir, fileNameWithExtension);99 }100 private File getThumbnailFileFor(File originalImage) {101 String orgName = originalImage.getName();102 String newName = "";103 int dotIndex = orgName.lastIndexOf(".");104 if (dotIndex == -1) {105 newName = orgName + "-thumb";106 } else {107 String extension = orgName.subSequence(dotIndex + 1, orgName.length()).toString();108 newName = orgName.substring(0, dotIndex) + "-thumb." + extension;109 }110 return new File(attachmentsDir, newName);111 }112 private File writeFile(AttachmentModel attachment, MediaType mediaType) {113 String extension = getExtension(mediaType);114 File targetFile = getTargetFile(attachment.getFileName(), extension);115 try {116 if (attachment.isBinary()) {117 if (mediaType.is(MediaType.ANY_IMAGE_TYPE)) {118 File thumbFile = getThumbnailFileFor(targetFile);119 byte[] thumbnail = compressToThumbnail(attachment.getValue(), extension);120 Files.write(thumbnail, thumbFile);121 }122 Files.write(BaseEncoding.base64().decode(attachment.getValue()), targetFile);123 } else {124 Files.write(attachment.getValue().getBytes(Charsets.UTF_8), targetFile);125 if (com.tngtech.jgiven.attachment.MediaType.SVG_UTF_8.toString().equals(attachment.getMediaType())) {126 File thumbFile = getThumbnailFileFor(targetFile);127 writeThumbnailForSVG(targetFile, thumbFile);128 }129 }130 } catch (IOException e) {131 log.error("Error while trying to write attachment to file " + targetFile, e);132 }133 return targetFile;134 }135 private byte[] compressToThumbnail(String base64content, String extension) {136 byte[] imageBytes = BaseEncoding.base64().decode(base64content);137 byte[] base64thumb = {};138 try {139 BufferedImage before = ImageIO.read(new ByteArrayInputStream(imageBytes));140 BufferedImage after = scaleDown(before);141 base64thumb = bufferedImageToBase64(after, extension);142 } catch (IOException e) {143 log.error("Error while decoding the attachment to BufferedImage ", e);144 }145 return base64thumb;146 }147 static BufferedImage scaleDown(BufferedImage before) {148 double xFactor = Math.min(1.0, MINIMAL_THUMBNAIL_SIZE / (double) before.getWidth());149 double yFactor = Math.min(1.0, MINIMAL_THUMBNAIL_SIZE / (double) before.getHeight());150 double factor = Math.max(xFactor, yFactor);151 int width = (int) Math.round(before.getWidth() * factor);152 int height = (int) Math.round(before.getHeight() * factor);153 BufferedImage after = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);154 AffineTransform at = new AffineTransform();155 at.scale(factor, factor);156 AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);157 return scaleOp.filter(before, after);158 }159 private byte[] bufferedImageToBase64(BufferedImage bi, String extension) {160 ByteArrayOutputStream baos = new ByteArrayOutputStream();161 byte[] imageArray = {};162 try {163 ImageIO.write(bi, extension, baos);164 imageArray = baos.toByteArray();165 baos.close();166 } catch (IOException e) {167 log.error("Error while decoding the compressed BufferedImage to base64 ", e);168 }169 return imageArray;170 }171 private void writeThumbnailForSVG(File initialSVG, File thumbnailSVG) {172 String base64PNGImage = getPNGFromSVG(initialSVG);173 byte[] scaledDownInBytes = compressToThumbnail(base64PNGImage, "png");174 Dimension imageDimension = getImageDimension(scaledDownInBytes);175 String base64ScaledDownContent = BaseEncoding.base64().encode(scaledDownInBytes);176 createSVGThumbFile(thumbnailSVG, base64ScaledDownContent, imageDimension);177 }178 Dimension getImageDimension(byte[] givenImage) {179 Dimension dimension = new Dimension();180 try (ByteArrayInputStream inputStream = new ByteArrayInputStream(givenImage)) {181 BufferedImage image = ImageIO.read(inputStream);182 dimension.height = image.getHeight();183 dimension.width = image.getWidth();184 } catch (IOException e) {185 log.error("The converted png image cannot be read.");186 }187 return dimension;188 }189 void createSVGThumbFile(File targetFile, String base64Image, Dimension dimension) {190 String xmlFormat = getXMLFormat(base64Image, dimension);191 try (FileWriter fileWriter = new FileWriter(targetFile)) {192 fileWriter.write(xmlFormat);193 } catch (IOException e) {194 log.error("Error writing the thumbnail svg to " + targetFile);195 }196 }197 private String getXMLFormat(String base64Image, Dimension dimension) {198 return "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" "199 + "height=\"" + dimension.getHeight() + "px\" width=\"" + dimension.getWidth() + "px\">"200 + "<image height=\"100%\" width=\"100%\" xlink:href=\"data:image/png;base64, " + base64Image + "\"/>"201 + "</svg>";202 }203 String getPNGFromSVG(File givenSVG) {204 PNGTranscoder transcoder = new PNGTranscoder();205 TranscoderInput transcoderInput = new TranscoderInput();206 TranscoderOutput transcoderOutput = new TranscoderOutput();207 try (FileInputStream inputStream = new FileInputStream(givenSVG);208 ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {209 transcoderInput.setInputStream(inputStream);210 transcoderOutput.setOutputStream(outputStream);211 transcoder.transcode(transcoderInput, transcoderOutput);212 return BaseEncoding.base64().encode(outputStream.toByteArray());213 } catch (FileNotFoundException e) {214 log.error("Error while reading the initial svg file.");...

Full Screen

Full Screen

Source:Html5AttachmentGeneratorTest.java Github

copy

Full Screen

...11import com.tngtech.jgiven.report.model.ScenarioCaseModel;12import com.tngtech.jgiven.report.model.ScenarioModel;13import com.tngtech.jgiven.report.model.StepModel;14import java.awt.*;15import java.awt.image.BufferedImage;16import java.io.*;17import java.net.URISyntaxException;18import java.util.ArrayList;19import javax.imageio.ImageIO;20import org.assertj.core.util.Lists;21import org.junit.Before;22import org.junit.Rule;23import org.junit.Test;24import org.junit.rules.TemporaryFolder;25import org.junit.runner.RunWith;26@RunWith(DataProviderRunner.class)27public class Html5AttachmentGeneratorTest {28 private Html5AttachmentGenerator generator;29 private static final byte[] BINARY_SAMPLE = BaseEncoding.base64().decode(30 "R0lGODlhFgAWAOZiAAUFBd3d3eHh4be3tzg4ODU1NaysrMHBwTs7O39/f15eXs/Pz+fn5wwMDEVFRTIyMh0dHUpKSigoKJeXl3x8fKioqOTk5NPT05qamjc3N2RkZDExMYmJiUxMTDo6Ouvr62pqanFxcW1tbfz8/CAgIM3Nze7u7vn5+eLi4m5ubjMzM52dnRcXF5ubm/Pz801NTcvLyz09PSwsLISEhJmZmT8/P+Xl5SIiIggICJGRkVxcXCUlJfDw8K2trZaWlhAQED4+Pmtra2hoaMfHx0BAQFpaWsrKynl5eVZWVq+vr6Ojo/j4+IeHh3p6ehQUFNjY2Ly8vK6ursLCwmBgYJSUlHBwcICAgIODg/Hx8WJiYouLi9/f33JycsTExC4uLvb29v///wICAi4uLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAGIALAAAAAAWABYAAAf/gGKCgwVFPgFfXwEtUwWDj4MbIQJglQxblWACKV6QggQ9YCcTDmGmYQVaX2BKHpAEMGADJKe1YRJGYAsIkVFgKwC2tgBXYAcPglyywcLCVGBNYgUCLhCnDwi1LFkNpjgoAh4KYDmnMpUJpjcWYBOnGmBBNGAEpySrYAk77GAcp04jBgTgYSsCPiyVDDAzVQLRE2ERlmRSaCtJogvCJHzIZEWYAUUfbElgUGkEOltdAlQAY83UD5JgDHTAB+IUABMDhIARcYpAwmAGwVQ45QBMFQICbHQzpQHEwgIJWoaBIgCImCP9mjUbx0TQgwNgFGitheDEgQyDiCwAQ2FsGB1fKxZ0gFQD7AUkS4lKMfbCkxgVFCh9KYEBwxATmmag9SsIgQiBiQIMCBHDUyAAOw==");31 @Rule32 public final TemporaryFolder temporaryFolderRule = new TemporaryFolder();33 @Before34 public void setup() {35 generator = new Html5AttachmentGenerator(temporaryFolderRule.getRoot());36 }37 @Test38 public void testFileNameGeneration() {39 assertThat(generator.getTargetFile("foo", "txt").getName()).isEqualTo("foo.txt");40 assertThat(generator.getTargetFile("foo", "txt").getName()).isEqualTo("foo2.txt");41 assertThat(generator.getTargetFile("foo", "png").getName()).isEqualTo("foo3.png");42 assertThat(generator.getTargetFile("foo4", "png").getName()).isEqualTo("foo4.png");43 assertThat(generator.getTargetFile("foo", "png").getName()).isEqualTo("foo5.png");44 }45 @Test46 public void testScalingOfImageToMinimumSize() throws IOException, URISyntaxException {47 Attachment attachment = Attachment.fromBinaryBytes(BINARY_SAMPLE, MediaType.GIF);48 BufferedImage before = ImageIO.read(new ByteArrayInputStream(BaseEncoding.base64()49 .decode(attachment.getContent())));50 assertThat(before.getWidth()).isEqualTo(22);51 assertThat(before.getHeight()).isEqualTo(22);52 StepModel stepModel = new StepModel("test", Lists.newArrayList());53 stepModel.addAttachment(attachment);54 generator.visit(stepModel);55 File writtenFile = new File(temporaryFolderRule.getRoot().getPath() + "/attachment-thumb.gif");56 Attachment writtenAttachment = Attachment.fromBinaryFile(writtenFile, MediaType.GIF);57 BufferedImage after = ImageIO.read(new ByteArrayInputStream(BaseEncoding.base64()58 .decode(writtenAttachment.getContent())));59 assertThat(after.getWidth()).isEqualTo(MINIMAL_THUMBNAIL_SIZE);60 assertThat(after.getHeight()).isEqualTo(MINIMAL_THUMBNAIL_SIZE);61 }62 @Test63 public void testFindingAndGeneratingAttachmentsInAllSteps() throws IOException {64 File root = temporaryFolderRule.getRoot();65 generator.generateAttachments(root, generateReportModelWithAttachments());66 File parentStepFile = new File(temporaryFolderRule.getRoot().getPath()67 + "/attachments/testing/parentAttachment.gif");68 File nestedStepFile = new File(temporaryFolderRule.getRoot().getPath()69 + "/attachments/testing/nestedAttachment.gif");70 Attachment writtenParentAttachment = Attachment.fromBinaryFile(parentStepFile, MediaType.GIF);71 Attachment writtenNestedAttachment = Attachment.fromBinaryFile(nestedStepFile, MediaType.GIF);72 assertThat(writtenParentAttachment.getContent()).isNotNull();73 assertThat(writtenNestedAttachment.getContent()).isNotNull();74 }75 @Test76 public void testGetImageDimensions() {77 assertThat(generator.getImageDimension(BINARY_SAMPLE)).isEqualTo(new Dimension(22, 22));78 }79 @Test80 public void testPNGConvertor() {81 File sampleSVG = new File("src/test/resources/SampleSVG.svg");82 String pngContent = generator.getPNGFromSVG(sampleSVG);83 assertThat(generator.getImageDimension(BaseEncoding.base64().decode(pngContent)))84 .isEqualTo(new Dimension(25, 25));85 }86 @Test87 public void testSVGFilesHaveAGeneratedThumbnail() throws IOException {88 File sampleSVG = new File("src/test/resources/SampleSVG.svg");89 Attachment sampleSVGAttachment = Attachment.fromTextFile(sampleSVG, MediaType.SVG_UTF_8)90 .withFileName("SampleSVG");91 StepModel stepModel = new StepModel("svgTest", Lists.newArrayList());92 stepModel.addAttachment(sampleSVGAttachment);93 generator.visit(stepModel);94 File svgThumbnail = new File(temporaryFolderRule.getRoot().getPath()95 + "/SampleSVG-thumb.svg");96 String pngContent = generator.getPNGFromSVG(svgThumbnail);97 assertThat(generator.getImageDimension(BaseEncoding.base64().decode(pngContent)))98 .isEqualTo(new Dimension(MINIMAL_THUMBNAIL_SIZE, MINIMAL_THUMBNAIL_SIZE));99 }100 private ReportModel generateReportModelWithAttachments() {101 Attachment nestedAttachment = Attachment.fromBinaryBytes(BINARY_SAMPLE, MediaType.GIF)102 .withFileName("nestedAttachment");103 Attachment parentAttachment = Attachment.fromBinaryBytes(BINARY_SAMPLE, MediaType.GIF)104 .withFileName("parentAttachment");105 StepModel parentStep = new StepModel("test", Lists.newArrayList());106 StepModel nestedStep = new StepModel("test", Lists.newArrayList());107 nestedStep.addAttachment(nestedAttachment);108 parentStep.addNestedStep(nestedStep);109 parentStep.addAttachment(parentAttachment);110 ReportModel model = new ReportModel();111 ArrayList<ScenarioModel> scenarios = new ArrayList<ScenarioModel>();112 ScenarioModel scenarioModel = new ScenarioModel();113 ScenarioCaseModel scenarioCase = new ScenarioCaseModel();114 scenarioCase.addStep(parentStep);115 scenarioModel.addCase(scenarioCase);116 scenarios.add(scenarioModel);117 model.setScenarios(scenarios);118 model.setClassName("testing");119 return model;120 }121 @Test122 @DataProvider(value = {123 "100, 10, 100, 10",124 "100, 100, 20, 20",125 "10, 100, 10, 100",126 "1000, 500, 40, 20",127 "10, 10, 10, 10"128 })129 public void testScaleDown(int initialWidth, int initialHeight, int expectedWidth, int expectedHeight) {130 BufferedImage image = new BufferedImage(initialWidth, initialHeight, BufferedImage.TYPE_INT_BGR);131 BufferedImage thumb = scaleDown(image);132 assertThat(thumb.getWidth()).isEqualTo(expectedWidth);133 assertThat(thumb.getHeight()).isEqualTo(expectedHeight);134 }135}...

Full Screen

Full Screen

Source:AttachmentsExampleStage.java Github

copy

Full Screen

...4import com.tngtech.jgiven.annotation.ExpectedScenarioState;5import com.tngtech.jgiven.annotation.Quoted;6import com.tngtech.jgiven.attachment.Attachment;7import com.tngtech.jgiven.attachment.MediaType;8import javax.imageio.ImageIO;9import java.awt.*;10import java.awt.image.BufferedImage;11import java.io.ByteArrayOutputStream;12import java.io.IOException;13public class AttachmentsExampleStage extends Stage<AttachmentsExampleStage> {14 @ExpectedScenarioState15 CurrentStep currentStep;16 private String content;17 public void some_text_content( @Quoted String content ) {18 this.content = content;19 }20 public void it_can_be_added_as_an_attachment_to_the_step_with_title( String title ) {21 currentStep.addAttachment( Attachment.plainText( content )22 .withTitle( title ) );23 }24 public void it_can_be_added_as_an_attachment_multiple_times_to_the_step() {25 currentStep.addAttachment( Attachment.plainText( content ).withTitle( "First Attachment" ) );26 currentStep.addAttachment( Attachment.plainText( content ).withTitle( "Second Attachment" ) );27 }28 public void a_large_oval_circle() throws IOException {29 addOvalAttachment( 800, 600, Color.BLUE, "large-oval-circle" );30 }31 public void an_oval_circle() throws IOException {32 addOvalAttachment( 300, 200, Color.BLUE, "oval-circle" );33 }34 public void a_$_oval_circle( String color ) throws IOException {35 addOvalAttachment( 300, 200, getColor( color ), "oval-circle" );36 }37 public void an_oval_circle_as_thumbnail() throws IOException {38 byte[] bytes = drawOval(300, 200, Color.BLUE);39 currentStep.addAttachment(40 Attachment.fromBinaryBytes( bytes, MediaType.PNG )41 .withTitle( "An oval drawn in Java" )42 .withFileName( "oval-circle-as-thumbnail" ));43 }44 private Color getColor( String color ) {45 if( color.equals( "red" ) ) {46 return Color.RED;47 }48 return Color.BLUE;49 }50 private void addOvalAttachment(int width, int height, Color color, String fileName ) throws IOException {51 byte[] bytes = drawOval(width, height, color);52 currentStep.addAttachment(53 Attachment.fromBinaryBytes( bytes, MediaType.PNG )54 .withTitle( "An oval drawn in Java" )55 .withFileName( fileName )56 .showDirectly() );57 }58 private byte[] drawOval(int width, int height, Color color) throws IOException {59 BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );60 Graphics2D g = image.createGraphics();61 g.setRenderingHint( RenderingHints.KEY_ANTIALIASING,62 RenderingHints.VALUE_ANTIALIAS_ON );63 g.setStroke( new BasicStroke( 10 ) );64 g.setPaint( color );65 g.drawOval( 10, 10, width - 20, height - 20 );66 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();67 byte[] bytes;68 try {69 ImageIO.write( image, "PNG", outputStream );70 bytes = outputStream.toByteArray();71 } finally {72 outputStream.close();73 }74 return bytes;75 }76}...

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.attachment.MediaType;2import com.tngtech.jgiven.junit.SimpleScenarioTest;3import org.junit.Test;4public class ImageAttachmentTest extends SimpleScenarioTest<GivenStage, WhenStage, ThenStage> {5public void image_attachment() {6given().an_image_is_attached();7when().the_image_is_added_as_an_attachment();8then().the_image_is_displayed();9}10}11import com.tngtech.jgiven.attachment.MediaType;12import com.tngtech.jgiven.junit.SimpleScenarioTest;13import org.junit.Test;14public class ImageAttachmentTest extends SimpleScenarioTest<GivenStage, WhenStage, ThenStage> {15public void image_attachment() {16given().an_image_is_attached();17when().the_image_is_added_as_an_attachment();18then().the_image_is_displayed();19}20}21import com.tngtech.jgiven.attachment.MediaType;22import com.tngtech.jgiven.junit.SimpleScenarioTest;23import org.junit.Test;24public class ImageAttachmentTest extends SimpleScenarioTest<GivenStage, WhenStage, ThenStage> {25public void image_attachment() {26given().an_image_is_attached();27when().the_image_is_added_as_an_attachment();28then().the_image_is_displayed();29}30}31import com.tngtech.jgiven.attachment.MediaType;32import com.tngtech.jgiven.junit.SimpleScenarioTest;33import org.junit.Test;34public class ImageAttachmentTest extends SimpleScenarioTest<GivenStage, WhenStage, ThenStage> {35public void image_attachment() {36given().an_image_is_attached();37when().the_image_is_added_as_an_attachment();38then().the_image_is_displayed();39}40}41import com.tngtech.jgiven.attachment.MediaType;42import com.tngtech.jgiven.junit.SimpleScenarioTest;43import org.junit.Test;44public class ImageAttachmentTest extends SimpleScenarioTest<GivenStage, WhenStage, ThenStage> {45public void image_attachment() {46given().an_image_is_attached();47when().the_image_is_added_as_an_attachment();

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1package com.example;2import com.tngtech.jgiven.attachment.MediaType;3import com.tngtech.jgiven.junit5.SimpleScenarioTest;4import org.junit.jupiter.api.Test;5public class ImageTest extends SimpleScenarioTest<GivenTest, WhenTest, ThenTest> {6 public void test() {7 given().a_step();8 when().another_step();9 then().a_step();10 String path = "src/test/resources/jgiven-logo.png";11 String title = "JGiven Logo";12 String type = "image/png";13 addAttachment(title, MediaType.image(path, type));14 }15}16package com.example;17import com.tngtech.jgiven.attachment.MediaType;18import com.tngtech.jgiven.junit5.SimpleScenarioTest;19import org.junit.jupiter.api.Test;20import java.io.File;21public class ImageTest extends SimpleScenarioTest<GivenTest, WhenTest, ThenTest> {22 public void test() {23 given().a_step();24 when().another_step();25 then().a_step();26 File file = new File("src/test/resources/jgiven-logo.png");27 String title = "JGiven Logo";28 String type = "image/png";29 addAttachment(title, MediaType.image(file, type));30 }31}32package com.example;33import com.tngtech.jgiven.attachment.MediaType;34import com.tngtech.jgiven.junit5.SimpleScenarioTest;35import org.junit.jupiter.api.Test;36import java.io.FileInputStream;37import java.io.FileNotFoundException;38public class ImageTest extends SimpleScenarioTest<GivenTest, WhenTest, ThenTest> {39 public void test() throws FileNotFoundException {40 given().a_step();41 when().another_step();42 then().a_step();43 FileInputStream fileInputStream = new FileInputStream("src/test/resources/jgiven-logo.png");44 String title = "JGiven Logo";45 String type = "image/png";46 addAttachment(title, MediaType.image(fileInputStream, type));47 }48}49package com.example;50import com.t

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 JGiven automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful