Closed abc9876543210 closed 8 years ago
Your version?
version 2.40.2, i referred to user docs on http://extentreports.relevantcodes.com/java/version2/docs.html#
i know these are categories made,but could you please provide sample code for above type report.
pretty simple to recreate this example, simply go thru docs and you will know how to..
The below code should help you for starters.
public class Main { private ExtentReports logger = new ExtentReports("C:\workspace\Screenshot.html"); private ExtentTest test = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
logger.loadConfig(new File("C:\\workspace\\extent-config.xml"));
test = logger.startTest("Login completed");
test.log(LogStatus.PASS, "Login", "Login successfull.");
logger.endTest(test);
logger.flush();
logger.close();
}
}
Here you go:
public class Extent {
public static void main(String[] args) {
ExtentReports extent = new ExtentReports("Extent.html", true);
String json = "{" +
"\"id\": 1," +
"\"name\": \"A green door\"," +
"\"price\": 12.50," +
"\"tags\": [\"home\", \"green\"]" +
"}";
String message = "This test shows how a category is displayed. Assigning a category also " +
"enables the Categories view.";
ExtentTest test = extent.startTest("CategoryTest", message);
test.assignCategory("ExtentAPI", "Category");
test.log(LogStatus.PASS, "A category was addedas");
test.log(LogStatus.INFO, "<pre>" + json + "</pre>");
extent.endTest(test);
message = "This test shows an example of an author assigned.";
test = extent.startTest("AuthorTest", message);
test.assignAuthor("Anshoo");
test.log(LogStatus.FAIL, "An author was added");
extent.endTest(test);
Exception nullPointerEx = new NullPointerException("A NullPointer occured.");
message = "This test shows an example of how exceptions are displayed. " +
"Logging an exception also creates the Exceptions view.";
test = extent.startTest("ExceptionTest", message);
test.assignCategory("ExtentAPI", "IntentionalException");
test.log(LogStatus.FAIL, nullPointerEx);
extent.endTest(test);
message = "HTML can be embedded anywhere in the report to create meaningful logs and messages.";
test = extent.startTest("HTMLTagsTest", message);
String labelMessage = "Labels can be created using: " +
"<span class='success label'>Success</span> " +
"<span class='fail label'>Fail</span> " +
"<span class='warning label'>Warning</span> " +
"<span class='info label'>Info</span> " +
"<span class='skip label'>Skip</span>";
test.log(LogStatus.PASS, labelMessage);
labelMessage = "<pre>"+
"<span class='success label'>Success</span> <br />" +
"<span class='fail label'>Fail</span> <br />" +
"<span class='warning label'>Warning</span> <br />" +
"<span class='info label'>Info</span> <br />" +
"<span class='skip label'>Skip</span>" +
"</pre>";
test.log(LogStatus.PASS, labelMessage);
test.log(LogStatus.PASS, "Link <a href='http://extentreports.relevantcodes.com/'>Linky</a>");
test.log(LogStatus.PASS, "<pre><a href='http://extentreports.relevantcodes.com/'>Linky</a></pre>");
extent.endTest(test);
test = extent.startTest("NodesTest");
ExtentTest child1 = extent.startTest("Child Node Level 1").assignCategory("Node");
child1.log(LogStatus.INFO, "INFO");
ExtentTest childLevel2 = extent.startTest("Child Node Level 2").assignCategory("Node");;
childLevel2.log(LogStatus.ERROR, "ERROR");
ExtentTest childLevel3 = extent.startTest("Child Node Level 3").assignCategory("Node");;
childLevel3.log(LogStatus.WARNING, "WARNING");
ExtentTest childLevel4 = extent.startTest("Child Node Level 4").assignCategory("Node");;
childLevel4.log(LogStatus.SKIP, "SKIP");
ExtentTest childLevel5 = extent.startTest("Child Node Level 5").assignCategory("Node");;
childLevel5.log(LogStatus.PASS, "PASS");
test.appendChild(child1);
test.appendChild(childLevel2);
test.appendChild(childLevel3);
test.appendChild(childLevel4);
test.appendChild(childLevel5);
childLevel2 = extent.startTest("Child Node Level 2").assignCategory("Node");;
childLevel2.log(LogStatus.ERROR, "ERROR");
test.appendChild(childLevel2);
extent.endTest(test);
test = extent.startTest("MediaTest");
test.log(LogStatus.INFO, test.addScreenCapture("./1.png"));
test.log(LogStatus.INFO, test.addScreenCapture("2.png"));
test.log(LogStatus.INFO, test.addBase64ScreenShot(" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMoAAAAYCAYAAAC7k2KMAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAAi4SURBVHhe7ZstsBRHFIWfQCAQCAQCgUAgEAgEAoGIQ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pVYhsT9DQEmeZu0PMDMS/luQJGaAkXKp5fdXknadaB4u93whLlAYU3IC2+R/pOn9zbfVKCA5GtufsNPiXKgTHailNun9H5U9R6k/LzHHWJtoHAi5C8vLnmFhXv33x6OgqVcx+rzGYk83rbD5lpaHChSfhXmnaXt1Eck789znjAZKH26P2iDaym9qaJun9Mybit2Figg8cZolO33tzhQQOKFQs9/M6Uvugcpv3IzmcfTc5oj5brxUuTGg1Ipz44wvJFtdnlU56Cj+OBVYqZ256YdWl+KZAnJCZkfwvDZTwh35iOSD6CfumuWOBsovQ2VDRuWLUOFJK8oowfLmBLdMwfJ7Ut2HWvKbkGiE/z0KmgKFEj2o1dGpMUdKfkafDKPp+e0jMTGPt8ndWSJR5t6/QKW3MWTPIkAyHkICPJQfwYg37hH+ugFRMnbjKWZ9ycHHKXHElwbHU9LTT7CX7vm5JPebsCbqvBUoDCF+rqZkWnJcxRn4x+35lhTdiuSPyEP1gRKXpa8sTS/h1qg5OVSMY+n57QSEoOCL4GmIIDq7z99XXL6pncKZh/2eKW9rbfxEpi9Sm2xa/9jBn40lG8/VA0UkFgn+pFxt0aVdl3RjjVlr0HKHd4cKCBx5OlLhDjq9XuYDRSQ+MezsC/m8fScNofEbMASi3U4fUl9CUxGcN6Bqr6S40gsFzmIYDZhFqE8BlGemfAvx5P3K80FCjMHIzzlEGiT79VJu/I/2oFgHJ7Kd/b+Zc+ePWWKF/fs2eMcHvwHRtCmdoL3r8UAAAAASUVORK5CYII="));
extent.endTest(test);
test = extent.startTest("SkippedTest").assignCategory("ExtentAPI");;
test.log(LogStatus.SKIP, "Skip");
test.log(LogStatus.PASS, "Pass");
test.log(LogStatus.INFO, "Info");
extent.endTest(test);
extent.setTestRunnerOutput("You can send all logs from your TestRunner (such as JUnit, TestNG etc) to Extent by using:");
extent.setTestRunnerOutput("<pre>for (String s : Reporter.getOutput()) { <br /> extent.setTestRunnerOutput(s); <br />}</pre>");
extent.flush();
}
}
thanx a lot
I am getting categories page like this. @anshooarora Can you please tell me how to get PASS fail details for each category shown on Dashboard
please provide sample code for making report as shown on:
http://relevantcodes.com/Tools/ExtentReports2/ExtentJava.html#!
because when i add jar my report does not comes as shown on this link and could not get help from java docs provided,so please provide sample code to make this format report.