package com.junit5.allure2report_addattachment_l3.addhtml;
import io.qameta.allure.Allure;
import io.qameta.allure.Attachment;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
@DisplayName("Allure2测试报告添加html")
public class HtmlTest {
/**
* 注解:String类型
*/
@Test
@DisplayName("html注解:注解形式添加")
public void testAddHtmlForStringWithAn() throws IOException {
File file = new File("allure2.html");
// BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line=bufferedReader.readLine())!=null){
stringBuffer.append(new String(line.getBytes(), "GBK"));
stringBuffer.append(System.lineSeparator());
}
attachTextFileWithString(stringBuffer.toString(),"百度首页注解");
}
@Attachment(value = "htmlName",type = "text/html")
String attachTextFileWithString(String contents,String htmlName){
System.out.println("htmlName:"+htmlName);
return contents;
}
@Test
@DisplayName("Html:调用方法添加")
public void testAddHtmlForStreamWithMethod() throws IOException {
Allure.addAttachment("stream流添加html",
"text/html",
Files.newInputStream(Paths.get("allure2.html")),
"html");
}
}
/**
* TEXT = ("text/plain", "txt")
* CSV = ("text/csv", "csv")
* TSV = ("text/tab-separated-values", "tsv")
* URI_LIST = ("text/uri-list", "uri")
*
* HTML = ("text/html", "html")
* XML = ("application/xml", "xml")
* JSON = ("application/json", "json")
* YAML = ("application/yaml", "yaml")
* PCAP = ("application/vnd.tcpdump.pcap", "pcap")
*
* PNG = ("image/png", "png")
* JPG = ("image/jpg", "jpg")
* SVG = ("image/svg-xml", "svg")
* GIF = ("image/gif", "gif")
* BMP = ("image/bmp", "bmp")
* TIFF = ("image/tiff", "tiff")
*
* MP4 = ("video/mp4", "mp4")
* OGG = ("video/ogg", "ogg")
* WEBM = ("video/webm", "webm")
*
* PDF = ("application/pdf", "pdf")
*/
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.