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