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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
/*-
* ============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.utilities;
import com.aventstack.extentreports.Status;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.ci.tests.datatypes.CreateAndImportButtonsEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.Dashboard;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.File;
import java.util.List;
import java.util.Random;
public final class ResourceUIUtils {
public static final String RESOURCE_NAME_PREFIX = "ResourceCDTest-";
protected static final boolean IS_BEFORE_TEST = true;
public static final String INITIAL_VERSION = "0.1";
public static final String ICON_RESOURCE_NAME = "call_controll";
protected static final String UPDATED_RESOURCE_ICON_NAME = "objectStorage";
private ResourceUIUtils() {
}
static WebDriver driver = GeneralUIUtils.getDriver();
// click and upload tosca file //**to be changed.
public static void importFileWithSendKey(String FilePath, String FileName, CreateAndImportButtonsEnum type)
throws Exception {
WebElement importButton = HomeUtils.createAndImportButtons(type, driver).findElement(By.tagName("input"));
importButton.sendKeys(FilePath + FileName);
}
public static String defineUserId(String userId) {
//
WebElement resourceUserIdTextbox = ResourceGeneralPage.getContactIdField();
resourceUserIdTextbox.clear();
resourceUserIdTextbox.sendKeys(userId);
return userId;
}
public static String definePropertyName(String name) {
WebElement nameProperty = GeneralUIUtils.getDriver().findElement(By.name("propertyName"));
nameProperty.sendKeys(name);
return name;
}
public static void selectRandomResourceIcon() throws Exception {
GeneralUIUtils.moveToStep(StepsEnum.ICON);
WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 4);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@data-tests-id, 'iconBox')]")));
List<WebElement> iconElement = GeneralUIUtils.getDriver()
.findElements(By.xpath("//*[contains(@data-tests-id, 'iconBox')]"));
iconElement.get(0).click();
}
public static void defineDefaultValueByType(String Value) {
WebElement valueString = GeneralUIUtils.getDriver().findElement(By.name("value"));
valueString.clear();
valueString.sendKeys(Value);
}
public static void defineBoolenDefaultValue(String Value) {
WebElement elementBoolean = GeneralUIUtils.getDriver().findElement(By.name("value"));
Select se = new Select(elementBoolean);
se.selectByValue(Value);
}
public static void fillResourceGeneralInformationPage(ResourceReqDetails resource, User user, boolean isNewResource) {
try {
ResourceGeneralPage.defineName(resource.getName());
ResourceGeneralPage.defineDescription(resource.getDescription());
ResourceGeneralPage.defineCategory(resource.getCategories().get(0).getSubcategories().get(0).getName());
ResourceGeneralPage.defineVendorName(resource.getVendorName());
ResourceGeneralPage.defineVendorRelease(resource.getVendorRelease());
if (isNewResource){
ResourceGeneralPage.defineTagsList(resource, new String[] { "This-is-tag", "another-tag", "Test-automation-tag" });
}
else{
ResourceGeneralPage.defineTagsList(resource, new String[] { "one-more-tag" });
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void fillMaxValueResourceGeneralInformationPage(ResourceReqDetails resource) {
String stringPattern = "ABCDabcd123456";
GeneralUIUtils.addStringtoClipboard(buildStringFromPattern(stringPattern, 5000));
ResourceGeneralPage.defineNameWithPaste();
ResourceGeneralPage.defineDescriptionWithPaste();
ResourceGeneralPage.defineVendorNameWithPaste();
ResourceGeneralPage.defineVendorReleaseWithPaste();
ResourceGeneralPage.defineTagsListWithPaste();
GeneralUIUtils.waitForAngular();
}
public static String buildStringFromPattern(String stringPattern, int stringLength){
char[] chars = stringPattern.toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < stringLength; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
return sb.toString();
}
/**
* @deprecated Use {@link #createVF(ResourceReqDetails,User)} instead
*/
public static void createResource(ResourceReqDetails resource, User user) throws Exception {
createVF(resource, user);
}
public static void createVF(ResourceReqDetails resource, User user) throws Exception {
ExtentTestActions.log(Status.INFO, "Going to create a new VF.");
createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_VF);
}
public static void createResource(ResourceReqDetails resource, User user, DataTestIdEnum.Dashboard button) {
WebElement addVFButton;
try {
GeneralUIUtils.ultimateWait();
try{
GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
addVFButton = GeneralUIUtils.getWebElementByTestID(button.getValue());
}
catch (Exception e){
File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resource.getName());
final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
SetupCDTest.getExtendTest().log(Status.WARNING, "Add button is not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
showButtonsADD();
addVFButton = GeneralUIUtils.getWebElementByTestID(button.getValue());
}
addVFButton.click();
GeneralUIUtils.ultimateWait();
}
catch (Exception e ) {
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on ADD button, retrying ... "));
GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
GeneralUIUtils.ultimateWait();
GeneralUIUtils.getWebElementByTestID(button.getValue()).click();
GeneralUIUtils.ultimateWait();
}
fillResourceGeneralInformationPage(resource, user, true);
resource.setVersion("0.1");
GeneralPageElements.clickCreateButton();
}
public static void updateResource(ResourceReqDetails resource, User user){
ResourceGeneralPage.defineContactId(resource.getContactId());
SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating General screen fields ..."));
fillResourceGeneralInformationPage(resource, user, false);
ResourceGeneralPage.clickUpdateButton();
}
/**
* Click on HTML element.
*
* @param dataTestId
* @throws Exception
*/
public static void getWebElementByTestID(String dataTestId) throws Exception {
WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 20);
WebElement element = wait
.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
element.click();
// wait.until(ExpectedConditions.elemetto)
// WebElement serviceButton =
// GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
// + dataTestId + "']"));
// serviceButton.
// serviceButton.click();
}
/**
* Import VFC
*
* @param user
* @param filePath
* @param fileName
* @return
* @throws Exception
*/
public static void importVfc(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
throws Exception {
GeneralUIUtils.ultimateWait();
SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VFC resource ", resourceMetaData.getName()));
GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
GeneralUIUtils.ultimateWait();
// Insert file to the browse dialog
WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
if (!buttonVFC.isDisplayed()){
File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
}
try{
fileInputElement.sendKeys(filePath + fileName);
} catch (ElementNotVisibleException e) {
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
showButtons();
fileInputElement.sendKeys(filePath + fileName);
}
// Fill the general page fields.
GeneralUIUtils.ultimateWait();
fillResourceGeneralInformationPage(resourceMetaData, user, true);
GeneralPageElements.clickCreateButton();
}
public static void importVfcNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
throws Exception {
GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
// Insert file to the browse dialog
WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
if (!buttonVFC.isDisplayed()){
File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
}
try{
fileInputElement.sendKeys(filePath + fileName);
} catch (ElementNotVisibleException e) {
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
showButtons();
fileInputElement.sendKeys(filePath + fileName);
}
// Fill the general page fields.
GeneralUIUtils.waitForLoader();
fillResourceGeneralInformationPage(resourceMetaData, user, true);
}
public static void importVfFromCsar(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
throws Exception {
GeneralUIUtils.ultimateWait();
SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s", resourceMetaData.getName()));
GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
GeneralUIUtils.ultimateWait();
// Insert file to the browse dialog
WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
if (!buttonDCAE.isDisplayed()){
File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
}
try{
fileInputElement.sendKeys(filePath + fileName);
} catch (ElementNotVisibleException e) {
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
showButtons();
fileInputElement.sendKeys(filePath + fileName);
}
// Fill the general page fields.
GeneralUIUtils.ultimateWait();
fillResourceGeneralInformationPage(resourceMetaData, user, true);
GeneralPageElements.clickCreateButton(10*60);
// GeneralUIUtils.ultimateWait(); "don't change import of csar can take longer then 3 minutes"
GeneralUIUtils.waitForLoader(10*60);
}
public static void importVfFromCsarNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
throws Exception {
GeneralUIUtils.ultimateWait();
SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s, Create button will not be clicked", resourceMetaData.getName()));
GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
GeneralUIUtils.ultimateWait();
// Insert file to the browse dialog
WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
if (!buttonDCAE.isDisplayed()){
File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
}
try{
fileInputElement.sendKeys(filePath + fileName);
} catch (ElementNotVisibleException e) {
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
showButtons();
fileInputElement.sendKeys(filePath + fileName);
}
// Fill the general page fields.
GeneralUIUtils.ultimateWait();
fillResourceGeneralInformationPage(resourceMetaData, user, true);
GeneralUIUtils.waitForLoader(10*60);
}
public static void updateVfWithCsar(String filePath, String fileName) {
ExtentTestActions.log(Status.INFO, "Updating VF with updated CSAR file named " + fileName);
WebElement browseWebElement = GeneralUIUtils.getInputElement(DataTestIdEnum.GeneralElementsEnum.UPLOAD_FILE_INPUT.getValue());
browseWebElement.sendKeys(filePath + fileName);
GeneralUIUtils.ultimateWait();
GeneralPageElements.clickUpdateButton();
GeneralUIUtils.waitForLoader();
ExtentTestActions.log(Status.INFO, "VF is updated.");
}
public static void showButtons(){
String parentElementClassAttribute = "sdc-dashboard-import-element-container";
WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
GeneralUIUtils.ultimateWait();
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
}
public static void showButtonsADD(){
try {
GeneralUIUtils.ultimateWait();
String parentElementClassAttribute = "sdc-dashboard-create-element-container";
WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
GeneralUIUtils.ultimateWait();
} catch (Exception e ){
GeneralUIUtils.ultimateWait();
String parentElementClassAttribute = "sdc-dashboard-create-element-container";
WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
GeneralUIUtils.ultimateWait();
}
SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
}
public static void clickOnElementByText(String textToClick, String customizationFoLog){
String customizationFoLogLocal = customizationFoLog != null ? customizationFoLog : "";
SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s %s", textToClick, customizationFoLogLocal));
GeneralUIUtils.clickOnElementByText(textToClick);
}
public static void createPNF(ResourceReqDetails resource, User user) throws Exception {
ExtentTestActions.log(Status.INFO, "Going to create a new PNF");
createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_PNF);
}
public static void createCR(ResourceReqDetails resource, User user) throws Exception {
ExtentTestActions.log(Status.INFO, "Going to create a new CR");
createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_CR);
}
public static ImmutablePair<String, String> getFirstRIPos(ResourceReqDetails createResourceInUI, User user) {
String responseAfterDrag = RestCDUtils.getResource(createResourceInUI, user).getResponse();
JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
String xPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
.get("posX");
String yPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
.get("posY");
return new ImmutablePair<String, String>(xPosPostDrag, yPosPostDrag);
}
}
|