2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.execute.setup;
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.ci.tests.execute.setup.ExtentManager.suiteNameXml;
25 import org.testng.ITestContext;
26 import org.testng.ITestResult;
28 import java.io.IOException;
30 public class ReportAfterTestManager extends ExtentTestActions {
32 private static String testName;
33 private static Throwable throwable;
34 private static int status;
36 private static void logSuccessAfterTest(){
37 final Status logStatus = Status.PASS;
38 addTag(logStatus, "Success");
40 String message = "Finished the test with the following screenshot : ";
41 addScreenshotToReport(logStatus, testName, message);
43 log(logStatus, "SUCCESS - The following exepction occured : " + e.getMessage());
47 private static void logFailAfterTest(){
48 addTag(Status.FAIL, "Failure");
50 log(Status.ERROR, "ERROR - The following exepction occured : ");
51 log(Status.ERROR, throwable);
52 String message = "Failure is described in the following screenshot : ";
53 addScreenshotToReport(Status.FAIL, testName, message);
55 log(Status.ERROR, "ERROR - The following exepction occured : " + e.getMessage());
59 private static void logSkipAfterTest(){
60 final Status logStatus = Status.SKIP;
61 addTag(logStatus, "Skipped");
63 log(logStatus, "SKIP - The following exepction occured : ");
64 log(logStatus, throwable);
65 String message = "Skip is described in the following screenshot : ";
66 addScreenshotToReport(logStatus, testName, message);
68 log(logStatus, "SKIP - The following exepction occured : " + e.getMessage());
71 private static void logFatalAfterTest(){
72 final Status logStatus = Status.FATAL;
73 addTag(logStatus, "Fatal");
75 log(logStatus, "FATAL - The following exepction occured : ");
76 log(logStatus, throwable);
77 String message = "Fatal is described in the following screenshot : ";
78 addScreenshotToReport(logStatus, testName, message);
80 log(logStatus, "FATAL - The following exepction occured : " + e.getMessage());
84 private static String addScreenshotToReport(Status logStatus, String testName, String message) throws IOException{
86 String addedValueFromDataProvider = WindowTestManager.getWindowMap().getAddedValueFromDataProvider();
87 if (addedValueFromDataProvider != null){
88 addedValueFromDataProvider = addedValueFromDataProvider.replace(":", "-");
89 testName = testName + "...." + addedValueFromDataProvider;
92 return addScreenshot(logStatus, testName, message);
95 public static void report(ITestResult result, ITestContext context){
97 testName = result.getName();
98 throwable = result.getThrowable();
99 status = result.getStatus();
101 String suiteName = ExtentManager.getSuiteName(context);
104 case ITestResult.SUCCESS:
105 logSuccessAfterTest();
108 case ITestResult.FAILURE:
110 if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
117 case ITestResult.SKIP: