summaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java')
-rw-r--r--ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java151
1 files changed, 136 insertions, 15 deletions
diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java
index 25ed4c2d91..b4f50020df 100644
--- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java
+++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/datatypes/CanvasManager.java
@@ -25,12 +25,15 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.LeftPanelCanvasItems;
+import org.openecomp.sdc.ci.tests.datatypes.enums.CircleSize;
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.CompositionPage;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
@@ -39,6 +42,7 @@ import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import com.aventstack.extentreports.Status;
+import com.clearspring.analytics.util.Pair;
public final class CanvasManager {
private Map<String, CanvasElement> canvasElements;
@@ -48,8 +52,14 @@ public final class CanvasManager {
private CanvasElement canvasElement;
// Offsets Are used to find upper right corner of canvas element in order to
// connect links
- private static final int CANVAS_ELEMENT_Y_OFFSET = 30;
- private static final int CANVAS_ELEMENT_X_OFFSET = 18; // 14 - 27
+ private static final int CANVAS_VF_Y_OFFSET = 30;
+ private static final int CANVAS_VF_X_OFFSET = 18; // 14 - 27
+
+ private static final int CANVAS_NORMATIVE_ELEMENT_Y_OFFSET = 12;
+ private static final int CANVAS_NORMATIVE_ELEMENT_X_OFFSET = 7;
+
+ private static final int CANVAS_SERVICE_Y_OFFSET = 27;
+ private static final int CANVAS_SERVICE_X_OFFSET = 16;
private CanvasManager() {
canvasElements = new HashMap<>();
@@ -116,6 +126,8 @@ public final class CanvasManager {
actions.perform();
actions.click().perform();
GeneralUIUtils.ultimateWait();
+
+ validateInstanceSelected(canvasElement);
ExtentTestActions.log(Status.INFO, String.format("Canvas element %s selected", canvasElement.getElementType()));
}
@@ -152,7 +164,7 @@ public final class CanvasManager {
}
return null;
}
-
+
public CanvasElement createElementOnCanvas(String elementName) throws Exception {
String actionDuration = GeneralUIUtils.getActionDuration(() -> {
try {
@@ -161,13 +173,13 @@ public final class CanvasManager {
e.printStackTrace();
}
});
-
+
if (canvasElement != null){
ExtentTestActions.log(Status.INFO, String.format("The element %s should now be on the canvas", elementName), actionDuration);
}
return canvasElement;
}
-
+
private CanvasElement createElementOnCanvasWithoutDuration(String elementDataTestId) throws Exception {
try {
WebElement element = findClickElement(elementDataTestId);
@@ -183,7 +195,7 @@ public final class CanvasManager {
addCanvasElement(canvasElement);
GeneralUIUtils.ultimateWait();
return canvasElement;
- }
+ }
catch (Exception e) {
System.out.println("Can't create element on canvas");
e.printStackTrace();
@@ -218,6 +230,7 @@ public final class CanvasManager {
return new ImmutablePair<Integer, Integer>(xElement, yElement);
}
+ // Will work only if 2 elements are big sized (VF size), if one of the elements is Small use the function linkElements
public void linkElements(CanvasElement firstElement, CanvasElement secondElement) throws Exception {
ExtentTestActions.log(Status.INFO, String.format("Linking between the %s instance and the %s instance.", firstElement.getElementType(), secondElement.getElementType()));
drawSimpleLink(firstElement, secondElement);
@@ -225,20 +238,41 @@ public final class CanvasManager {
ExtentTestActions.log(Status.INFO, String.format("The instances %s and %s should now be connected.", firstElement.getElementType(), secondElement.getElementType()));
}
+ public void linkElements(CanvasElement firstElement, CircleSize firstElementSize, CanvasElement secondElement, CircleSize secondElementSize) throws Exception {
+ drawSimpleLink(firstElement,firstElementSize, secondElement,secondElementSize);
+ selectReqAndCapAndConnect();
+ ExtentTestActions.log(Status.INFO, String.format("The instances %s and %s should now be connected.", firstElement.getElementType(), secondElement.getElementType()));
+ }
+
private void selectReqAndCapAndConnect() throws Exception {
- // Select First Cap
- GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.LinkMenuItems.LINK_ITEM_CAP.getValue()).get(0).click();
- // Select First Req
- GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.LinkMenuItems.LINK_ITEM_REQ.getValue()).get(0).click();
- // Connect
- GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.LinkMenuItems.CONNECT_BUTTON.getValue()).click();
+ addFitstReqOrCapAndPressNext();
+ addFitstReqOrCapAndPressNext();
+ linkMenuClickOnFinishButton();
+ }
- GeneralUIUtils.waitForLoader();
+ private void addFitstReqOrCapAndPressNext() throws Exception {
+ addFirstReqOrCap();
+ linkMenuClickOnNextButton();
}
+ private void addFirstReqOrCap() {
+ GeneralUIUtils.getWebElementsListByClassName(DataTestIdEnum.LinkMenuItems.LINK_ITEM_CAP_Or_REQ.getValue()).get(0).click();
+ }
+
+ private void linkMenuClickOnNextButton() throws Exception {
+ GeneralUIUtils.clickOnElementByText("Next");
+ GeneralUIUtils.ultimateWait();
+ }
+
+ private void linkMenuClickOnFinishButton() throws Exception {
+ GeneralUIUtils.clickOnElementByText("Finish");
+ GeneralUIUtils.ultimateWait();
+ }
+
+
private void drawSimpleLink(CanvasElement firstElement, CanvasElement secondElement) throws Exception {
- int yOffset = CANVAS_ELEMENT_Y_OFFSET;
- int xOffset = CANVAS_ELEMENT_X_OFFSET;
+ int yOffset = CANVAS_VF_Y_OFFSET;
+ int xOffset = CANVAS_VF_X_OFFSET;
actions.moveToElement(canvas, firstElement.getLocation().left + xOffset,
firstElement.getLocation().right - yOffset);
@@ -250,6 +284,45 @@ public final class CanvasManager {
GeneralUIUtils.ultimateWait();
}
+ private void drawSimpleLink(CanvasElement firstElement, CircleSize firstElementSize, CanvasElement secondElement, CircleSize secondElementSize) throws Exception {
+ ExtentTestActions.log(Status.INFO, String.format("Linking between the %s instance and the %s instance.", firstElement.getElementType(), secondElement.getElementType()));
+ Integer yOffset = getCircleOffset(firstElementSize).right;
+ Integer xOffset = getCircleOffset(firstElementSize).left;
+ firstElement.getElementType();
+
+
+ actions.moveToElement(canvas, firstElement.getLocation().left + xOffset,
+ firstElement.getLocation().right - yOffset);
+
+ actions.clickAndHold();
+
+ yOffset = getCircleOffset(secondElementSize).right;
+ xOffset = getCircleOffset(secondElementSize).left;
+
+ actions.moveToElement(canvas, secondElement.getLocation().left + xOffset, secondElement.getLocation().right - yOffset);
+ actions.release();
+ actions.perform();
+ GeneralUIUtils.ultimateWait();
+ }
+
+ private Pair<Integer,Integer> getCircleOffset(CircleSize circleSize)
+ {
+ Pair<Integer,Integer> circleSizes;
+ if(circleSize.equals(CircleSize.VF))
+ {
+ circleSizes = new Pair <Integer,Integer> (CANVAS_VF_X_OFFSET,CANVAS_VF_Y_OFFSET);
+ }
+ else if (circleSize.equals(CircleSize.NORMATIVE))
+ {
+ circleSizes = new Pair <Integer,Integer> (CANVAS_NORMATIVE_ELEMENT_X_OFFSET,CANVAS_NORMATIVE_ELEMENT_Y_OFFSET);
+ }
+ else
+ {
+ circleSizes = new Pair <Integer,Integer> (CANVAS_SERVICE_X_OFFSET,CANVAS_SERVICE_Y_OFFSET);
+ }
+ return circleSizes;
+ }
+
public String updateElementNameInCanvas(CanvasElement canvasElement, String newInstanceName) throws Exception {
GeneralUIUtils.ultimateWait();;
clickOnCanvaElement(canvasElement);
@@ -265,4 +338,52 @@ public final class CanvasManager {
SetupCDTest.getExtendTest().log(Status.INFO, String.format("Name of element instance changed from %s to %s", oldInstanceName, newInstanceName));
return oldInstanceName;
}
+
+ /**
+ * @param canvasElement
+ * Validate that instance was selected on right sidebar
+ */
+ public void validateInstanceSelected(CanvasElement canvasElement) {
+ long maxWait = 3000;
+ long sumOfWaiting = 0;
+ long napPeriod = 200;
+ boolean isInstanceSelected;
+ do {
+ isInstanceSelected = CompositionPage.getSelectedInstanceName().contains(canvasElement.getElementType());
+
+ if (!isInstanceSelected) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(napPeriod);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ sumOfWaiting += napPeriod;
+ if (sumOfWaiting > maxWait) {
+ Assert.fail(String.format("Can't select instance properly, waited for %s seconds", (int) (maxWait/1000)));
+ }
+ } while (!isInstanceSelected);
+ }
+
+ private void selectReqCapByName(String reqCapName)
+ {
+ GeneralUIUtils.clickOnElementByText(reqCapName);
+ GeneralUIUtils.ultimateWait();
+ }
+
+ private void selectTypeOfReqCap(String reqCapType)
+ {
+ GeneralUIUtils.getSelectList(reqCapType,DataTestIdEnum.LinkMenuItems.REQ_CAP_SELECT_DATA_TESTS_ID.getValue());
+ GeneralUIUtils.ultimateWait();
+ }
+
+ public void linkElementsAndSelectCapReqTypeAndCapReqName(CanvasElement firstElement, CircleSize firstElementSize, CanvasElement secondElement, CircleSize secondElementSize, ConnectionWizardPopUpObject connectionWizardPopUpObject) throws Exception {
+ drawSimpleLink(firstElement, firstElementSize, secondElement, secondElementSize);
+ selectTypeOfReqCap(connectionWizardPopUpObject.getCapabilityTypeSecondItem());
+ addFitstReqOrCapAndPressNext();
+ selectReqCapByName(connectionWizardPopUpObject.getCapabilityNameSecondItem());
+ linkMenuClickOnNextButton();
+ linkMenuClickOnFinishButton();
+ }
}