2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.datatypes;
23 import com.aventstack.extentreports.Status;
24 import com.clearspring.analytics.util.Pair;
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonParser;
27 import org.apache.commons.lang3.tuple.ImmutablePair;
28 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.LeftPanelCanvasItems;
29 import org.openecomp.sdc.ci.tests.datatypes.enums.CircleSize;
30 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
31 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
32 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
33 import org.openecomp.sdc.ci.tests.pages.PropertiesAssignmentPage;
34 import org.openecomp.sdc.ci.tests.pages.PropertyNameBuilder;
35 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
36 import org.openqa.selenium.By;
37 import org.openqa.selenium.StaleElementReferenceException;
38 import org.openqa.selenium.WebElement;
39 import org.openqa.selenium.interactions.Actions;
40 import org.testng.Assert;
41 import org.testng.SkipException;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.List;
47 import java.util.Random;
48 import java.util.UUID;
49 import java.util.concurrent.TimeUnit;
50 import java.util.stream.Collectors;
52 public final class CanvasManager {
53 public static final int VIEW_BUTTON_X_DELTA = 30;
54 public static final int VIEW_BUTTON_Y_DELTA = 11;
55 public static final int DELTET_BUTTON_X_DELTA = 30;
56 public static final int CANVAS_ELEMENT_TYPE_SPLITER = 4;
57 public static final int MAX_WAIT_DIVIDER = 1000;
58 public static final int THREAD_SLEEP_TIME = 5000;
59 private Map<String, CanvasElement> canvasElements;
60 private Actions actions;
61 private WebElement canvas;
62 private int reduceCanvasWidthFactor;
63 private CanvasElement canvasElement;
64 // Offsets Are used to find upper right corner of canvas element in order to
66 private static final int CANVAS_VF_Y_OFFSET = 30;
67 private static final int CANVAS_VF_X_OFFSET = 18; // 14 - 27
69 private static final int CANVAS_NORMATIVE_ELEMENT_Y_OFFSET = 12;
70 private static final int CANVAS_NORMATIVE_ELEMENT_X_OFFSET = 7;
72 private static final int CANVAS_SERVICE_Y_OFFSET = 27;
73 private static final int CANVAS_SERVICE_X_OFFSET = 16;
75 private CanvasManager() {
76 canvasElements = new HashMap<>();
77 actions = new Actions(GeneralUIUtils.getDriver());
78 canvas = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.CANVAS.getValue());
80 WebElement webElement = GeneralUIUtils
81 .getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.CANVAS_RIGHT_PANEL.getValue());
82 reduceCanvasWidthFactor = webElement.getSize().width;
83 } catch (Exception e) {
84 reduceCanvasWidthFactor = 0;
88 public static CanvasManager getCanvasManager() {
89 return new CanvasManager();
92 public List<CanvasElement> getCanvasElements() {
93 return canvasElements.values().stream().collect(Collectors.toList());
96 private void addCanvasElement(CanvasElement element) {
97 String prefix = element.getElementType();
98 List<CanvasElement> canvasElementsFromSameTemplate = new ArrayList<>();
100 // collect all elements from from same template
101 for (CanvasElement currElement : canvasElements.values()) {
102 if (currElement.getElementNameOnCanvas().toLowerCase().startsWith(prefix.toLowerCase())) {
103 canvasElementsFromSameTemplate.add(currElement);
107 // match element name to actual name on canvas
108 if (canvasElementsFromSameTemplate.size() > 0) {
109 String newName = prefix + " " + canvasElementsFromSameTemplate.size();
110 element.setElementNameOnCanvas(newName);
113 canvasElements.put(element.getUniqueId(), element);
116 private void moveElementOnCanvas(CanvasElement canvasElement, ImmutablePair<Integer, Integer> newLocation)
118 GeneralUIUtils.waitForLoader();
119 actions.moveToElement(canvas, canvasElement.getLocation().left, canvasElement.getLocation().right);
120 actions.clickAndHold();
121 actions.moveToElement(canvas, newLocation.left, newLocation.right);
124 canvasElement.setLocation(newLocation);
125 GeneralUIUtils.waitForLoader();
129 public void moveToFreeLocation(String containerName) {
130 final int maxWait = 5000;
131 final int napPeriod = 200;
132 int sumOfWaiting = 0;
133 boolean isKeepWaiting = false;
134 while (!isKeepWaiting) {
135 ImmutablePair<Integer, Integer> freePosition = getFreePosition();
136 actions.moveToElement(canvas, freePosition.left, freePosition.right);
137 actions.clickAndHold();
140 isKeepWaiting = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.CompositionRightPanel.COMPONENT_TITLE.getValue()).getText()
141 .equals(containerName);
142 sumOfWaiting += napPeriod;
143 if (sumOfWaiting > maxWait) {
144 Assert.fail("Can't click on VF");
149 public void clickOnCanvaElement(CanvasElement canvasElement) {
150 ImmutablePair<Integer, Integer> coordinates = getElementCoordinates(canvasElement.getElementNameOnCanvas());
151 actions.moveToElement(canvas, coordinates.left, coordinates.right);
152 actions.clickAndHold();
155 GeneralUIUtils.ultimateWait();
156 actions.click().perform();
157 GeneralUIUtils.ultimateWait();
159 validateInstanceSelected(canvasElement);
160 ExtentTestActions.log(Status.INFO, String.format("Canvas element %s selected", canvasElement.getElementType()));
163 public void openLinkPopupReqsCapsConnection(CanvasElement canvasElement) {
164 ExtentTestActions.log(Status.INFO, "Open Link popup");
165 clickOnCanvasLink(canvasElement);
166 int x = canvasElement.getLocation().getLeft() + VIEW_BUTTON_X_DELTA;
167 int y = canvasElement.getLocation().getRight() + VIEW_BUTTON_Y_DELTA;
168 clickOnCanvasPosition(x, y);
169 GeneralUIUtils.ultimateWait();
172 public void openLinkPopupReqsCapsConnection(CanvasElement sourceElement, CanvasElement destElement) {
173 ExtentTestActions.log(Status.INFO, "Open Link popup");
174 ImmutablePair<Integer, Integer> sourceCoordinates = getElementCoordinates(sourceElement.getElementNameOnCanvas());
175 ImmutablePair<Integer, Integer> destCoordinates = getElementCoordinates(destElement.getElementNameOnCanvas());
176 ImmutablePair<Integer, Integer> linkPosition = calcMidOfLink(sourceCoordinates, destCoordinates);
178 clickOnCanvasPosition(linkPosition.left, linkPosition.right); // click on link
179 int x = linkPosition.left + VIEW_BUTTON_X_DELTA;
180 int y = linkPosition.right + VIEW_BUTTON_Y_DELTA;
181 clickOnCanvasPosition(x, y); // click on view popup
182 GeneralUIUtils.ultimateWait();
185 public void closeLinkPopupReqsCapsConnection() {
186 GeneralUIUtils.clickOnElementByTestId("Cancel");
187 //GeneralUIUtils.ultimateWait();
190 public void clickSaveOnLinkPopup() {
191 ExtentTestActions.log(Status.INFO, "Click save on link popup");
192 GeneralUIUtils.clickOnElementByTestId("Save");
193 //GeneralUIUtils.ultimateWait();
196 public void deleteLinkPopupReqsCapsConnection(CanvasElement canvasElement) {
197 ExtentTestActions.log(Status.INFO, "Delete Link ");
198 clickOnCanvasLink(canvasElement);
199 int x = canvasElement.getLocation().getLeft() + DELTET_BUTTON_X_DELTA;
200 int y = canvasElement.getLocation().getRight() + DELTET_BUTTON_X_DELTA;
201 clickOnCanvasPosition(x, y);
204 public void deleteLinkPopupReqsCapsConnection(CanvasElement sourceElement, CanvasElement destElement) {
205 ExtentTestActions.log(Status.INFO, "Delete Link ");
206 ImmutablePair<Integer, Integer> sourceCoordinates = getElementCoordinates(sourceElement.getElementNameOnCanvas());
207 ImmutablePair<Integer, Integer> destCoordinates = getElementCoordinates(destElement.getElementNameOnCanvas());
208 ImmutablePair<Integer, Integer> linkPosition = calcMidOfLink(sourceCoordinates, destCoordinates);
209 clickOnCanvasPosition(linkPosition.left, linkPosition.right); // click on link
210 int x = linkPosition.left + DELTET_BUTTON_X_DELTA;
211 int y = linkPosition.right + DELTET_BUTTON_X_DELTA;
212 clickOnCanvasPosition(x, y);
215 public void clickOnCanvasLink(CanvasElement canvasElement) {
216 actions.moveToElement(canvas, canvasElement.getLocation().left, canvasElement.getLocation().right);
217 actions.click().perform();
218 GeneralUIUtils.ultimateWait();
221 public void clickOnCanvasPosition(int x, int y) {
224 actions.moveToElement(canvas, x, y);
227 GeneralUIUtils.ultimateWait();
228 } catch (Exception e) {
229 System.out.println(e);
233 public void moveElementOnCanvas(CanvasElement canvasElement) throws Exception {
234 moveElementOnCanvas(canvasElement, getFreePosition());
237 public void deleteElementFromCanvas(CanvasElement canvasElement) throws Exception {
238 GeneralUIUtils.waitForLoader();
239 actions.moveToElement(canvas, canvasElement.getLocation().left, canvasElement.getLocation().right);
242 ExtentTestActions.log(Status.INFO, String.format("Removing canvas element %s ", canvasElement.getElementType()));
243 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.DELETE_INSTANCE_BUTTON.getValue())
245 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.DELETE_INSTANCE_CANCEL.getValue()).click();
246 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.DELETE_INSTANCE_BUTTON.getValue())
248 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.DELETE_INSTANCE_OK.getValue()).click();
249 canvasElements.remove(canvasElement.getUniqueId());
250 GeneralUIUtils.ultimateWait();
251 if (canvasElement.getElementType().contains("-")) {
252 ExtentTestActions.log(Status.INFO, String.format(
253 "Canvas element %s is removed",
254 canvasElement.getElementType().split("-")[CANVAS_ELEMENT_TYPE_SPLITER]));
256 ExtentTestActions.log(Status.INFO, String.format(
257 "Canvas element %s is removed",
258 canvasElement.getElementType()));
262 private WebElement findClickElement(String dataTestId) {
264 while (attempts < 2) {
266 return GeneralUIUtils.getWebElementByTestID(dataTestId);
267 } catch (StaleElementReferenceException e) {
274 public CanvasElement createElementOnCanvas(String elementName) {
275 String actionDuration = GeneralUIUtils.getActionDuration(() -> {
277 canvasElement = createElementOnCanvasWithoutDuration(elementName);
278 } catch (Exception e) {
283 if (canvasElement != null) {
284 ExtentTestActions.log(Status.INFO, String.format("The element %s should now be on the canvas", elementName), actionDuration);
286 return canvasElement;
289 private CanvasElement createElementOnCanvasWithoutDuration(String elementDataTestId) throws Exception {
290 final int offset = 20;
292 CompositionPage.searchForElement(elementDataTestId);
293 WebElement element = findClickElement(elementDataTestId);
294 ImmutablePair<Integer, Integer> freePosition = getFreePosition();
295 actions.moveToElement(element, offset, offset);
296 actions.clickAndHold();
297 actions.moveToElement(canvas, freePosition.left, freePosition.right);
300 GeneralUIUtils.ultimateWait();
301 String uniqueId = elementDataTestId + "_" + UUID.randomUUID().toString();
302 CanvasElement canvasElement = new CanvasElement(uniqueId, freePosition, elementDataTestId);
303 addCanvasElement(canvasElement);
304 GeneralUIUtils.ultimateWait();
305 return canvasElement;
306 } catch (Exception e) {
307 System.out.println("Can't create element on canvas");
313 public CanvasElement createElementOnCanvas(LeftPanelCanvasItems canvasItem) {
314 return createElementOnCanvas(canvasItem.getValue());
317 private ImmutablePair<Integer, Integer> getFreePosition() {
318 ImmutablePair<Integer, Integer> randomPosition = null;
319 boolean freePosition = false;
320 final int minSpace = 150;
321 while (!freePosition) {
322 ImmutablePair<Integer, Integer> tempRandomPosition = getRandomPosition();
323 freePosition = !canvasElements.values().stream().map(e -> e.getLocation())
324 .filter(e -> Math.abs(e.left - tempRandomPosition.left) < minSpace
325 && Math.abs(e.right - tempRandomPosition.right) < minSpace)
326 .findAny().isPresent();
327 randomPosition = tempRandomPosition;
329 return randomPosition;
332 private ImmutablePair<Integer, Integer> getRandomPosition() {
333 final int edgeBuffer = 50;
334 Random random = new Random();
335 int xElement = random.nextInt(canvas.getSize().width - 2 * edgeBuffer - reduceCanvasWidthFactor) + edgeBuffer;
336 int yElement = random.nextInt(canvas.getSize().height - 2 * edgeBuffer) + edgeBuffer;
337 return new ImmutablePair<Integer, Integer>(xElement, yElement);
340 // Will work only if 2 elements are big sized (VF size), if one of the elements is Small use the function linkElements
341 public void linkElements(CanvasElement firstElement, CanvasElement secondElement) throws Exception {
342 ExtentTestActions.log(Status.INFO, String.format("Linking between the %s instance and the %s instance.", firstElement.getElementType(), secondElement.getElementType()));
343 drawSimpleLink(firstElement.getElementNameOnCanvas(), secondElement.getElementNameOnCanvas());
344 selectReqAndCapAndConnect();
345 ExtentTestActions.log(Status.INFO, String.format("The instances %s and %s should now be connected.", firstElement.getElementType(), secondElement.getElementType()));
348 // old version, depricated
349 public void linkElements(CanvasElement firstElement, CircleSize firstElementSize, CanvasElement secondElement, CircleSize secondElementSize) throws Exception {
350 drawSimpleLink(firstElement, firstElementSize, secondElement, secondElementSize);
351 selectReqAndCapAndConnect();
352 ExtentTestActions.log(Status.INFO, String.format("The instances %s and %s should now be connected.", firstElement.getElementType(), secondElement.getElementType()));
355 public void linkElements(String firstElement, String secondElement) throws Exception {
356 drawSimpleLink(firstElement, secondElement);
357 selectReqAndCapAndConnect();
358 ExtentTestActions.log(Status.INFO, String.format("The instances %s and %s should now be connected.", firstElement, secondElement));
361 // use JS to get coordinates of elements
362 private void drawSimpleLink(String firstElement, String secondElement) {
363 ImmutablePair<Integer, Integer> firstElementCoordinates = getGreenDotCoordinatesOfElement(firstElement);
364 ImmutablePair<Integer, Integer> secondElementCoordinates = getElementCoordinates(secondElement);
366 actions.moveToElement(canvas, firstElementCoordinates.left, firstElementCoordinates.right);
368 actions.moveToElement(canvas, firstElementCoordinates.left, firstElementCoordinates.right);
369 actions.clickAndHold();
370 actions.moveToElement(canvas, secondElementCoordinates.left, secondElementCoordinates.right);
373 GeneralUIUtils.ultimateWait();
376 private void selectReqAndCapAndConnect() throws Exception {
377 addFirstReqOrCapAndPressNext();
378 addFirstReqOrCapAndPressNext();
379 linkMenuClickOnFinishButton();
382 private void addFirstReqOrCapAndPressNext() throws Exception {
384 linkMenuClickOnNextButton();
387 private void addFirstReqOrCap() {
388 GeneralUIUtils.getWebElementsListByClassName(DataTestIdEnum.LinkMenuItems.LINK_ITEM_CAP_OR_REQ.getValue()).get(0).click();
391 private void linkMenuClickOnNextButton() throws Exception {
392 GeneralUIUtils.clickOnElementByText("Next");
393 GeneralUIUtils.ultimateWait();
396 private void linkMenuClickOnFinishButton() throws Exception {
397 GeneralUIUtils.clickOnElementByText("Finish");
398 GeneralUIUtils.ultimateWait();
402 private void drawSimpleLink(CanvasElement firstElement, CanvasElement secondElement) throws Exception {
403 int yOffset = CANVAS_VF_Y_OFFSET;
404 int xOffset = CANVAS_VF_X_OFFSET;
406 actions.moveToElement(canvas, firstElement.getLocation().left + xOffset,
407 firstElement.getLocation().right - yOffset);
409 actions.clickAndHold();
410 actions.moveToElement(canvas, secondElement.getLocation().left + xOffset, secondElement.getLocation().right - yOffset);
413 GeneralUIUtils.ultimateWait();
416 private void drawSimpleLink(CanvasElement firstElement, CircleSize firstElementSize, CanvasElement secondElement, CircleSize secondElementSize) throws Exception {
417 ExtentTestActions.log(Status.INFO, String.format("Linking between the %s instance and the %s instance.", firstElement.getElementType(), secondElement.getElementType()));
418 Integer yOffset = getCircleOffset(firstElementSize).right;
419 Integer xOffset = getCircleOffset(firstElementSize).left;
420 firstElement.getElementType();
423 actions.moveToElement(canvas, firstElement.getLocation().left + xOffset,
424 firstElement.getLocation().right - yOffset);
426 actions.clickAndHold();
428 yOffset = getCircleOffset(secondElementSize).right;
429 xOffset = getCircleOffset(secondElementSize).left;
431 actions.moveToElement(canvas, secondElement.getLocation().left + xOffset, secondElement.getLocation().right - yOffset);
435 GeneralUIUtils.ultimateWait();
438 private Pair<Integer, Integer> getCircleOffset(CircleSize circleSize) {
439 Pair<Integer, Integer> circleSizes;
440 if (circleSize.equals(CircleSize.VF)) {
441 circleSizes = new Pair<Integer, Integer>(CANVAS_VF_X_OFFSET, CANVAS_VF_Y_OFFSET);
442 } else if (circleSize.equals(CircleSize.NORMATIVE)) {
443 circleSizes = new Pair<Integer, Integer>(CANVAS_NORMATIVE_ELEMENT_X_OFFSET, CANVAS_NORMATIVE_ELEMENT_Y_OFFSET);
445 circleSizes = new Pair<Integer, Integer>(CANVAS_SERVICE_X_OFFSET, CANVAS_SERVICE_Y_OFFSET);
450 public String updateElementNameInCanvas(CanvasElement canvasElement, String newInstanceName) {
451 GeneralUIUtils.ultimateWait();
452 clickOnCanvaElement(canvasElement);
453 GeneralUIUtils.getWebElementBy(By.id("editPencil")).click();
454 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.RENAME_INSTANCE_CANCEL.getValue()).click();
455 GeneralUIUtils.getWebElementBy(By.id("editPencil")).click();
456 WebElement instanceNameField = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.INSTANCE_NAME_FIELD.getValue());
457 String oldInstanceName = instanceNameField.getAttribute("value");
458 instanceNameField.clear();
459 instanceNameField.sendKeys(newInstanceName);
460 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.RENAME_INSTANCE_OK.getValue()).click();
461 GeneralUIUtils.ultimateWait();
462 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("w-sdc-modal-resource-instance-name"));
463 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Name of element instance changed from %s to %s", oldInstanceName, newInstanceName));
464 return oldInstanceName;
468 * @param canvasElement Validate that instance was selected on right sidebar
470 private void validateInstanceSelected(CanvasElement canvasElement) {
471 final long maxWait = 5000;
472 final long napPeriod = 200;
473 long sumOfWaiting = 0;
474 boolean isInstanceSelected;
476 isInstanceSelected = CompositionPage.getSelectedInstanceName().toLowerCase().contains(canvasElement.getElementType().toLowerCase());
478 if (!isInstanceSelected) {
480 TimeUnit.MILLISECONDS.sleep(napPeriod);
481 } catch (InterruptedException e) {
486 sumOfWaiting += napPeriod;
487 if (sumOfWaiting > maxWait) {
488 throw new SkipException(String.format("Bug 342260, can't select instance properly, waited for %s seconds after click on instance", (int) (maxWait / MAX_WAIT_DIVIDER)));
490 } while (!isInstanceSelected);
493 public void validateLinkIsSelected() {
494 final long maxWait = 5000;
495 final long napPeriod = 200;
496 long sumOfWaiting = 0;
497 boolean isInstanceSelected;
499 isInstanceSelected = GeneralUIUtils.isWebElementExistByClass("w-sdc-menu-item w-sdc-canvas-menu-item-view");
501 if (!isInstanceSelected) {
503 TimeUnit.MILLISECONDS.sleep(napPeriod);
504 } catch (InterruptedException e) {
509 sumOfWaiting += napPeriod;
510 if (sumOfWaiting > maxWait) {
511 Assert.fail(String.format("Can't select link properly, waited for %s seconds", (int) (maxWait / MAX_WAIT_DIVIDER)));
513 } while (!isInstanceSelected);
516 private void selectReqCapByName(String reqCapName) {
517 GeneralUIUtils.clickOnElementByText(reqCapName);
518 GeneralUIUtils.ultimateWait();
521 private void selectTypeOfReqCap(String dataTestId, String reqCapType) {
522 GeneralUIUtils.selectByValueTextContained(dataTestId, reqCapType);
525 public void linkElementsAndSelectCapReqTypeAndCapReqName(CanvasElement firstElement, CanvasElement secondElement, ConnectionWizardPopUpObject connectionWizardPopUpObject) throws Exception {
526 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating link between %s and %s", firstElement.getElementType(), secondElement.getElementType()));
527 drawSimpleLink(firstElement.getElementNameOnCanvas(), secondElement.getElementNameOnCanvas());
528 selectTypeOfReqCap(DataTestIdEnum.LinkMenuItems.REQ_CAP_SELECT_DATA_TESTS_ID.getValue(), connectionWizardPopUpObject.getCapabilityTypeSecondItem());
529 addFirstReqOrCapAndPressNext();
530 selectReqCapByName(connectionWizardPopUpObject.getCapabilityNameSecondItem());
531 linkMenuClickOnNextButton();
532 linkMenuClickOnFinishButton();
535 public Map<String, String> linkElementsWithCapPropAssignment(CanvasElement firstElement, CanvasElement secondElement, ConnectionWizardPopUpObject connectionWizardPopUpObject) throws Exception {
536 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating link between %s and %s", firstElement.getElementType(), secondElement.getElementType()));
537 drawSimpleLink(firstElement.getElementNameOnCanvas(), secondElement.getElementNameOnCanvas());
538 selectTypeOfReqCap(DataTestIdEnum.LinkMenuItems.REQ_CAP_SELECT_DATA_TESTS_ID.getValue(), connectionWizardPopUpObject.getCapabilityTypeSecondItem());
539 addFirstReqOrCapAndPressNext();
540 selectReqCapByName(connectionWizardPopUpObject.getCapabilityNameSecondItem());
541 linkMenuClickOnNextButton();
542 Map<String, String> mapOfValues = connectionWizardAssignCapPropValues();
543 linkMenuClickOnFinishButton();
544 Thread.sleep(THREAD_SLEEP_TIME);
549 public Map<String, String> connectionWizardAssignCapPropValues() throws Exception {
550 //get list of capability property value fields data-tests-ids in connection wizard
551 List<String> valueField = getListOfValueFieldIDs();
552 //get map of field ids and their values, fill in values if empty
553 Map<String, String> propValues = getMapOfCapPropValues(valueField, true);
557 public Map<String, String> connectionWizardCollectCapPropValues() throws Exception {
558 //get list of capability property value fields data-tests-ids in connection wizard
559 List<String> valueField = getListOfValueFieldIDs();
560 //get map of field ids and their values, collect existing values
561 Map<String, String> propValues = getMapOfCapPropValues(valueField, false);
565 private List<String> getListOfValueFieldIDs() {
566 String propName = GeneralUIUtils.getWebElementsListByContainsClassName("multiline-ellipsis-content").get(0).getText();
567 List<WebElement> valueNameElement = GeneralUIUtils.findElementsByXpath("//div[@class='dynamic-property-row nested-level-1']/div[1]");
568 List<String> valueName = new ArrayList<>();
569 for (int i = 0; i < valueNameElement.size(); i++) {
570 valueName.add(valueNameElement.get(i).getText());
572 //get list of value field names as appear in data-tests-id
573 List<String> valueField = new ArrayList<>();
574 for (int i = 0; i < valueName.size(); i++) {
575 valueField.add(PropertyNameBuilder.buildIComplexField(propName, valueName.get(i)));
580 private Map<String, String> getMapOfCapPropValues(List<String> valueField, boolean isValueAssign) throws Exception {
581 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Assigning values to properties of capabilities and/or collecting existing ones"));
582 Map<String, String> propValues = new HashMap<>();
583 for (int i = 0; i < valueField.size(); i++) {
584 String fieldId = valueField.get(i);
585 if (GeneralUIUtils.getWebElementByTestID(fieldId).getAttribute("value").isEmpty() && isValueAssign) {
586 //add value and put into map
587 propValues.put(fieldId, "value" + i);
588 PropertiesAssignmentPage.editPropertyValue(fieldId, "value" + i);
590 //put existing value into map
591 propValues.put(fieldId, GeneralUIUtils.getWebElementByTestID(valueField.get(i)).getAttribute("value"));
598 public ImmutablePair<Integer, Integer> calcMidOfLink(ImmutablePair<Integer, Integer> location1, ImmutablePair<Integer, Integer> location2) {
599 int x = (location1.getLeft() + location2.getLeft()) / 2;
600 int y = (location1.getRight() + location2.getRight()) / 2;
602 ImmutablePair<Integer, Integer> location = new ImmutablePair<>(x, y);
606 public ImmutablePair<Integer, Integer> getElementCoordinates(String elementName) {
607 Object position = GeneralUIUtils.getElementPositionOnCanvas(elementName);
608 return converJSJsonToCoordinates(position);
611 public ImmutablePair<Integer, Integer> getGreenDotCoordinatesOfElement(String elementName) {
612 Object position = GeneralUIUtils.getElementGreenDotPositionOnCanvas(elementName);
613 return converJSJsonToCoordinates(position);
616 public ImmutablePair<Integer, Integer> converJSJsonToCoordinates(Object position) {
617 JsonElement root = new JsonParser().parse(position.toString());
618 int xElement = root.getAsJsonObject().get("x").getAsInt();
619 int yElement = root.getAsJsonObject().get("y").getAsInt();
620 return new ImmutablePair<Integer, Integer>(xElement, yElement);