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.api;
23 import com.aventstack.extentreports.ExtentReports;
24 import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
25 import com.aventstack.extentreports.reporter.ExtentXReporter;
26 import com.aventstack.extentreports.reporter.configuration.Protocol;
27 import com.aventstack.extentreports.reporter.configuration.Theme;
28 import org.openecomp.sdc.ci.tests.config.Config;
29 import org.openecomp.sdc.ci.tests.utils.Utils;
30 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
31 import org.openecomp.sdc.ci.tests.utils.rest.AutomationUtils;
32 import org.testng.ITestContext;
36 public class ExtentManager {
38 private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
39 private static ExtentReports extent;
40 private static ExtentHtmlReporter htmlReporter;
41 private static ExtentXReporter extentxReporter;
43 public enum suiteNameXml {
45 TESTNG_FAILED_XML_NAME("testng-failed.xml");
47 suiteNameXml(String value) {
53 public String getValue() {
59 public synchronized static ExtentReports setReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
60 String dbIp = Utils.getConfig().getReportDBhost();
61 int dbPort = Utils.getConfig().getReportDBport();
64 extentxReporter = new ExtentXReporter(dbIp, dbPort);
65 extent = new ExtentReports();
66 initAndSetExtentHtmlReporter(filePath, htmlFile, isAppend);
68 if(extentxReporter.config().getReportObjectId() != null){
69 setExtentXReporter(isAppend);
71 extentxReporter.stop();
77 public synchronized static void setExtentXReporter(Boolean isAppend){
78 extentxReporter.setAppendExisting(isAppend);
79 extent.attachReporter(extentxReporter);
82 public synchronized static void initAndSetExtentHtmlReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception{
83 htmlReporter = new ExtentHtmlReporter(filePath + htmlFile);
84 setConfiguration(htmlReporter);
85 htmlReporter.setAppendExisting(isAppend);
86 extent.attachReporter(htmlReporter);
89 public synchronized static ExtentReports getReporter() {
93 public static void initReporter(String filepath, String htmlFile, ITestContext context) throws Exception {
95 String onboardVersion = AutomationUtils.getOnboardVersion();
96 String osVersion = AutomationUtils.getOSVersion();
97 Config config = Utils.getConfig();
98 String envData = config.getUrl();
99 String suiteName = getSuiteName(context);
101 if(suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())){
102 if (config.getUseBrowserMobProxy())
103 setTrafficCaptue(config);
105 setReporter(filepath, htmlFile, true);
106 String suiteNameFromVersionInfoFile = FileHandling.getKeyByValueFromPropertyFormatFile(filepath + VERSIONS_INFO_FILE_NAME, "suiteName");
107 reporterDataDefinition(onboardVersion, osVersion, envData, suiteNameFromVersionInfoFile);
109 FileHandling.deleteDirectory(ComponentBaseTest.getReportFolder());
110 FileHandling.createDirectory(filepath);
111 setReporter(filepath, htmlFile, false);
112 reporterDataDefinition(onboardVersion, osVersion, envData, suiteName);
113 AutomationUtils.createVersionsInfoFile(filepath + VERSIONS_INFO_FILE_NAME, onboardVersion, osVersion, envData, suiteName);
118 public static void reporterDataDefinition(String onboardVersion, String osVersion, String envData, String suiteNameFromVersionInfoFile) throws Exception {
119 extent.setSystemInfo("Onboard Version", onboardVersion);
120 extent.setSystemInfo("OS Version", osVersion);
121 // extent.setSystemInfo("Host Name Address", RestCDUtils.getExecutionHostAddress());
122 extent.setSystemInfo("ExecutedOn", envData);
123 extent.setSystemInfo("SuiteName", suiteNameFromVersionInfoFile);
126 public static String getSuiteName(ITestContext context) {
127 String suitePath = context.getSuite().getXmlSuite().getFileName();
128 if(suitePath != null){
129 File file = new File(suitePath);
130 String suiteName = file.getName();
136 public synchronized static ExtentHtmlReporter setConfiguration(ExtentHtmlReporter htmlReporter) throws Exception {
138 htmlReporter.config().setTheme(Theme.STANDARD);
139 htmlReporter.config().setEncoding("UTF-8");
140 htmlReporter.config().setProtocol(Protocol.HTTPS);
141 htmlReporter.config().setDocumentTitle("SDC Automation Report");
142 htmlReporter.config().setChartVisibilityOnOpen(true);
143 // htmlReporter.config().setReportName(AutomationUtils.getATTVersion());
144 htmlReporter.config().setReportName("SDC Automation Report");
145 htmlReporter.config().setChartVisibilityOnOpen(false);
146 // htmlReporter.config().setJS(icon);
150 public static void closeReporter(){
154 public static void setTrafficCaptue(Config config) {
155 boolean mobProxyStatus = config.getUseBrowserMobProxy();
157 config.setCaptureTraffic(true);;