Sync Integ to Master
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / setup / SetupCDTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.setup;
22
23 import java.io.File;
24 import java.io.FileWriter;
25 import java.io.IOException;
26 import java.util.Arrays;
27 import java.util.Map;
28 import java.util.UUID;
29 import java.util.logging.FileHandler;
30 import java.util.logging.Handler;
31 import java.util.logging.LogManager;
32 import java.util.logging.Logger;
33
34 import org.json.simple.JSONObject;
35 import org.littleshoot.proxy.impl.ClientToProxyConnection;
36 import org.littleshoot.proxy.impl.ProxyToServerConnection;
37 import org.openecomp.sdc.be.model.User;
38 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestManager;
39 import org.openecomp.sdc.ci.tests.api.SomeInterface;
40 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.UserCredentials;
42 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
43 import org.openecomp.sdc.ci.tests.execute.sanity.OnboardingFlowsUI;
44 import org.openecomp.sdc.ci.tests.execute.setup.ExtentManager.suiteNameXml;
45 import org.openecomp.sdc.ci.tests.pages.HomePage;
46 import org.openecomp.sdc.ci.tests.run.StartTest;
47 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
48 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
49 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
50 import org.openecomp.sdc.ci.tests.utils.rest.AutomationUtils;
51 import org.openqa.selenium.By;
52 import org.openqa.selenium.JavascriptExecutor;
53 import org.openqa.selenium.WebDriver;
54 import org.openqa.selenium.WebElement;
55 import org.openqa.selenium.support.ui.ExpectedConditions;
56 import org.openqa.selenium.support.ui.WebDriverWait;
57 import org.slf4j.LoggerFactory;
58 import org.testng.Assert;
59 import org.testng.ITestContext;
60 import org.testng.ITestResult;
61 import org.testng.annotations.AfterMethod;
62 import org.testng.annotations.AfterSuite;
63 import org.testng.annotations.BeforeMethod;
64 import org.testng.annotations.BeforeSuite;
65 import org.testng.annotations.Optional;
66 import org.testng.annotations.Parameters;
67 import org.testng.annotations.Test;
68
69 import com.aventstack.extentreports.ExtentReports;
70 import com.aventstack.extentreports.ExtentTest;
71 import com.aventstack.extentreports.Status;
72
73 import ch.qos.logback.classic.Level;
74 import ch.qos.logback.classic.LoggerContext;
75 import groovyjarjarantlr.Utils;
76 import net.lightbody.bmp.BrowserMobProxyServer;
77 import net.lightbody.bmp.core.har.Har;
78
79 public abstract class SetupCDTest extends DriverFactory {
80         
81 //      private static final String RE_RUN = "ReRun - ";
82         private static final String RE_RUN = "<html><font color=\"red\">ReRun - </font></html>";
83         private static final String WEB_SEAL_PASSWORD = "123123a";
84
85         public SetupCDTest() {
86                 LoggerContext lc = (LoggerContext) LoggerFactory. getILoggerFactory();
87                 lc.getLogger("org.apache").setLevel(Level.INFO);            
88         }
89
90         /**************** CONSTANTS ****************/
91         private static final String CREDENTIALS_FILE = "credentials.yaml";
92         private static final String REPORT_FILE_NAME = "SDC_UI_Extent_Report.html";
93         protected static final String REPORT_FOLDER = "." + File.separator + "ExtentReport" + File.separator;
94         protected static final String SCREENSHOT_FOLDER = REPORT_FOLDER + "screenshots" + File.separator;
95         protected static final String HAR_FILES_FOLDER_NAME = "har_files";
96         protected static final String HAR_FILES_FOLDER = REPORT_FOLDER + HAR_FILES_FOLDER_NAME + File.separator;
97         
98
99         private static final String SHORT_CSV_REPORT_FILE_NAME = "ShortReport.csv";
100         private static final int NUM_OF_ATTEMPTS_TO_REFTRESH = 2;
101         
102
103         /**************** PRIVATES ****************/
104         private static String url;
105         private static boolean localEnv = true;
106         private static OnboardCSVReport csvReport;
107         private static Map<?, ?> credentials;
108         
109     protected static ITestContext myContext;
110         
111         
112         /**************** METHODS ****************/
113         public static ExtentTest getExtendTest() {
114                 SomeInterface testManager = new ExtentTestManager(); 
115                 return testManager.getTest();
116         }
117         public static WindowTest getWindowTest(){
118                 return WindowTestManager.getWindowMap();
119         }
120         
121         public OnboardCSVReport getCsvReport() {
122                 return csvReport;
123         }
124         
125         public static String getReportFolder() {
126                 return REPORT_FOLDER;
127         }
128         
129         public static String getScreenshotFolder() {
130                 return SCREENSHOT_FOLDER;
131         }
132         
133         public static String getHarFilesFolder() {
134                 return HAR_FILES_FOLDER;
135         }
136         
137         
138         protected abstract UserRoleEnum getRole();
139         
140         /**************** BEFORE ****************/
141
142         @BeforeSuite(alwaysRun = true)
143         public void setupBeforeSuite(ITestContext context) throws Exception {
144                 RestCDUtils.deleteOnDemand();
145                 myContext=context;
146                 setErrorConfigurationFile();
147                 setUrl();
148                 ExtentManager.initReporter(getReportFolder(), REPORT_FILE_NAME, context);               
149                 csvReport = new OnboardCSVReport(getReportFolder(), SHORT_CSV_REPORT_FILE_NAME);
150         }
151         
152         private static void setErrorConfigurationFile() {
153                 if (!System.getProperty("os.name").contains("Windows")){
154                         String errorConfigurationFilename = getConfig().getErrorConfigurationFile();
155                         errorConfigurationFilename = errorConfigurationFilename.substring(errorConfigurationFilename.lastIndexOf("/") + 1, errorConfigurationFilename.length());
156                         getConfig().setErrorConfigurationFile(FileHandling.getBasePath() + File.separator + "conf" + File.separator + errorConfigurationFilename);
157                         if (new File(getConfig().getErrorConfigurationFile()).exists()){
158                                 System.out.println("Found error-configuration.yaml in : " + getConfig().getErrorConfigurationFile());
159                         }
160                 }
161         }
162         
163         @BeforeMethod(alwaysRun = true )
164         public void setBrowserBeforeTest(java.lang.reflect.Method method, ITestContext context) throws Exception {
165                 
166                 boolean emptyDataProvider = method.getAnnotation(Test.class).dataProvider().isEmpty();
167                 String className = method.getDeclaringClass().getName();
168                 if (emptyDataProvider && !className.contains("ToscaValidationTest") ) {
169                         System.out.println("ExtentReport instance started from BeforeMethod...");
170                         String suiteName = ExtentManager.getSuiteName(context);
171                         if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
172                                 ExtentTestManager.startTest(RE_RUN + method.getName());
173                         }else{
174                                 ExtentTestManager.startTest(method.getName());
175                         }
176                 
177                         ExtentTestManager.assignCategory(this.getClass());
178                         setBrowserBeforeTest(getRole());
179                 } else {
180                         System.out.println("ExtentReport instance started from Test...");
181                 }
182                 
183                 getConfig().setWindowsDownloadDirectory(getWindowTest().getDownloadDirectory());
184                 
185                 if (getConfig().getCaptureTraffic()){
186                         try{
187                             MobProxy.getPoxyServer().newHar(method.getName() + ".har");
188                         } catch (Throwable e) {
189                                 e.printStackTrace();
190                         }
191                 }               
192         }
193         
194         /**************** AFTER ****************/
195         @AfterMethod(alwaysRun = true)
196         public void quitAfterTest(ITestResult result, ITestContext context) throws Exception {
197                 
198                 try{
199                         ReportAfterTestManager.report(result, context);
200                         GeneralUIUtils.closeErrorMessage();
201                 }
202                 finally{
203                         try {
204                                 if (getConfig().getCaptureTraffic()){
205                                         addTrafficFileToReport(result);                         
206                                 }
207                                 
208                                 if (result.getInstanceName().equals(OnboardingFlowsUI.class.getName())  && result.getStatus() == ITestResult.FAILURE){
209                                         System.out.println("Onboarding test failed, closign browser....");
210                                         getExtendTest().log(Status.INFO, "Onboarding test failed, closing browser....");
211                                         quitDriver();
212                                 }
213                                 else if (!getUser().getRole().toLowerCase().equals(UserRoleEnum.ADMIN.name().toLowerCase())){
214                                         boolean navigateToHomePageSuccess = HomePage.navigateToHomePage();
215                                         if (!navigateToHomePageSuccess){
216                                                 System.out.println("Navigating to homepage failed, reopening driver....");
217                                                 getExtendTest().log(Status.INFO, "Navigating to homepage failed, reopening driver....");
218                                                 quitDriver();
219                                         }
220                                 }
221                                 
222                         } catch (Exception e) {
223                                 e.printStackTrace();
224                                                 getExtendTest().log(Status.ERROR, "Exception:"+ e.toString());
225                         } 
226                         
227                         
228                         
229                 ExtentTestManager.endTest();
230                         String suiteName = ExtentManager.getSuiteName(context);
231 //                      write result to csv file
232                         if((!suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) && (result.getStatus() == ITestResult.SKIP)) {
233                                 addResultToCSV(result, context);
234                         }
235                         if(suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue()) && !(result.getStatus() == ITestResult.SUCCESS)) {
236                                 addResultToCSV(result, context);
237                         }
238 //              ExtentManager.closeReporter();
239                 FileHandling.cleanCurrentDownloadDir();
240         }
241
242         }
243         public void addResultToCSV(ITestResult result, ITestContext context) {
244 //              String suiteName = ExtentManager.getSuiteName(context);
245                 ExtentTest test = getExtendTest();
246                 com.aventstack.extentreports.model.Test model = test.getModel();
247                 String name = model.getName();
248                 String status = model.getStatus().toString();
249 //              if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue()) && !(result.getStatus() == ITestResult.SUCCESS)) {
250                         getCsvReport().writeRow(result.getInstanceName(), name.replace(RE_RUN,""), status);
251 //              }
252         }
253         
254         public void generateReport4Jenkins(ITestContext context) {
255                 String suiteName = ExtentManager.getSuiteName(context); 
256 //              String outputDirectory = context.getOutputDirectory();
257             JSONObject obj = new JSONObject();
258             String success = Integer.toString(context.getPassedTests().size());
259             String failed = Integer.toString(context.getFailedTests().size());
260             String total = Integer.toString(context.getFailedTests().size()+context.getPassedTests().size());
261         obj.put("projectName", "SDC-ONAP-UI-Automation-"+suiteName);
262         obj.put("projectVersion",  AutomationUtils.getOSVersion());
263         obj.put("platform", "Linux");
264         obj.put("total", total);
265         obj.put("success", success);
266         obj.put("failed", failed);
267         
268         try (FileWriter file = new FileWriter(getReportFolder() + "jenkinsResults.json")) {
269
270             file.write(obj.toJSONString());
271             file.flush();
272
273         } catch (IOException e) {
274             e.printStackTrace();
275         }
276
277         System.out.print(obj);
278                 
279                 
280         }
281         
282         
283         @Parameters({ "eraseAfterTests" })
284         @AfterSuite(alwaysRun = true)   
285         public void afterSuite2(@Optional("true") String eraseAfterTestsReadValue) throws Exception  {
286 //              public void afterSuite() throws Exception  {
287                 
288                 csvReport.closeFile();
289                 generateReport4Jenkins(myContext);
290                 
291                 if (Boolean.parseBoolean(eraseAfterTestsReadValue)){
292                         RestCDUtils.deleteOnDemand();
293                 } else {
294                         System.out.println("Resources will not be deleted according to suite configuration ...");
295                 }
296                 
297                 if (getConfig().getUseBrowserMobProxy()){
298                         MobProxy.getPoxyServer().stop();
299                 }
300         }
301         
302         protected static String setUrl() {
303                 url = getConfig().getUrl();
304                 if (url == null) {
305                         String message = "no URL found";
306                         System.out.println(message);
307                         Assert.fail(message);
308                 } else if (!url.contains("localhost") && !url.contains("192.168.33.10") && !url.contains("127.0.0.1")) {
309                         localEnv = false;
310                 }
311                 return url;
312         }
313
314         public static void loadCredentialsFile() throws Exception {
315                 if (credentials != null){
316                         return;
317                 }
318                 File credentialsFileRemote = new File(FileHandling.getBasePath() + File.separator + "conf" + File.separator + CREDENTIALS_FILE);
319 //              File credentialsFileLocal = new File(FileHandling.getConfFilesPath() + CREDENTIALS_FILE);
320                 File credentialsFileLocal = new File(FileHandling.getSdcVnfsPath() + File.separator + "conf" 
321                                 + File.separator + CREDENTIALS_FILE);
322                 File[] credentialFiles = {credentialsFileRemote, credentialsFileLocal};
323                 for (File credentialsFile : credentialFiles){
324                         if (credentialsFile.exists()){
325                                 credentials = FileHandling.parseYamlFile(credentialsFile.getAbsolutePath());
326                                 break;
327                         }
328                 }
329         }
330
331         private UserCredentials getUserCredentialsFromFile(String userRole) throws Exception {
332                 @SuppressWarnings("unchecked")
333                 Map<String, String> credentialsMap = (Map<String, String>) credentials.get(userRole);
334                 String user = (String) credentialsMap.get("username");
335                 String password = (String) credentialsMap.get("password");
336                 String firstname = (String) credentialsMap.get("firstname");
337                 String lastname = (String) credentialsMap.get("lastname");
338
339                 return new UserCredentials(user, password, firstname, lastname, userRole);
340         }
341
342
343         public static void navigateToUrl(String url) throws Exception {
344                 try {
345                         System.out.println("Deleting cookies...");
346                         deleteCookies();
347
348                         System.out.println("Navigating to URL : " + url);
349                         getDriver().navigate().to(url);
350                         GeneralUIUtils.waitForLoader();
351                         
352                         System.out.println("Zooming out...");
353                         GeneralUIUtils.windowZoomOutUltimate();
354                         
355                 } 
356                 catch (Exception e) {
357                         String msg = "Browser is unreachable";
358                         System.out.println(msg);
359                         getExtendTest().log(Status.ERROR, msg);
360                         Assert.fail(msg);
361                 }
362         }
363         private static void deleteCookies() throws Exception {
364                 getDriver().manage().deleteAllCookies();
365                 Thread.sleep(1000);
366                 
367                 int attempts = 0;
368                 final int max_attempts = 3;
369                 
370                 while (!getDriver().manage().getCookies().isEmpty() && attempts < max_attempts){
371                         getExtendTest().log(Status.INFO, "Trying to delete cookies one more time - " + (attempts + 1) + "/" + max_attempts + "attempts");
372                         String deleteCookiesJS = "document.cookie.split(';').forEach(function(c) { document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/'); });";
373                         ((JavascriptExecutor) getDriver()).executeScript(deleteCookiesJS);
374                         attempts++;
375                         
376                         if (attempts == max_attempts){
377                                 String msg = "Did not delete cookies, can't login as user " + WindowTestManager.getWindowMap().getUser().getRole();
378                                 System.out.println(msg);
379                                 getExtendTest().log(Status.ERROR, msg);
380                                 Assert.fail(msg);
381                         }
382                 }
383         }
384         
385         protected void loginToSystem(UserRoleEnum role) throws Exception {
386                 UserCredentials credentials;
387                 if (localEnv){
388                         loginToSimulator(role);
389                         credentials = new UserCredentials(role.getUserId(), WEB_SEAL_PASSWORD, role.getFirstName(), role.getLastName(), role.name());
390                 }
391                 else{
392                         credentials = getUserFromFileByRole(role);
393                         sendUserAndPasswordKeys(credentials);
394                         WebElement submitButton = GeneralUIUtils.getWebElementBy(By.name("btnSubmit"), 30);
395                         submitButton.click();
396                         WebElement buttonOK = GeneralUIUtils.getWebElementBy(By.name("successOK"), 30);
397                         Assert.assertTrue(buttonOK.isDisplayed(), "OK button is not displayed.");
398                         buttonOK.click();
399                 }
400                 GeneralUIUtils.ultimateWait();                   
401                 getWindowTest().setUser(credentials);
402         }
403         protected UserCredentials getUserFromFileByRole(UserRoleEnum role) throws Exception {
404                 loadCredentialsFile();
405                 return getUserCredentialsFromFile(role.name().toLowerCase());
406         }
407         private void goToHomePage(UserRoleEnum role) throws Exception {
408                 try {
409                         getWindowTest().setRefreshAttempts(getWindowTest().getRefreshAttempts() == 0 ? NUM_OF_ATTEMPTS_TO_REFTRESH : getWindowTest().getRefreshAttempts());
410                         if (!role.equals(UserRoleEnum.ADMIN)) {
411                                 
412                                 WebElement closeButton = GeneralUIUtils.getClickableButtonBy(By.className("sdc-welcome-close"), 10);
413                                 if (closeButton != null){
414                                         closeButton.click();
415                                 }
416                                 
417                                 if (!GeneralUIUtils.isElementVisibleByTestId(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue()))
418                                 {
419                                         restartBrowser(role);
420                                 }
421                         }
422                 }
423                 catch (Exception e) {
424                         restartBrowser(role);
425                 }
426         }
427         private void restartBrowser(UserRoleEnum role) throws Exception {
428                 getWindowTest().setRefreshAttempts(getWindowTest().getRefreshAttempts() - 1);
429                 if (getWindowTest().getRefreshAttempts() <= 0) {
430                         System.out.println("ERR : Something is wrong with browser!");
431                         Assert.fail("ERR : Something is wrong with browser!");
432                 }
433                 System.out.println("Trying again...");
434                 getExtendTest().log(Status.INFO, "Trying again...");
435                 getExtendTest().log(Status.INFO, String.format("%s attempt(s) left", getWindowTest().getRefreshAttempts() ));
436                 System.out.println(String.format("%s attempt(s) left", getWindowTest().getRefreshAttempts() ));
437
438                 reloginWithNewRole(role);
439         }
440         
441         public void loginToSimulator(UserRoleEnum role){
442                 WebDriver driver = GeneralUIUtils.getDriver();
443                 WebDriverWait wait = new WebDriverWait(driver, 30);
444                 
445                 wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@method='" + "post" + "']"))));
446                 
447                 WebElement userIdTextbox = GeneralUIUtils.getWebElementBy(By.name("userId"));
448                 userIdTextbox.sendKeys(role.getUserId());
449                 WebElement passwordTextbox = GeneralUIUtils.getWebElementBy(By.name("password"));
450                 passwordTextbox.sendKeys(WEB_SEAL_PASSWORD);
451                 
452                 wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//*[@value='" + "Login" + "']")))).click();
453         }
454
455         private void sendUserAndPasswordKeys(UserCredentials userId) {
456                 System.out.println("Login as user : " + userId.getUserId());
457                 WebElement userNameTextbox = GeneralUIUtils.getWebElementBy(By.name("userid"));
458                 userNameTextbox.sendKeys(userId.getUserId());
459                 WebElement passwordTextbox = GeneralUIUtils.getWebElementBy(By.name("password"));
460                 passwordTextbox.sendKeys(userId.getPassword());
461         }
462
463         public void loginWithUser(UserRoleEnum role) {
464                 try {
465                         getExtendTest().log(Status.INFO, String.format("Login as user %s", role.name().toUpperCase()));
466                         loginToSystem(role);
467                         goToHomePage(role);
468                 } catch (Exception e) {
469                         throw new RuntimeException(e);
470                 }
471                 finally{
472                         getWindowTest().setPreviousRole(getWindowTest().getUser().getRole());
473                 }
474         }
475
476         private void setUser(UserRoleEnum role) {
477                 User user = new User();
478                 user.setUserId(role.getUserId());
479                 user.setFirstName(role.getFirstName());
480                 user.setRole(role.name());
481                 user.setLastName(role.getLastName());
482                 
483                 getWindowTest().setUser(user);
484         }
485
486         public User getUser() {
487                 return getWindowTest().getUser();
488         }
489
490         private void setBrowserBeforeTest(UserRoleEnum role) {
491                 System.out.println(String.format("Setup before test as %s.", role.toString().toUpperCase() ));
492                 try {
493                         System.out.println("Previous role is : " + getWindowTest().getPreviousRole() + " ; Current role is : " + role.name());
494                         if (!getWindowTest().getPreviousRole().toLowerCase().equals(role.name().toLowerCase())){
495                                 System.out.println("Roles are different, navigate and login");
496                                 navigateAndLogin(role);
497                         }
498                 } catch (Exception e) {
499                         e.printStackTrace();
500                 }
501         }
502
503         public void navigateAndLogin(UserRoleEnum role) throws Exception {
504                 getWindowTest().setRefreshAttempts(getWindowTest().getRefreshAttempts() != 0 ? getWindowTest().getRefreshAttempts() : 0);
505                 setUser(role);
506                 navigateToUrl(url);
507                 loginWithUser(role);
508                 GeneralUIUtils.ultimateWait();
509         }
510
511         public User getUser(UserRoleEnum role) {
512                 User user = new User();
513                 user.setUserId(role.getUserId());
514                 user.setFirstName(role.getFirstName());
515                 user.setLastName(role.getLastName());
516                 user.setRole(role.name());
517                 return user;
518         }
519
520         protected void reloginWithNewRole(UserRoleEnum role) throws Exception {
521                 System.out.println(String.format("Setup before relogin as %s", role.toString().toUpperCase()));
522                 navigateAndLogin(role);
523         }
524
525         /*public static void setLocalUrl(UserRoleEnum role) {
526                 switch (role) {
527                         case ADMIN: {
528                                 url = "http://localhost:8181/sdc1/proxy-admin1#/dashboard";
529                                 break;
530                         }
531                         case DESIGNER: {
532                                 url = "http://localhost:8181/sdc1/proxy-designer1#/dashboard";
533                                 break;
534                         }
535                         case GOVERNOR: {
536                                 url = "http://localhost:8181/sdc1/proxy-governor1#/dashboard";
537                                 break;
538                         }
539                         case OPS: {
540                                 url = "http://localhost:8181/sdc1/proxy-ops1#/dashboard";
541                                 break;
542                         }
543                         case TESTER: {
544                                 url = "http://localhost:8181/sdc1/proxy-tester1#/dashboard";
545                                 break;
546                         }
547                         case PRODUCT_MANAGER1: {
548                                 url = "http://localhost:8181/sdc1/proxy-pm1#/dashboard";
549                                 break;
550                         }
551                         case PRODUCT_MANAGER2: {
552                                 url = "http://localhost:8181/sdc1/proxy-pm2#/dashboard";
553                                 break;
554                         }
555                         case PRODUCT_STRATEGIST1: {
556                                 url = "http://localhost:8181/sdc1/proxy-ps1#/dashboard";
557                                 break;
558                         }
559                         case PRODUCT_STRATEGIST2: {
560                                 url = "http://localhost:8181/sdc1/proxy-ps2#/dashboard";
561                                 break;
562                         }
563                         default: {
564                                 break;
565                         }
566                 }
567         }*/
568         
569         public void addTrafficFileToReport(ITestResult result) {
570                 try {                           
571                         // Get the HAR data
572                         Har har = MobProxy.getPoxyServer().getHar();
573                         String shortUUID = UUID.randomUUID().toString().split("-")[0];
574                         File harFile = new File(getHarFilesFolder() + result.getName() + shortUUID + ".har");
575                         new File(getHarFilesFolder()).mkdirs();
576
577                         har.writeTo(harFile);
578                         
579                         String pathToFileFromReportDirectory = HAR_FILES_FOLDER_NAME + File.separator + harFile.getName();
580                         ExtentTestActions.addFileToReportAsLink(harFile, pathToFileFromReportDirectory, "File with captured traffic");
581                 } catch (IOException ioe) {
582                         ioe.printStackTrace();
583                 }
584         }
585         
586         /*
587          * * Start section of test in ExtentReport with DataProvider parameters,
588          * should be started from test method, see example in onboardVNFTest
589          */
590         public void setLog(String fromDataProvider) {
591                 
592                 String suiteName = ExtentManager.getSuiteName(myContext);
593                 if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
594                         ExtentTestManager.startTest(RE_RUN +Thread.currentThread().getStackTrace()[2].getMethodName() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + fromDataProvider);
595                 }else{
596                         ExtentTestManager.startTest(Thread.currentThread().getStackTrace()[2].getMethodName() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + fromDataProvider);
597                 }
598                 
599                 
600                 
601                 getWindowTest().setAddedValueFromDataProvider(fromDataProvider);
602                 ExtentTestManager.assignCategory(this.getClass());
603                 setBrowserBeforeTest(getRole());
604         }
605         
606         
607         
608         /**************** MAIN ****************/
609         public static void main(String[] args) {
610                 System.out.println("---------------------");
611                 System.out.println("running test from CLI");
612                 System.out.println("---------------------");
613
614                 String attsdcFilePath = FileHandling.getBasePath() + File.separator + "conf" + File.separator + "attsdc.yaml";
615                 System.setProperty("config.resource", attsdcFilePath);
616                 System.out.println("attsdc.yaml file path is : " + attsdcFilePath);
617                 
618                 String filepath = FileHandling.getBasePath() + File.separator + "Files" + File.separator;
619                 System.setProperty("filePath", filepath);
620                 System.out.println("filePath is : " + System.getProperty("filePath"));
621                 
622                 Object[] testSuitsList = FileHandling.filterFileNamesFromFolder(FileHandling.getBasePath() + File.separator + "testSuites", ".xml");
623                 if (testSuitsList != null) {
624                         System.out.println(String.format("Found %s testSuite(s)", testSuitsList.length));
625                         args = Arrays.copyOf(testSuitsList, testSuitsList.length, String[].class);
626                         StartTest.main(args);
627                 }
628         }
629 }