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