Merge "Template modal - Start from Scratch button + UT"
diff --git a/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt b/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
index b638a03..b23a464 100644
--- a/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
@@ -163,11 +163,10 @@
             dataAccessService.getList(ServiceInfo::class.java, filterInstantiatedServiceByServiceModelId(serviceModelId), orderByCreatedDateAndStatus(), null) as List<ServiceInfo>;
 
     fun getAllTemplatesServiceModelIds(): Set<String> {
-        val allTemplatesInfo =
-                dataAccessService.getList(ServiceInfo::class.java, filterByInstantiateActionStatus(), null, null) as List<ServiceInfo>
-
-        return allTemplatesInfo
-                .map { it.serviceModelId }
-                .toHashSet()
+        val allTemplatesServiceModelID: List<String> =
+            dataAccessService.executeQuery(
+                "select distinct serviceModelId from ServiceInfo ${filterByInstantiateActionStatus()}",
+                null) as List<String>
+        return allTemplatesServiceModelID.toHashSet()
     }
 }
diff --git a/vid-automation/TestNg-UI-half.xml b/vid-automation/TestNg-UI-half.xml
index 27abcd7..d76aa6f 100644
--- a/vid-automation/TestNg-UI-half.xml
+++ b/vid-automation/TestNg-UI-half.xml
@@ -22,12 +22,12 @@
                             "vid.automation.test.test.ChangeManagementTest",
                             "vid.automation.test.test.ALaCarteflowTest",
                             "vid.automation.test.test.VlanTagSubInterfaceTest",
+                            "vid.automation.test.test.CreatePortMirroringConfigurationTest",
                             "vid.automation.test.test.CreateNewInstanceTest"
                         };
 
                         String [] classes3 = new String [] {
-                            "vid.automation.test.test.NewServiceInstanceTest",
-                            "vid.automation.test.test.CreatePortMirroringConfigurationTest"
+                            "vid.automation.test.test.NewServiceInstanceTest"
                         };
 
                         String [] classes4 = new String [] {
diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUIUtils.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUIUtils.java
index c2c93e7..dd632d2 100644
--- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUIUtils.java
+++ b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUIUtils.java
@@ -642,13 +642,14 @@
     public static void waitForAngular2(){
     	WebDriverWait wait = newWait(90);
     	wait.until(AdditionalConditions.pageLoadWait());
+		waitForLoader(60);
     	try {
-			WebDriverWait briefWait = newWait(2);
+			WebDriverWait briefWait = newWait(3);
 			briefWait.until(AdditionalConditions.angular2HasFinishedProcessing());
 		} catch (TimeoutException | org.openqa.selenium.ScriptTimeoutException e) {
 			logger.info("Ignoring TimeoutException while waiting for angular2: {}", e, e);
+			waitForLoader(30);
 		}
-		waitForLoader(10);
     }
 
 	public static Object getAllElementAttributes(WebElement element) {
@@ -826,4 +827,14 @@
 		ultimateWait();
 	}
 
+	public static void acceptDeadObjectException(Runnable todo) {
+		try {
+			todo.run();
+		} catch (org.openqa.selenium.WebDriverException e) {
+			if (!e.getMessage().startsWith("TypeError: can't access dead object")) {
+				throw e;
+			}
+		}
+	}
+
 }
diff --git a/vid-automation/src/main/java/vid/automation/test/sections/VidBasePage.java b/vid-automation/src/main/java/vid/automation/test/sections/VidBasePage.java
index 43dd68f..0312208 100644
--- a/vid-automation/src/main/java/vid/automation/test/sections/VidBasePage.java
+++ b/vid-automation/src/main/java/vid/automation/test/sections/VidBasePage.java
@@ -1,16 +1,10 @@
 package vid.automation.test.sections;
 
-import com.aventstack.extentreports.Status;
-import org.junit.Assert;
-import org.onap.sdc.ci.tests.execute.setup.ExtentTestActions;
-import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
-import org.openqa.selenium.*;
-import org.openqa.selenium.support.ui.ExpectedConditions;
-import org.openqa.selenium.support.ui.WebDriverWait;
-import vid.automation.test.Constants;
-import vid.automation.test.Constants.ViewEdit;
-import vid.automation.test.infra.*;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.onap.sdc.ci.tests.utilities.GeneralUIUtils.getDriver;
 
+import com.aventstack.extentreports.Status;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -19,12 +13,25 @@
 import java.util.Date;
 import java.util.List;
 import java.util.function.Function;
-
-import static java.util.stream.Collectors.toMap;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.onap.sdc.ci.tests.utilities.GeneralUIUtils.getDriver;
-import static org.testng.Assert.assertEquals;
+import org.junit.Assert;
+import org.onap.sdc.ci.tests.execute.setup.ExtentTestActions;
+import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
+import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.TimeoutException;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+import vid.automation.test.Constants;
+import vid.automation.test.Constants.ViewEdit;
+import vid.automation.test.infra.Click;
+import vid.automation.test.infra.Exists;
+import vid.automation.test.infra.Features;
+import vid.automation.test.infra.Get;
+import vid.automation.test.infra.Input;
+import vid.automation.test.infra.SelectOption;
+import vid.automation.test.infra.Wait;
 
 public class VidBasePage {
 
@@ -276,6 +283,7 @@
         }
         String target = uri.resolve(path).toString();
 
+        goOutFromIframe();
         getDriver().navigate().to(target);
         GeneralUIUtils.ultimateWait();
 
@@ -308,6 +316,7 @@
     }
 
     public static void goOutFromIframe(){
+        GeneralUIUtils.acceptDeadObjectException(GeneralUIUtils::ultimateWait);
         getDriver().switchTo().defaultContent();
     }
 
diff --git a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIBase.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIBase.java
index dd605ff..acddc1b 100644
--- a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIBase.java
+++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIBase.java
@@ -28,6 +28,7 @@
         GeneralUIUtils.ultimateWait();
         clickCancelButtonByTestID();
         goOutFromIframe();
+        GeneralUIUtils.ultimateWait();
     }
 
     @Override
diff --git a/vid-automation/src/main/java/vid/automation/test/test/InstantiationStatusTest.java b/vid-automation/src/main/java/vid/automation/test/test/InstantiationStatusTest.java
index 4eb637a..70fe620 100644
--- a/vid-automation/src/main/java/vid/automation/test/test/InstantiationStatusTest.java
+++ b/vid-automation/src/main/java/vid/automation/test/test/InstantiationStatusTest.java
@@ -1,34 +1,37 @@
 package vid.automation.test.test;
 
+import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME;
+import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.VNF_NAME;
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON;
+
 import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
 import org.junit.Assert;
+import org.onap.sdc.ci.tests.datatypes.UserCredentials;
+import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames;
 import org.onap.vid.api.AsyncInstantiationBase;
 import org.onap.vid.api.CreateServiceWithFailedVnf;
 import org.onap.vid.api.TestUtils;
-import org.onap.sdc.ci.tests.datatypes.UserCredentials;
-import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebElement;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 import vid.automation.test.Constants;
-import vid.automation.test.infra.*;
+import vid.automation.test.infra.Click;
+import vid.automation.test.infra.FeatureTogglingTest;
+import vid.automation.test.infra.Features;
+import vid.automation.test.infra.Get;
+import vid.automation.test.infra.Wait;
 import vid.automation.test.sections.DrawingBoardPage;
 import vid.automation.test.sections.InstantiationStatusPage;
 import vid.automation.test.sections.SideMenu;
 import vid.automation.test.sections.VidBasePage;
 import vid.automation.test.services.AsyncJobsService;
 
-import java.util.Collections;
-
-import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME;
-import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.VNF_NAME;
-import static org.testng.Assert.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON;
-
 public class InstantiationStatusTest extends VidBaseTestCase {
 
     private final String serviceModelVersion = "5.1";
@@ -126,6 +129,8 @@
     }
 
     private void checkFailedAuditInfoOnRetry(String instanceName, String requestId, String message) {
+        GeneralUIUtils.ultimateWait();
+
         WebElement webElement = Get.byTestId("model-item-value-instance_name");
         assertEquals(webElement.getText(), instanceName, "Instance Name must be equal");
 
diff --git a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java
index 41ede9a..c2733f0 100644
--- a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java
+++ b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java
@@ -190,7 +190,7 @@
 
     @BeforeSuite(alwaysRun = true)
     public void setSmallDefaultTimeout() throws Exception {
-        getDriver().manage().timeouts().implicitlyWait(250, TimeUnit.MILLISECONDS);
+        getDriver().manage().timeouts().implicitlyWait(500, TimeUnit.MILLISECONDS);
     }
 
     @Override
diff --git a/vid-webpack-master/cypress/integration/iFrames/instantiation.templates.modal.e2e.ts b/vid-webpack-master/cypress/integration/iFrames/instantiation.templates.modal.e2e.ts
index 7fb7ea5..73d3115 100644
--- a/vid-webpack-master/cypress/integration/iFrames/instantiation.templates.modal.e2e.ts
+++ b/vid-webpack-master/cypress/integration/iFrames/instantiation.templates.modal.e2e.ts
@@ -125,7 +125,7 @@
     .getElementByDataTestsId('templateButton').click({force: true}) // Open template Modal
 
     const serviceModelId = '5c9e863f-2716-467b-8799-4a67f378dcaa';
-    const vidBaseUrl = `http://localhost:8080/vid/serviceModels.htm`;
+    const vidBaseUrl = `${Cypress.config().baseUrl}/serviceModels.htm`;
 
     cy.getElementByDataTestsId(`row-${templateJobIdFromE2EFile}`).click();
     cy.getElementByDataTestsId('LoadTemplateButton').click().setViewportToDefault();
diff --git a/vid-webpack-master/cypress/integration/iFrames/instantiationStatus.e2e.ts b/vid-webpack-master/cypress/integration/iFrames/instantiationStatus.e2e.ts
index 342818a..cf727b5 100644
--- a/vid-webpack-master/cypress/integration/iFrames/instantiationStatus.e2e.ts
+++ b/vid-webpack-master/cypress/integration/iFrames/instantiationStatus.e2e.ts
@@ -121,7 +121,7 @@
     //see cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json id:8
     const jobId = '5c2cd8e5-27d0-42e3-85a1-85db5eaba459';
     const serviceModelId = 'e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0';
-    const vidBaseUrl = `http://localhost:8080/vid/serviceModels.htm`;
+    const vidBaseUrl = `${Cypress.config().baseUrl}/serviceModels.htm`;
 
     cy.openIframe('app/ui/#/instantiationStatus');