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 org.openecomp.sdc.ci.tests.config.Config;
24 import org.openecomp.sdc.ci.tests.utils.Utils;
25 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
26 import org.testng.ITestContext;
27 import com.aventstack.extentreports.ExtentReports;
28 import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
29 import com.aventstack.extentreports.reporter.ExtentXReporter;
30 import com.aventstack.extentreports.reporter.configuration.Protocol;
31 import com.aventstack.extentreports.reporter.configuration.Theme;
32 import org.openecomp.sdc.ci.tests.config.Config;
34 import org.openecomp.sdc.ci.tests.utils.Utils;
35 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
36 import org.openecomp.sdc.ci.tests.utils.rest.AutomationUtils;
37 import org.testng.ITestContext;
41 public class ExtentManager {
43 private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
44 private static ExtentReports extent;
45 private static ExtentHtmlReporter htmlReporter;
46 private static ExtentXReporter extentxReporter;
48 public enum suiteNameXml {
50 TESTNG_FAILED_XML_NAME("testng-failed.xml");
52 suiteNameXml(String value) {
58 public String getValue() {
64 public synchronized static ExtentReports setReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
65 String dbIp = Utils.getConfig().getReportDBhost();
66 int dbPort = Utils.getConfig().getReportDBport();
69 extentxReporter = new ExtentXReporter(dbIp, dbPort);
70 extent = new ExtentReports();
71 initAndSetExtentHtmlReporter(filePath, htmlFile, isAppend);
73 if(extentxReporter.config().getReportObjectId() != null){
74 setExtentXReporter(isAppend);
76 extentxReporter.stop();
82 public synchronized static void setExtentXReporter(Boolean isAppend){
83 extentxReporter.setAppendExisting(isAppend);
84 extent.attachReporter(extentxReporter);
87 public synchronized static void initAndSetExtentHtmlReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception{
88 htmlReporter = new ExtentHtmlReporter(filePath + htmlFile);
89 setConfiguration(htmlReporter);
90 htmlReporter.setAppendExisting(isAppend);
91 extent.attachReporter(htmlReporter);
94 public synchronized static ExtentReports getReporter() {
98 public static void initReporter(String filepath, String htmlFile, ITestContext context) throws Exception {
100 String onboardVersion = AutomationUtils.getOnboardVersion();
101 String osVersion = AutomationUtils.getOSVersion();
102 Config config = Utils.getConfig();
103 String envData = config.getUrl();
104 String suiteName = getSuiteName(context);
106 if(suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())){
107 if (config.getUseBrowserMobProxy())
108 setTrafficCaptue(config);
110 setReporter(filepath, htmlFile, true);
111 String suiteNameFromVersionInfoFile = FileHandling.getKeyByValueFromPropertyFormatFile(filepath + VERSIONS_INFO_FILE_NAME, "suiteName");
112 reporterDataDefinition(onboardVersion, osVersion, envData, suiteNameFromVersionInfoFile);
114 FileHandling.deleteDirectory(ComponentBaseTest.getReportFolder());
115 FileHandling.createDirectory(filepath);
116 setReporter(filepath, htmlFile, false);
117 reporterDataDefinition(onboardVersion, osVersion, envData, suiteName);
118 AutomationUtils.createVersionsInfoFile(filepath + VERSIONS_INFO_FILE_NAME, onboardVersion, osVersion, envData, suiteName);
123 public static void reporterDataDefinition(String onboardVersion, String osVersion, String envData, String suiteNameFromVersionInfoFile) throws Exception {
124 extent.setSystemInfo("Onboard Version", onboardVersion);
125 extent.setSystemInfo("OS Version", osVersion);
126 // extent.setSystemInfo("Host Name Address", RestCDUtils.getExecutionHostAddress());
127 extent.setSystemInfo("ExecutedOn", envData);
128 extent.setSystemInfo("SuiteName", suiteNameFromVersionInfoFile);
131 public static String getSuiteName(ITestContext context) {
132 String suitePath = context.getSuite().getXmlSuite().getFileName();
133 if(suitePath != null){
134 File file = new File(suitePath);
135 String suiteName = file.getName();
141 public synchronized static ExtentHtmlReporter setConfiguration(ExtentHtmlReporter htmlReporter) throws Exception {
143 htmlReporter.config().setTheme(Theme.STANDARD);
144 htmlReporter.config().setEncoding("UTF-8");
145 htmlReporter.config().setProtocol(Protocol.HTTPS);
146 htmlReporter.config().setDocumentTitle("SDC Automation Report");
147 htmlReporter.config().setChartVisibilityOnOpen(true);
148 // htmlReporter.config().setReportName(AutomationUtils.getATTVersion());
149 htmlReporter.config().setReportName("SDC Automation Report");
150 htmlReporter.config().setChartVisibilityOnOpen(false);
151 // htmlReporter.config().setJS(icon);
155 public static void closeReporter(){
159 public static void setTrafficCaptue(Config config) {
160 boolean mobProxyStatus = config.getUseBrowserMobProxy();
162 config.setCaptureTraffic(true);;