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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
package vid.automation.test.sections;
import com.aventstack.extentreports.Status;
import org.junit.Assert;
import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import vid.automation.test.Constants;
import vid.automation.test.infra.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import static org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.getDriver;
public class VidBasePage {
public VidBasePage setInstanceName(String name) {
setInputText(Constants.INSTANCE_NAME_SELECT_TESTS_ID, name);
return this;
}
public VidBasePage setLegacyRegion(String name) {
setInputText(Constants.ViewEdit.LEGACY_REGION_INPUT_TESTS_ID, name);
return this;
}
public String generateAndSetInstanceName(String prefix) {
String instanceName = generateInstanceName(prefix);
setInstanceName(instanceName);
return instanceName;
}
public VidBasePage setInputText(String inputTestsId, String text) {
WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
instanceNameInput.sendKeys(text);
return this;
}
public String getInputValue(String inputTestsId) {
WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
String value =instanceNameInput.getAttribute("value");
return value;
}
public String generateInstanceName(String prefix) {
SimpleDateFormat sdf = new SimpleDateFormat(Constants.BrowseASDC.DATE_FORMAT);
Date now = Calendar.getInstance().getTime();
return prefix + sdf.format(now);
}
public VidBasePage selectServiceTypeByName(String serviceType) {
SelectOption.byTestIdAndVisibleText(serviceType, Constants.SERVICE_TYPE_SELECT_TESTS_ID);
return this;
}
public VidBasePage selectFromDropdownByTestId(String itemTestId, String dropdownButtonTestId) {
GeneralUIUtils.clickOnElementByTestId(dropdownButtonTestId, 60);
Assert.assertTrue(String.format(Constants.ViewEdit.OPTION_IN_DROPDOWN_NOT_EXISTS,itemTestId, dropdownButtonTestId),GeneralUIUtils.getWebElementByTestID(itemTestId) != null );
GeneralUIUtils.clickOnElementByTestId(itemTestId, 60);
return this;
}
public VidBasePage noOptionDropdownByTestId( String dropdownButtonTestId) {
List<WebElement> selectList= SelectOption.getList(dropdownButtonTestId);
Assert.assertTrue("The Select Input "+ dropdownButtonTestId+" should be empty",selectList.size()==1);
return this;
}
public static void selectSubscriberById(String subscriberId) {
SelectOption.byValue(subscriberId, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
}
public VidBasePage selectSubscriberByName(String subscriberName) {
SelectOption.byTestIdAndVisibleText(subscriberName, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
return this;
}
public VidBasePage selectProductFamily(String productFamily) {
SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
return this;
}
public VidBasePage selectSuppressRollback(String shouldSuppress) {
SelectOption.byTestIdAndVisibleText(shouldSuppress, Constants.SUPPRESS_ROLLBACK_SELECT_TESTS_ID);
return this;
}
public VidBasePage clickDeployServiceButtonByServiceUUID(String serviceUUID) {
Input.replaceText(serviceUUID, Constants.BROWSE_SEARCH);
String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
GeneralUIUtils.clickOnElementByTestId(elementTestId, 30);
GeneralUIUtils.ultimateWait();
screenshotDeployDialog(serviceUUID);
return this;
}
public void screenshotDeployDialog(String serviceUUID) {
try {
GeneralUIUtils.ultimateWait();
GeneralUIUtils.ultimateWait(); // better screenshot
String screenshotName = "deployService-" + serviceUUID;
ExtentTestActions.addScreenshot(Status.INFO, screenshotName, screenshotName);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public VidBasePage clickEditViewByInstanceId(String instanceId) {
String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
GeneralUIUtils.clickOnElementByTestId(elementTestId, 100);
return this;
}
public Boolean checkEditOrViewExistsByInstanceId(String instanceId) {
String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
return Exists.byTestId(elementTestId);
}
public VidBasePage clickSubmitButton() {
GeneralUIUtils.clickOnElementByText(Constants.SUBMIT_BUTTON_TEXT, 30);
return this;
}
public VidBasePage clickCancelButton() {
Click.byId(Constants.generalCancelButtonId);
return this;
}
public VidBasePage clickCancelButtonByTestID() {
GeneralUIUtils.clickOnElementByTestId(Constants.CANCEL_BUTTON_TEST_ID, 30);
return this;
}
public VidBasePage clickConfirmButton() {
GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_BUTTON_TESTS_ID, 30);
return this;
}
public VidBasePage clickConfirmButtonInResumeDelete() {
GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
return this;
}
public VidBasePage clickCommitCloseButton() {
GeneralUIUtils.clickOnElementByTestId(Constants.COMMIT_CLOSE_BUTTON_ID, 30);
return this;
}
public VidBasePage clickCloseButton() {
return clickCloseButton(30);
}
public VidBasePage clickCloseButton(int customTimeout) {
GeneralUIUtils.clickOnElementByText(Constants.CLOSE_BUTTON_TEXT, customTimeout);
return this;
}
public VidBasePage selectLcpRegion(String lcpRegion) {
SelectOption.byValue(lcpRegion, Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
return this;
}
public VidBasePage selectTenant(String tenant) {
SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
return this;
}
public VidBasePage selectAicZone(String aicZone) {
SelectOption.byValue(aicZone, Constants.ViewEdit.AIC_ZONE_TEST_ID);
return this;
}
public VidBasePage selectRollbackOption(boolean rollback) {
SelectOption.byValue(String.valueOf(rollback) , Constants.ViewEdit.ROLLBACK_TEST_ID);
return this;
}
public VidBasePage selectPlatform(String platform) {
SelectOption.byValue(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
return this;
}
public VidBasePage selectLineOfBusiness(String lob) {
SelectOption.byValue(lob, Constants.OwningEntity.LOB_SELECT_TEST_ID);
return this;
}
public void assertButtonState(String dataTestId, boolean shouldBeEnabled) {
assertButtonStateInternal(dataTestId, shouldBeEnabled,
(dataTestIdInner) -> GeneralUIUtils.getWebElementByTestID(dataTestIdInner, 60));
}
public void assertButtonStateEvenIfButtonNotVisible(String dataTestId, boolean shouldBeEnabled) {
// getInputElement is quite similar to getWebElementByTestID, but doesn't use
// the visibility predicate, so button is reachable bhind the grayed-out panel
assertButtonStateInternal(dataTestId, shouldBeEnabled,
(dataTestIdInner) -> GeneralUIUtils.getInputElement(dataTestIdInner));
}
protected void assertButtonStateInternal(String dataTestId, boolean shouldBeEnabled, Function<String,WebElement> strategy) {
GeneralUIUtils.ultimateWait();
boolean enabledElement= strategy.apply(dataTestId).getAttribute("disabled") == null;
if(shouldBeEnabled) {
Assert.assertTrue(String.format(Constants.ViewEdit.DISABLE_ERROR_MESSAGE,dataTestId), enabledElement);
}else{
Assert.assertFalse(String.format(Constants.ViewEdit.ENABLE_ERROR_MESSAGE,dataTestId),enabledElement);
}
}
public VidBasePage assertMsoRequestModal(String statusMsg) {
boolean waitForTextResult = Wait.waitByClassAndText("status", statusMsg, 20);
Assert.assertTrue(statusMsg + " message didn't appear on time", waitForTextResult);
return this;
}
public VidBasePage refreshPage() {
getDriver().navigate().refresh();
return this;
}
public String navigateTo(String path) {
String envUrl = System.getProperty("ENV_URL");
URI uri;
try {
uri = new URI(envUrl);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
String target = uri.resolve(path).toString();
getDriver().navigate().to(target);
GeneralUIUtils.ultimateWait();
return target;
}
public String getTextByTestID(String testId){
WebElement webElement= GeneralUIUtils.getWebElementByTestID(testId);
return webElement.getText();
}
public void checkAndCloseAlert(String expectedText) {
String alertText= Get.alertText();
Assert.assertEquals(expectedText, alertText);
Click.acceptAlert();
}
public void goToIframe() {
final long start = System.currentTimeMillis();
goOutFromIframe();
GeneralUIUtils.ultimateWait();
System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start));
final WebDriver iframeReady = new WebDriverWait(getDriver(), 10).until(
ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe"))
);
Assert.assertNotNull("failed going into iframe", iframeReady);
final long start2 = System.currentTimeMillis();
GeneralUIUtils.ultimateWait();
System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start2));
}
public void goOutFromIframe(){
getDriver().switchTo().defaultContent();
}
public static WebDriverWait waitUntilDriverIsReady(int time) {
return new WebDriverWait(getDriver(), (long)time);
}
}
|