1 package vid.automation.test.sections;
3 import com.google.common.collect.ImmutableList;
4 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.JavascriptExecutor;
7 import org.openqa.selenium.NoSuchElementException;
8 import org.openqa.selenium.WebElement;
9 import org.testng.Assert;
10 import vid.automation.test.Constants;
11 import vid.automation.test.infra.Click;
12 import vid.automation.test.infra.Get;
13 import vid.automation.test.infra.Wait;
15 import java.util.Collection;
17 import java.util.function.Function;
18 import java.util.stream.Collectors;
20 import static org.hamcrest.CoreMatchers.equalTo;
21 import static org.hamcrest.CoreMatchers.is;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.collection.IsEmptyCollection.empty;
24 import static vid.automation.test.Constants.DrawingBoard.*;
26 public class DrawingBoardPage extends VidBasePage {
28 public DrawingBoardPage(){
32 public void expandTreeByClickingNode(String nodeName, String... children) {
33 checkNodesVisible(children, false);
35 checkNodesVisible(children, true);
38 public void clickNode(String nodeName) {
39 Click.byTestId(Constants.DrawingBoard.NODE_PREFIX + nodeName);
42 public void expandFirstItemInTreeByExpanderIcon(String treeDataTestId, String... children) {
43 checkNodesVisible(children, false);
44 Click.byXpath("//tree-root[@data-tests-id='" + treeDataTestId + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
45 checkNodesVisible(children, true);
48 public void checkLeafNodeHasNoExpander(String nodeName){
49 WebElement webElement = Get.byXpath("//div[contains(@class, '" + Constants.DrawingBoard.TREE_NODE_LEAF + "') and .//div[@data-tests-id='" + Constants.DrawingBoard.NODE_PREFIX + nodeName + "']]");
50 Assert.assertNotNull(webElement, "There is an expander to node " + nodeName + " without children");
53 public void verifyNonCollapsableTreeByClickingNode(String nodeName, String... children) {
54 checkNodesVisible(children, true);
56 checkNodesVisible(children, true);
59 public void collapseFirstItemInTreeByCollapseIcon(String treeDataTestId, String... children) {
60 checkNodesVisible(children, true);
61 Click.byXpath("//tree-root[@data-tests-id='" + treeDataTestId + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
62 checkNodesVisible(children, false);
65 public void RefreshPage(){
66 GeneralUIUtils.getDriver().navigate().refresh();
69 public void assertInitalTextOfTree(String treeDataTestId, String[] initialElements) {
70 WebElement webElement = Get.byTestId(treeDataTestId);
71 String expected = String.join("\n", initialElements);
72 Wait.byText(expected);
73 Assert.assertEquals(webElement.getText(), expected);
76 public void checkAddButton(String[] rootElements){
77 String previousAddButton = null;
78 for (String root : rootElements) {
79 String currentButton = Constants.DrawingBoard.NODE_PREFIX + root + Constants.DrawingBoard.ADD_BUTTON;
80 checkThatButtonNotExist(currentButton);
81 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + root);
82 checkThatButtonExist(currentButton);
83 if (previousAddButton != null) {
84 checkThatButtonNotExist(previousAddButton);
86 Click.byTestId(currentButton);
87 previousAddButton = currentButton;
91 public void clickAddButtonByNodeName(String treeNodeId) {
92 String nodeElement = "node-"+ treeNodeId;
93 String addButtonTestId = Constants.DrawingBoard.NODE_PREFIX + treeNodeId + Constants.DrawingBoard.ADD_BUTTON;
94 GeneralUIUtils.hoverOnAreaByTestId(nodeElement);
95 GeneralUIUtils.hoverOnAreaByTestId(addButtonTestId);
96 Click.byTestId(addButtonTestId);
99 private void checkThatButtonNotExist(String dataTestId){
100 // Assert.assertFalse(GeneralUIUtils.isElementVisibleByTestId(dataTestId),"button " + dataTestId + " should not exist");
103 private void checkThatButtonExist(String dataTestId){
104 // Assert.assertTrue(GeneralUIUtils.isElementVisibleByTestId(dataTestId), "button " + dataTestId + " should exist");
107 private void checkThatPseudoElementNotExist(String dataTestId) {
108 assertPseudoElementDisplayProp(dataTestId, "none");
111 private void assertPseudoElementDisplayProp(String dataTestId, String expectedCssDisplayProp){
112 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
113 final Object cssDisplayProp = javascriptExecutor.executeScript("" +
114 "return window.getComputedStyle(" +
115 " document.querySelector('[data-tests-id=\""+dataTestId+"\"]'),':before'" +
116 ").getPropertyValue('display')"
118 assertThat("button " + dataTestId + " should exist", cssDisplayProp, is(expectedCssDisplayProp));
121 private void checkThatPseudoElementExist(String dataTestId) {
122 assertPseudoElementDisplayProp(dataTestId, "inline-block");
125 public void checkThatContextMenuExist(String contextMenu){
126 Assert.assertTrue(GeneralUIUtils.isWebElementExistByTestId(contextMenu), "context menu should appear");
129 public void checkThatContextMenuNotExist(String contextMenu){
130 Assert.assertFalse(GeneralUIUtils.isWebElementExistByTestId(contextMenu), "context menu should not appear");
133 public void checkNodesVisible(String[] children, boolean shouldExist) {
134 checkElements(ImmutableList.copyOf(children),
135 childName -> GeneralUIUtils.isWebElementExistByTestId(Constants.DrawingBoard.NODE_PREFIX + childName) ? "exists" : "absent",
136 shouldExist ? "exists" : "absent", "visibility");
139 public void checkNodesHighlighted(String[] children) {
140 checkElements(ImmutableList.copyOf(children),
142 final WebElement webElement = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + childName);
143 final String color = webElement.getCssValue("color");
146 HIGHLIGHTED_COLOR, "highlightning");
149 public void checkNodesVisibleAndMatchIsHighlighted(String searchString, String... children) {
150 checkElements(ImmutableList.copyOf(children),
152 final WebElement webElement = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + childName);
153 String visible = webElement.isDisplayed() ? "visible" : "hidden";
154 String highlightedText;
157 final WebElement highlighted = webElement.findElement(By.cssSelector(".highlight"));
158 highlightedText = highlighted.getText();
159 bgColor = highlighted.getCssValue("background-color");
160 } catch (NoSuchElementException e) {
161 highlightedText = "";
164 return String.join("", visible, " and '", highlightedText, "' in ", bgColor);
166 "visible and '" + searchString + "' in rgb(157, 217, 239)", "match highlightning");
169 private void checkElements(Collection<String> elements, Function<String, String> predicate, String expected, final String description) {
170 final Map<String, String> expectedMap = elements.stream().collect(Collectors.toMap(
171 childName -> childName,
174 final Map<String, String> actual = elements.stream().collect(Collectors.toMap(
175 childName -> childName,
179 assertThat("There was an error in " + description + " of elements", actual, equalTo(expectedMap));
182 public void navigateToServicePlanningPage() {
183 navigateTo("/vid/app/ui/#/servicePlanning");
186 public void navigateToEmptyServicePlanningPage() {
187 navigateTo("/vid/app/ui/#/servicePlanningEmpty");
190 public void checkContextMenu(String node){
191 String contextMenuButton = Constants.DrawingBoard.NODE_PREFIX + node + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
192 final String contextMenu = Constants.DrawingBoard.CONTEXT_MENU_ITEM;
194 checkThatPseudoElementNotExist(contextMenuButton);
195 checkThatContextMenuNotExist(contextMenu);
197 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + node);
198 checkThatPseudoElementExist(contextMenuButton);
199 Click.byTestId(contextMenuButton);
201 checkThatContextMenuExist(contextMenu);
204 public void checkSearch(){
205 String searchElement = Constants.DrawingBoard.SEARCH_LEFT_TREE;// TODO - should add that it is on the left tree and should create the id of the search element???
206 Assert.assertTrue(GeneralUIUtils.isWebElementExistByTestId(searchElement), "search " + searchElement + " should exist");
209 public void showTooltipByHoverAboveAlertIcon(String element){
210 assertThat("tooltip should not appear before click",
211 GeneralUIUtils.getDriver().findElements(By.xpath("//*[contains(@class, '" + "tooltip-inner" + "')]")),
215 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + element + Constants.DrawingBoard.ALERT_ICON);
217 final WebElement webElement = GeneralUIUtils.getWebElementByContainsClassName("tooltip-inner");
218 assertThat(webElement.getText(), is("Missing required information. Please open and fill in the details."));
221 public void clickDeployButton(){
222 GeneralUIUtils.ultimateWait();
225 GeneralUIUtils.clickOnElementByTestId(DEPLOY_BUTTON);
226 } catch (org.openqa.selenium.WebDriverException e) {
227 // "deploy" replaces the iframe, so "TypeError: can't access dead object" exception is eventually thrown
228 if (!e.getMessage().startsWith("TypeError: can't access dead object")) {
235 public void checkDeployButtonDisabled(){
236 Assert.assertFalse(Get.byTestId(DEPLOY_BUTTON).isEnabled(),"Deploy button is enabled and should be disabled");
239 public void checkExistsAndEnabled(String dataTestId){
240 Assert.assertFalse(GeneralUIUtils.isElementDisabled(dataTestId),"Element " + dataTestId + " should exist and be enabled");
243 public void checkServiceInstanceName(String expectedServiceName){
244 Assert.assertEquals(SERVICE_INSTANCE_VALUE, Get.byTestId(SERVICE_INSTANCE_TEST_ID).getText());
245 Assert.assertEquals(Get.byTestId(SERVICE_NAME).getText(),expectedServiceName);
248 public void checkServiceStatus() {
249 Assert.assertEquals(Get.byTestId(SERVICE_STATUS).getText(),STATUS_TEXT);
252 public void checkQuantityNumberIsCorrect(int expectedQuantity) {
253 Assert.assertEquals(Get.byTestId(QUANTITY_LABEL_TEST_ID).getText(), (String.valueOf(QUANTITY_LABEL_VALUE)));
254 Assert.assertEquals(Get.byTestId(SERVICE_QUANTITY).getText(), (String.valueOf(expectedQuantity)));