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 java.io.IOException;
25 import org.openecomp.sdc.ci.tests.execute.setup.ExtentManager.suiteNameXml;
26 import org.testng.ITestContext;
27 import org.testng.ITestResult;
29 import com.aventstack.extentreports.Status;
31 public class ReportAfterTestManager extends ExtentTestActions {
33 private static String testName;
34 private static Throwable throwable;
35 private static int status;
37 private static void logSuccessAfterTest(){
38 final Status logStatus = Status.PASS;
39 addTag(logStatus, "Success");
41 String message = "Finished the test with the following screenshot : ";
42 addScreenshotToReport(logStatus, testName, message);
44 log(logStatus, "SUCCESS - The following exepction occured : " + e.getMessage());
48 private static void logFailAfterTest(){
49 addTag(Status.FAIL, "Failure");
51 log(Status.ERROR, "ERROR - The following exepction occured : ");
52 log(Status.ERROR, throwable);
53 String message = "Failure is described in the following screenshot : ";
54 addScreenshotToReport(Status.FAIL, testName, message);
56 log(Status.ERROR, "ERROR - The following exepction occured : " + e.getMessage());
60 private static void logSkipAfterTest(){
61 final Status logStatus = Status.SKIP;
62 addTag(logStatus, "Skipped");
64 log(logStatus, "SKIP - The following exepction occured : ");
65 log(logStatus, throwable);
66 String message = "Skip is described in the following screenshot : ";
67 addScreenshotToReport(logStatus, testName, message);
69 log(logStatus, "SKIP - The following exepction occured : " + e.getMessage());
72 private static void logFatalAfterTest(){
73 final Status logStatus = Status.FATAL;
74 addTag(logStatus, "Fatal");
76 log(logStatus, "FATAL - The following exepction occured : ");
77 log(logStatus, throwable);
78 String message = "Fatal is described in the following screenshot : ";
79 addScreenshotToReport(logStatus, testName, message);
81 log(logStatus, "FATAL - The following exepction occured : " + e.getMessage());
85 private static String addScreenshotToReport(Status logStatus, String testName, String message) throws IOException{
87 String addedValueFromDataProvider = WindowTestManager.getWindowMap().getAddedValueFromDataProvider();
88 if (addedValueFromDataProvider != null){
89 addedValueFromDataProvider = addedValueFromDataProvider.replace(":", "-");
90 testName = testName + "...." + addedValueFromDataProvider;
93 return addScreenshot(logStatus, testName, message);
96 public static void report(ITestResult result, ITestContext context){
98 testName = result.getName();
99 throwable = result.getThrowable();
100 status = result.getStatus();
102 String suiteName = ExtentManager.getSuiteName(context);
105 case ITestResult.SUCCESS:
106 logSuccessAfterTest();
109 case ITestResult.FAILURE:
111 if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
118 case ITestResult.SKIP: