1 package vid.automation.test.sections;
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.Sets;
5 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
6 import org.openqa.selenium.By;
7 import org.openqa.selenium.JavascriptExecutor;
8 import org.openqa.selenium.NoSuchElementException;
9 import org.openqa.selenium.WebElement;
10 import org.testng.Assert;
11 import vid.automation.test.Constants;
12 import vid.automation.test.infra.Click;
13 import vid.automation.test.infra.Get;
14 import vid.automation.test.infra.Wait;
17 import java.util.function.Function;
18 import java.util.function.Predicate;
19 import java.util.stream.Collectors;
21 import static org.hamcrest.CoreMatchers.equalTo;
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.collection.IsEmptyCollection.empty;
25 import static vid.automation.test.Constants.DrawingBoard.*;
27 public class DrawingBoardPage extends VidBasePage {
29 public DrawingBoardPage(){
33 public void expandTreeByClickingNode(String nodeName, String... children) {
34 checkNodesVisible(children, false);
36 checkNodesVisible(children, true);
39 public void clickNode(String nodeName) {
40 Click.byTestId(Constants.DrawingBoard.NODE_PREFIX + nodeName);
43 public void expandFirstItemInTreeByExpanderIcon(String treeDataTestId, String... children) {
44 checkNodesVisible(children, false);
45 Click.byXpath("//tree-root[@data-tests-id='" + treeDataTestId + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
46 checkNodesVisible(children, true);
49 public void checkLeafNodeHasNoExpander(String nodeName){
50 WebElement webElement = Get.byXpath("//div[contains(@class, '" + Constants.DrawingBoard.TREE_NODE_LEAF + "') and .//div[@data-tests-id='" + Constants.DrawingBoard.NODE_PREFIX + nodeName + "']]");
51 Assert.assertNotNull(webElement, "There is an expander to node " + nodeName + " without children");
54 public void verifyNonCollapsableTreeByClickingNode(String nodeName, String... children) {
55 checkNodesVisible(children, true);
57 checkNodesVisible(children, true);
60 public void collapseFirstItemInTreeByCollapseIcon(String treeDataTestId, String... children) {
61 checkNodesVisible(children, true);
62 Click.byXpath("//tree-root[@data-tests-id='" + treeDataTestId + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
63 checkNodesVisible(children, false);
66 public void RefreshPage(){
67 GeneralUIUtils.getDriver().navigate().refresh();
70 public void assertInitalTextOfTree(String treeDataTestId, String[] initialElements) {
71 WebElement webElement = Get.byTestId(treeDataTestId);
72 String expected = String.join("\n", initialElements);
73 Wait.byText(expected);
74 Assert.assertEquals(webElement.getText(), expected);
77 public void checkAddButton(String[] rootElements){
78 String previousAddButton = null;
79 for (String root : rootElements) {
80 String currentButton = Constants.DrawingBoard.NODE_PREFIX + root + Constants.DrawingBoard.ADD_BUTTON;
81 checkThatButtonNotExist(currentButton);
82 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + root);
83 checkThatButtonExist(currentButton);
84 if (previousAddButton != null) {
85 checkThatButtonNotExist(previousAddButton);
87 Click.byTestId(currentButton);
88 previousAddButton = currentButton;
92 public void clickAddButtonByNodeName(String treeNodeId) {
93 String nodeElement = "node-"+ treeNodeId;
94 String addButtonTestId = Constants.DrawingBoard.NODE_PREFIX + treeNodeId + Constants.DrawingBoard.ADD_BUTTON;
95 GeneralUIUtils.hoverOnAreaByTestId(nodeElement);
96 GeneralUIUtils.hoverOnAreaByTestId(addButtonTestId);
97 Click.byTestId(addButtonTestId);
100 private void checkThatButtonNotExist(String dataTestId){
101 // Assert.assertFalse(GeneralUIUtils.isElementVisibleByTestId(dataTestId),"button " + dataTestId + " should not exist");
104 private void checkThatButtonExist(String dataTestId){
105 // Assert.assertTrue(GeneralUIUtils.isElementVisibleByTestId(dataTestId), "button " + dataTestId + " should exist");
108 private void checkThatPseudoElementNotExist(String dataTestId) {
109 assertPseudoElementDisplayProp(dataTestId, "none");
112 private void assertPseudoElementDisplayProp(String dataTestId, String expectedCssDisplayProp){
113 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
114 final Object cssDisplayProp = javascriptExecutor.executeScript("" +
115 "return window.getComputedStyle(" +
116 " document.querySelector('[data-tests-id=\""+dataTestId+"\"]'),':before'" +
117 ").getPropertyValue('display')"
119 assertThat("button " + dataTestId + " should exist", cssDisplayProp, is(expectedCssDisplayProp));
122 private void checkThatPseudoElementExist(String dataTestId) {
123 assertPseudoElementDisplayProp(dataTestId, "inline-block");
126 public void checkThatContextMenuExist(String contextMenu){
127 Assert.assertTrue(GeneralUIUtils.isWebElementExistByTestId(contextMenu), "context menu should appear");
130 public void checkThatContextMenuNotExist(String contextMenu){
131 Assert.assertFalse(GeneralUIUtils.isWebElementExistByTestId(contextMenu), "context menu should not appear");
134 public void checkNodesVisible(String[] children, boolean shouldExist) {
135 checkElements(ImmutableList.copyOf(children),
136 childName -> GeneralUIUtils.isWebElementExistByTestId(Constants.DrawingBoard.NODE_PREFIX + childName) ? "exists" : "absent",
137 shouldExist ? "exists" : "absent", "visibility");
140 public void checkNodesHighlighted(String[] children) {
141 checkElements(ImmutableList.copyOf(children),
143 final WebElement webElement = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + childName);
144 final String color = webElement.getCssValue("color");
147 HIGHLIGHTED_COLOR, "highlightning");
150 public void checkNodesVisibleAndMatchIsHighlighted(String searchString, String... children) {
151 checkElements(ImmutableList.copyOf(children),
153 final WebElement webElement = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + childName);
154 String visible = webElement.isDisplayed() ? "visible" : "hidden";
155 String highlightedText;
158 final WebElement highlighted = webElement.findElement(By.cssSelector(".highlight"));
159 highlightedText = highlighted.getText();
160 bgColor = highlighted.getCssValue("background-color");
161 } catch (NoSuchElementException e) {
162 highlightedText = "";
165 return String.join("", visible, " and '", highlightedText, "' in ", bgColor);
167 "visible and '" + searchString + "' in rgb(157, 217, 239)", "match highlightning");
170 private void checkElements(Collection<String> elements, Function<String, String> predicate, String expected, final String description) {
171 final Map<String, String> expectedMap = elements.stream().collect(Collectors.toMap(
172 childName -> childName,
175 final Map<String, String> actual = elements.stream().collect(Collectors.toMap(
176 childName -> childName,
180 assertThat("There was an error in " + description + " of elements", actual, equalTo(expectedMap));
183 public void navigateToServicePlanningPage() {
184 navigateTo("/vid/app/ui/#/servicePlanning");
187 public void navigateToEmptyServicePlanningPage() {
188 navigateTo("/vid/app/ui/#/servicePlanningEmpty");
191 public void checkContextMenu(String node){
192 String contextMenuButton = Constants.DrawingBoard.NODE_PREFIX + node + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
193 final String contextMenu = Constants.DrawingBoard.CONTEXT_MENU_EDIT;
195 checkThatPseudoElementNotExist(contextMenuButton);
196 checkThatContextMenuNotExist(contextMenu);
198 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + node);
199 checkThatPseudoElementExist(contextMenuButton);
200 Click.byTestId(contextMenuButton);
202 checkThatContextMenuExist(contextMenu);
205 public void checkSearch(){
206 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???
207 Assert.assertTrue(GeneralUIUtils.isWebElementExistByTestId(searchElement), "search " + searchElement + " should exist");
210 public void showTooltipByHoverAboveAlertIcon(String element){
211 assertThat("tooltip should not appear before click",
212 GeneralUIUtils.getDriver().findElements(By.xpath("//*[contains(@class, '" + "tooltip-inner" + "')]")),
216 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + element + Constants.DrawingBoard.ALERT_ICON);
218 final WebElement webElement = GeneralUIUtils.getWebElementByContainsClassName("tooltip-inner");
219 assertThat(webElement.getText(), is("Missing required information. Please open and fill in the details."));
222 public void clickDeployButton(){
223 GeneralUIUtils.ultimateWait();
226 GeneralUIUtils.clickOnElementByTestId(DEPLOY_BUTTON);
227 } catch (org.openqa.selenium.WebDriverException e) {
228 // "deploy" replaces the iframe, so "TypeError: can't access dead object" exception is eventually thrown
229 if (!e.getMessage().startsWith("TypeError: can't access dead object")) {
236 public void checkDeployButtonDisabled(){
237 Assert.assertFalse(Get.byTestId(DEPLOY_BUTTON).isEnabled(),"Deploy button is enabled and should be disabled");
240 public void checkExistsAndEnabled(String dataTestId){
241 Assert.assertFalse(GeneralUIUtils.isElementDisabled(dataTestId),"Element " + dataTestId + " should exist and be enabled");
244 public void checkServiceInstanceName(String expectedServiceName){
245 Assert.assertEquals(SERVICE_INSTANCE_VALUE, Get.byTestId(SERVICE_INSTANCE_TEST_ID).getText());
246 Assert.assertEquals(Get.byTestId(SERVICE_NAME).getText(),expectedServiceName);
249 public void checkServiceStatus() {
250 Assert.assertEquals(Get.byTestId(SERVICE_STATUS).getText(),STATUS_TEXT);
253 public void checkQuantityNumberIsCorrect(int expectedQuantity) {
254 Assert.assertEquals(Get.byTestId(QUANTITY_LABEL_TEST_ID).getText(), (String.valueOf(QUANTITY_LABEL_VALUE)));
255 Assert.assertEquals(Get.byTestId(SERVICE_QUANTITY).getText(), (String.valueOf(expectedQuantity)));
258 public static class ServiceStatusChecker implements Predicate<Boolean> {
259 private String actualInstanceName;
260 private Set<String> expectedStatuses;
261 private Set<String> columnClassesSet;
263 public ServiceStatusChecker(String actualInstanceName, Set<String> expectedStatuses) {
264 this.actualInstanceName = actualInstanceName;
265 this.expectedStatuses = expectedStatuses;
269 public boolean test(Boolean noMeaning) {
270 InstantiationStatusPage.clickRefreshButton();
271 final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
273 System.err.println("**********************" + actualInstanceName + "************************************************");
274 columnClassesSet = Collections.singleton(actualInstanceName + " NOT FOUND");
275 return false; // treat missing row as if test condition not fulfilled
277 columnClassesSet = new HashSet<>(Arrays.asList(
278 row.findElements(By.xpath(".//*[@id='" + "jobStatus" + "']")).get(0).getAttribute("class").split(" ")));
279 return !(Sets.intersection(expectedStatuses, columnClassesSet).isEmpty());
283 public Set<String> getColumnClassesSet() {
284 return columnClassesSet;