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