aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/GeneralPageElements.java
blob: fea3843b7a325cc0008e7b7927aa25eac8615a7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.ci.tests.pages;

import static org.testng.AssertJUnit.assertTrue;
import java.util.List;
import java.util.function.Supplier;

import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.relevantcodes.extentreports.LogStatus;

public class GeneralPageElements {

	public GeneralPageElements() {
		super();
	}

	public static ResourceLeftMenu getLeftMenu() {
		return new ResourceLeftMenu();
	}

	public static void clickCreateButton() {
		SetupCDTest.getExtendTest().log(LogStatus.INFO, "creating...");
		GeneralUIUtils.getWebButton(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue()).click();
		GeneralUIUtils.waitForLoader();
	}

	public static void clickCheckinButton(String componentName) throws Exception {
		SetupCDTest.getExtendTest().log(LogStatus.INFO, "clicking on checkin");
		GeneralUIUtils.getWebButton(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue()).click();
		GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.ACCEP_TESTING_MESSAGE.getValue())
				.sendKeys("Checkin " + componentName);
		GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.OK.getValue()).click();
		GeneralUIUtils.waitForLoader();
		assertTrue(GeneralUIUtils.getWebElementWaitForVisible("formlifecyclestate").getText()
				.equals(LifeCycleStateEnum.CHECKIN.getValue()));
	}

	public static void clickSubmitForTestingButton(String componentName) throws Exception {
		try {
			SetupCDTest.getExtendTest().log(LogStatus.INFO, "submiting for testing");
			GeneralUIUtils
					.getWebElementWaitForVisible(DataTestIdEnum.LifeCyleChangeButtons.SUBMIT_FOR_TESTING.getValue())
					.click();
			GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.SUMBIT_FOR_TESTING_MESSAGE.getValue())
					.sendKeys("Submit for testing for " + componentName);
			GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.OK.getValue()).click();
			GeneralUIUtils.waitForLoader();
			GeneralUIUtils.sleep(2000);
			GeneralUIUtils.getWebElementWaitForVisible("main-menu-input-search");
		} catch (Exception e) {
			throw e;
		}
	}

	public static void clickDeleteVersionButton() {
		GeneralUIUtils.getWebButton(DataTestIdEnum.GeneralElementsEnum.DELETE_VERSION_BUTTON.getValue()).click();
	}

	public static void clickRevertButton() {
		GeneralUIUtils.getWebButton(DataTestIdEnum.GeneralElementsEnum.REVERT_BUTTON.getValue()).click();
	}

	public static String getLifeCycleState() {
		return GeneralUIUtils.getWebButton(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()).getText();
	}

	public static void selectVersion(String version) {
		GeneralUIUtils.getSelectList(version, DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue());
	}

	public static List<WebElement> getElemenetsFromTable() {
		GeneralUIUtils.waitForLoader();
		return GeneralUIUtils.getElemenetsFromTable(By.className("flex-container"));
	}

	public static boolean checkElementsCountInTable(int expectedElementsCount) {
		// int maxWaitingPeriodMS = 1000;
		// int napPeriodMS = 100;
		// int sumOfWaiting = 0;
		// List<WebElement> elememts = null;
		// boolean isKeepWaiting = false;
		// while (!isKeepWaiting){
		// GeneralUIUtils.sleep(napPeriodMS);
		// sumOfWaiting += napPeriodMS;
		// elememts = getElemenetsFromTable();
		// isKeepWaiting = ( expectedElementsCount == elememts.size() );
		// if (sumOfWaiting > maxWaitingPeriodMS)
		// return false;
		// }
		//
		// return true;
		SetupCDTest.getExtendTest().log(LogStatus.INFO, "checking number of elements in table");
		return checkElementsCountInTable(expectedElementsCount, () -> getElemenetsFromTable());
	}

	public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
		int maxWaitingPeriodMS = 10000;
		int napPeriodMS = 100;
		int sumOfWaiting = 0;
		List<WebElement> elements = null;
		boolean isKeepWaiting = false;
		while (!isKeepWaiting) {
			GeneralUIUtils.sleep(napPeriodMS);
			sumOfWaiting += napPeriodMS;
			elements = func.get();
			isKeepWaiting = (expectedElementsCount == elements.size());
			if (sumOfWaiting > maxWaitingPeriodMS)
				return false;
		}
		return true;
	}

}