-
Notifications
You must be signed in to change notification settings - Fork 130
Markup System
Anshoo Arora edited this page Aug 13, 2020
·
1 revision
Tables can be created from String[][]
or a custom object (as shown below).
public class MyCustomLog {
private List<Object> names = Arrays.asList("Anshoo", "Extent", "Klov");
private Object[] favStack = new Object[]{"Java", "C#", "Angular"};
@MarkupIgnore
private List<Object> ignored = Arrays.asList("Anshoo/Ignore", "Extent/Ignore", "Klov/Ignore");
private Map<Object, Object> items = new HashMap<Object, Object>() {
{
put("Item1", "Value1");
put("Item2", "Value2");
put("Item3", "Value3");
}
};
}
// create table as a custom log
extent.createTest("GeneratedLog")
.generateLog(Status.FAIL, MarkupHelper.toTable(new MyCustomLog(), "table-sm"));
// or as a predefined one:
extent.createTest("Log")
.fail(MarkupHelper.toTable(new MyCustomLog(), "table-sm"));
CodeBlocks are helpful if you intend to display pre-formatted code.
String code = "<root>" +
"\n <Person>" +
"\n <Name>Joe Doe</Name>" +
"\n <StartDate>2007-01-01</StartDate>" +
"\n <EndDate>2009-01-01</EndDate>" +
"\n <Location>London</Location>" +
"\n </Person>" +
"\n</root>";
Markup m = MarkupHelper.createCodeBlock(code);
test.info(m);
String json = "{'foo' : 'bar', 'foos' : ['b','a','r'], 'bar' : {'foo':'bar', 'bar':false,'foobar':1234}}";
test.pass(MarkupHelper.createCodeBlock(json, CodeLanguage.JSON));
It is possible to include upto 4 code-blocks horizontally. Considering an example of a REST API test where you have a request/response, they can both be logged in a single line.
String code = "<root>" +
"\n <Person>" +
"\n <Name>Joe Doe</Name>" +
"\n <StartDate>2007-01-01</StartDate>" +
"\n <EndDate>2009-01-01</EndDate>" +
"\n <Location>London</Location>" +
"\n </Person>" +
"\n</root>";
Markup m = MarkupHelper.createCodeBlock(code, code);
// or:
Markup m = MarkupHelper.createCodeBlocks(new String[] { code, code });
Use MarkupHelper::createOrderedList
or MarkupHelper::createUnorderedList
to display information as ordered or unordered list.
List<Object> items = Arrays.asList(new Object[] { "Item1", "Item2", "Item3" });
extent.createTest("Test").info(MarkupHelper.createOrderedList(items));
Map<Object, Object> items = new HashMap<Object, Object>()
{{
put("Item1", "Value1");
put("Item2", "Value2");
put("Item3", "Value3");
}};
extent.createTest("Test").info(MarkupHelper.createUnorderedList(items).getMarkup());
A small labeling component.
test.info(MarkupHelper.createLabel("Extent", ExtentColor.BLUE));
Copyright (c) 2020 ExtentReports - Licensed under Apache-2.0