Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / OpsOperationPage.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.onap.sdc.frontend.ci.tests.pages;
22
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
25 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
26 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
27 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebElement;
30 import org.openqa.selenium.support.ui.ExpectedConditions;
31 import org.openqa.selenium.support.ui.WebDriverWait;
32
33 import java.util.List;
34
35 public class OpsOperationPage {
36
37     private static final int WEB_DRIVER_TIME_OUT = 90;
38     private static final int MAX_WAITING_PERIOD_MS = 5 * 60 * 1000;
39     private static final int NAP_PERIOD = 10000;
40     private static final int MAX_WAITING_PERIOF_DIVIDER = 1000;
41
42     private OpsOperationPage() {
43         super();
44     }
45
46     public static void distributeService() {
47         SetupCDTest.getExtendTest().log(Status.INFO, "Distributing");
48         clickOnButton(DataTestIdEnum.DistributionChangeButtons.DISTRIBUTE);
49         GeneralUIUtils.waitForLoader();
50         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.MONITOR.getValue());
51     }
52
53     public static void displayMonitor() {
54         GeneralUIUtils.moveToStep(StepsEnum.MONITOR);
55     }
56
57     public static void reDistributeService() {
58         SetupCDTest.getExtendTest().log(Status.INFO, "Redistributing...");
59         clickOnButton(DataTestIdEnum.DistributionChangeButtons.RE_DISTRIBUTE);
60         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.MONITOR.getValue());
61     }
62
63     private static void clickOnButton(DataTestIdEnum.DistributionChangeButtons button) {
64         GeneralUIUtils.getWebElementByTestID(button.getValue()).click();
65         GeneralUIUtils.waitForLoader();
66     }
67
68     public static List<WebElement> getRowsFromMonitorTable() {
69         SetupCDTest.getExtendTest().log(Status.INFO, "Counting the rows from the distribution table");
70         GeneralPageElements.checkElementsCountInTable(1, () -> GeneralUIUtils.getWebElementsListByTestID("ditributionTable"));
71         List<WebElement> distributionRecords = GeneralUIUtils.getWebElementsListByTestID("ditributionTable");
72         List<WebElement> findElements = distributionRecords.get(0).findElements(By.className("w-sdc-distribute-parent-block"));
73         return findElements;
74     }
75
76     public static void showDistributionStatus(int rowIndex) {
77         GeneralUIUtils.getWebElementByTestID("ShowRecordButton_" + String.valueOf(rowIndex)).click();
78         GeneralUIUtils.waitForLoader();
79     }
80
81     public static String getTotalArtifactsSum(int rowIndex) {
82         return GeneralUIUtils.getWebElementByTestID("totalArtifacts_" + String.valueOf(rowIndex)).getText();
83     }
84
85     public static String getNotifiedArtifactsSum(int rowIndex) {
86         return GeneralUIUtils.getWebElementByTestID("notified_" + String.valueOf(rowIndex)).getText();
87     }
88
89     public static String getDownloadedArtifactsSum(int rowIndex) {
90         return GeneralUIUtils.getWebElementByTestID("downloaded_" + String.valueOf(rowIndex)).getText();
91     }
92
93     public static String getDeployedArtifactsSum(int rowIndex) {
94         return GeneralUIUtils.getWebElementByTestID("deployed_" + String.valueOf(rowIndex)).getText();
95     }
96
97     public static String getNotNotifiedArtifactsSum(int rowIndex) {
98         return GeneralUIUtils.getWebElementByTestID("NotNotified_" + String.valueOf(rowIndex)).getText();
99     }
100
101     public static String getErrorsSum(int rowIndex) {
102         return GeneralUIUtils.getWebElementByTestID("errors_" + String.valueOf(rowIndex)).getText();
103     }
104
105     public static void clickRefreshTableButton(int rowIndex) {
106         GeneralUIUtils.getWebElementByTestID("refreshButton").click();
107         // wait until total artifacts field disappear
108         WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), WEB_DRIVER_TIME_OUT);
109         wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + "totalArtifacts_" + String.valueOf(rowIndex) + "']")));
110     }
111
112     public static void waitUntilArtifactsDistributed(int rowIndex) throws Exception {
113         waitUntilArtifactsDistributed("0", 0);
114     }
115
116     public static void waitUntilArtifactsDistributed(String expectedArtifactsSum, int rowIndex) throws Exception {
117         SetupCDTest.getExtendTest().log(Status.INFO, "Waiting until all artifacts are distributed");
118         boolean isKeepWaiting = true;
119         int maxWaitingPeriodMS = MAX_WAITING_PERIOD_MS;
120         int sumWaitingTime = 0;
121         int napPeriod = NAP_PERIOD;
122         while (isKeepWaiting) {
123             showDistributionStatus(rowIndex);
124             String actualTotalArtifactsSize = getTotalArtifactsSum(rowIndex);
125             String actualNotifiedArtifactsSize = getNotifiedArtifactsSum(rowIndex);
126             String actualDownloadedArtifactsSize = getDownloadedArtifactsSum(rowIndex);
127             String actualDeployedArtifactsSize = getDeployedArtifactsSum(rowIndex);
128             String actualNotNotifedArtifactsSize = getNotNotifiedArtifactsSum(rowIndex);
129             isKeepWaiting = !actualTotalArtifactsSize.equals(actualDownloadedArtifactsSize)
130                     || !actualTotalArtifactsSize.equals(actualNotifiedArtifactsSize)
131                     || !actualTotalArtifactsSize.equals(actualDeployedArtifactsSize)
132                     || actualTotalArtifactsSize.equals("0") || actualDownloadedArtifactsSize.equals("0")
133                     || actualNotifiedArtifactsSize.equals("0") || actualDeployedArtifactsSize.equals("0");
134
135             if (isKeepWaiting) {
136
137                 if (Integer.parseInt(actualNotNotifedArtifactsSize) > 1) {
138                     SetupCDTest.getExtendTest().log(Status.INFO, "Some artifacts are not notified");
139                     isKeepWaiting = false;
140                     throw new Exception("Some artifacts are not notified...");
141                 }
142
143                 GeneralUIUtils.sleep(napPeriod);
144                 sumWaitingTime += napPeriod;
145
146                 if (sumWaitingTime > maxWaitingPeriodMS) {
147                     SetupCDTest.getExtendTest().log(Status.INFO, "Not all artifacts are displayed");
148                     isKeepWaiting = false;
149                     throw new Exception(String.format("Not all artifacts are displayed withing %s seconds",
150                             String.valueOf(maxWaitingPeriodMS / MAX_WAITING_PERIOF_DIVIDER)));
151                 }
152
153                 clickRefreshTableButton(rowIndex);
154             }
155         }
156
157         SetupCDTest.getExtendTest().log(Status.INFO, "All artifacts were successfully distributed");
158     }
159
160 }