1 package vid.automation.test.sections;
3 import org.apache.http.NameValuePair;
4 import org.apache.http.client.utils.URLEncodedUtils;
5 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
6 import org.openqa.selenium.By;
7 import org.openqa.selenium.WebElement;
8 import org.openqa.selenium.support.ui.ExpectedConditions;
9 import org.openqa.selenium.support.ui.WebDriverWait;
10 import vid.automation.test.Constants;
11 import vid.automation.test.infra.Click;
12 import vid.automation.test.infra.Get;
13 import vid.automation.test.infra.Wait;
15 import java.nio.charset.Charset;
16 import java.util.List;
18 import java.util.function.Consumer;
19 import java.util.stream.Collectors;
21 import static java.util.stream.Collectors.toMap;
22 import static org.hamcrest.CoreMatchers.containsString;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.testng.Assert.assertEquals;
27 public abstract class InstantiationStatusPage extends VidBasePage {
29 public static final String refreshButtonId = "refresh-btn";
31 private static final String NEW_VIEW_EDIT_RELATIVE_URL = "serviceModels.htm#/servicePlanning";
34 public static String getWebTrTdSpanElementByParentID(WebElement tr, String id, int timeout) {
35 return tr.findElements(By.xpath(".//*[@id='" + id + "']//span")).get(0).getText();
38 public static int getNumberOfTableRows(int timeout){
39 WebDriverWait wait = waitUntilDriverIsReady(timeout);
40 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[table]//tbody/tr"))).size();
43 public static void verifyUrlMatchInstantiationStatusWithFilterSearchParam(String serviceModelId) {
45 Map<String, String> paramsMap = extractQueryParamsFromCurrentURL("instantiationStatus?");
46 assertEquals(paramsMap.get("filterText"), serviceModelId);
50 public static WebElement assertInstantiationStatusRow(String spanIdSelector, Map<String, String> fieldsIdsAndExpected) {
52 WebElement newTrRow = getInstantiationStatusRow(spanIdSelector);
53 final Map<String, String> fieldIdAndActual = fieldsIdsAndExpected.entrySet().stream()
54 .collect(Collectors.toMap(
56 kv -> getWebTrTdSpanElementByParentID(newTrRow, kv.getKey(), 1)
59 assertThat("failed comparing spanIdSelector " + spanIdSelector, fieldIdAndActual, is(fieldsIdsAndExpected));
62 } catch (Exception e) {
63 throw new RuntimeException("error while assertInstantiationStatusRow with: String spanIdSelector=" +
64 spanIdSelector + ", fieldsIdsAndExpected=" + fieldsIdsAndExpected, e);
68 public static WebElement getInstantiationStatusRow(String spanIdSelector) {
69 GeneralUIUtils.ultimateWait();
70 return Get.byXpath("//*[@id='" + spanIdSelector + "']/parent::*/parent::*/parent::*", 0);
73 public static void clickRefreshButton() {
74 WebDriverWait wait = waitUntilDriverIsReady(0);
75 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='"+ refreshButtonId + "']"))).click();
76 GeneralUIUtils.ultimateWait();
79 public static void checkMenuItem(String actualInstanceName, String contextMenuItem, boolean shouldBeEnabled, Consumer<String> doIfEnabled) {
80 Wait.waitFor(name -> {
81 if (null == getInstantiationStatusRow(name)) {
87 }, actualInstanceName, 8, 1);
88 final WebElement row = getInstantiationStatusRow(actualInstanceName);
89 row.findElement(By.className("menu-div")).click();
90 String clazz = Get.byXpath("//div[@data-tests-id='" + contextMenuItem + "']/ancestor::li").getAttribute("class");
91 assertThat("item " + contextMenuItem + " of " + actualInstanceName +
92 " should be " + (shouldBeEnabled ? "enabled" : "disabled"), !clazz.equals("disabled"), is(shouldBeEnabled));
93 if (shouldBeEnabled) {
94 doIfEnabled.accept(contextMenuItem);
97 Get.byTestId("instantiation-status-title").click();
101 public void showTooltipByHoverAboveStatusIcon(String elementTestId){
102 WebElement selectedElement = GeneralUIUtils.getWebElementByTestID(elementTestId, 30);
105 public static void openDrawingBoardForRetry(String serviceInstanceName) {
106 InstantiationStatusPage.checkMenuItem(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_RETRY, true, contextMenuRetry -> {
107 Click.byTestId(contextMenuRetry);
108 VidBasePage.goOutFromIframe();
109 verifyUrlPrefixMatchNewViewEdit("RETRY_EDIT");
113 public static void verifyOpenNewViewEdit(String serviceInstanceName, String serviceInstanceId, String serviceModelId, String serviceType, String subscriberId, String mode) {
114 InstantiationStatusPage.checkMenuItem(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, true, contextMenuOpen -> {
115 Click.byTestId(contextMenuOpen);
116 VidBasePage.goOutFromIframe();
117 verifyUrlMatchNewViewEdit(serviceInstanceId, serviceModelId, serviceType, subscriberId, mode);
118 SideMenu.navigateToMacroInstantiationStatus();
122 public static void verifyOpenNewViewEdit(String serviceInstanceName, boolean openShouldBeEnabled, String expectedMode) {
123 InstantiationStatusPage.checkMenuItem(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, openShouldBeEnabled, contextMenuOpen -> {
124 Click.byTestId(contextMenuOpen);
125 VidBasePage.goOutFromIframe();
126 verifyUrlPrefixMatchNewViewEdit(expectedMode);
127 SideMenu.navigateToMacroInstantiationStatus();
131 public static void verifyUrlMatchNewViewEdit(String serviceInstanceId, String serviceModelId, String serviceType, String subscriberId, String expectedMode) {
132 verifyUrlPrefixMatchNewViewEdit(expectedMode);
133 Map<String, String> paramsMap = extractQueryParamsFromCurrentURL(NEW_VIEW_EDIT_RELATIVE_URL + "/" + expectedMode + "?");
134 //assertEquals(paramsMap.get("mode"), expectedMode);
135 assertEquals(paramsMap.get("serviceInstanceId"), serviceInstanceId);
136 assertEquals(paramsMap.get("serviceModelId"), serviceModelId);
137 assertEquals(paramsMap.get("serviceType"), serviceType);
138 assertEquals(paramsMap.get("subscriberId"), subscriberId);
141 protected static Map<String, String> extractQueryParamsFromCurrentURL(String relativePath) {
142 String currentUrl = GeneralUIUtils.getDriver().getCurrentUrl();
143 //unfortunately parse(final URI uri, final String charset) can't handle with the #/ part of the uri
144 String urlSuffix = currentUrl.substring(currentUrl.indexOf(relativePath)+relativePath.length());
145 List<NameValuePair> params = URLEncodedUtils.parse(urlSuffix, Charset.forName("UTF-8"));
146 return params.stream().collect(toMap(NameValuePair::getName, NameValuePair::getValue));
149 public static void verifyUrlPrefixMatchNewViewEdit(String expectedMode) {
150 String currentUrl = GeneralUIUtils.getDriver().getCurrentUrl();
151 assertThat(currentUrl, containsString(NEW_VIEW_EDIT_RELATIVE_URL + "/" + expectedMode));