1 package vid.automation.test.sections;
3 import static org.hamcrest.CoreMatchers.equalTo;
4 import static org.hamcrest.CoreMatchers.is;
5 import static org.hamcrest.MatcherAssert.assertThat;
6 import static org.hamcrest.collection.IsEmptyCollection.empty;
7 import static org.testng.AssertJUnit.assertTrue;
8 import static vid.automation.test.Constants.DrawingBoard.DEPLOY_BUTTON;
9 import static vid.automation.test.Constants.DrawingBoard.HIGHLIGHTED_COLOR;
10 import static vid.automation.test.Constants.DrawingBoard.QUANTITY_LABEL_TEST_ID;
11 import static vid.automation.test.Constants.DrawingBoard.QUANTITY_LABEL_VALUE;
12 import static vid.automation.test.Constants.DrawingBoard.SERVICE_INSTANCE_TEST_ID;
13 import static vid.automation.test.Constants.DrawingBoard.SERVICE_INSTANCE_VALUE;
14 import static vid.automation.test.Constants.DrawingBoard.SERVICE_NAME;
15 import static vid.automation.test.Constants.DrawingBoard.SERVICE_QUANTITY;
16 import static vid.automation.test.Constants.DrawingBoard.SERVICE_STATUS;
17 import static vid.automation.test.Constants.DrawingBoard.STATUS_TEXT;
19 import com.google.common.collect.ImmutableList;
20 import com.google.common.collect.Sets;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.HashSet;
27 import java.util.function.Function;
28 import java.util.function.Predicate;
29 import java.util.stream.Collectors;
30 import org.apache.logging.log4j.LogManager;
31 import org.apache.logging.log4j.Logger;
32 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
33 import org.openqa.selenium.By;
34 import org.openqa.selenium.JavascriptExecutor;
35 import org.openqa.selenium.NoSuchElementException;
36 import org.openqa.selenium.WebElement;
37 import org.testng.Assert;
38 import vid.automation.test.Constants;
39 import vid.automation.test.infra.Click;
40 import vid.automation.test.infra.Get;
41 import vid.automation.test.infra.Wait;
42 import vid.automation.test.test.NewServiceInstanceTest;
44 public class DrawingBoardPage extends VidBasePage {
46 private static final Logger logger = LogManager.getLogger(DrawingBoardPage.class);
48 public DrawingBoardPage(){
52 public void expandTreeByClickingNode(String nodeName, String... children) {
53 checkNodesVisible(children, false);
55 checkNodesVisible(children, true);
58 public void clickNode(String nodeName) {
59 Click.byTestId(Constants.DrawingBoard.NODE_PREFIX + nodeName);
62 public void expandFirstItemInTreeByExpanderIcon(String treeDataTestId, String... children) {
63 checkNodesVisible(children, false);
64 Click.byXpath("//tree-root[@data-tests-id='" + treeDataTestId + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
65 checkNodesVisible(children, true);
68 public void checkLeafNodeHasNoExpander(String nodeName){
69 WebElement webElement = Get.byXpath("//div[contains(@class, '" + Constants.DrawingBoard.TREE_NODE_LEAF + "') and .//div[@data-tests-id='" + Constants.DrawingBoard.NODE_PREFIX + nodeName + "']]");
70 Assert.assertNotNull(webElement, "There is an expander to node " + nodeName + " without children");
73 public void verifyNonCollapsableTreeByClickingNode(String nodeName, String... children) {
74 checkNodesVisible(children, true);
76 checkNodesVisible(children, true);
79 public void collapseFirstItemInTreeByCollapseIcon(String treeDataTestId, String... children) {
80 checkNodesVisible(children, true);
81 Click.byXpath("//tree-root[@data-tests-id='" + treeDataTestId + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
82 checkNodesVisible(children, false);
85 public void RefreshPage(){
86 GeneralUIUtils.getDriver().navigate().refresh();
89 public void assertInitalTextOfTree(String treeDataTestId, String[] initialElements) {
90 WebElement webElement = Get.byTestId(treeDataTestId);
91 String expected = String.join("\n", initialElements);
92 Wait.byText(expected);
93 Assert.assertEquals(webElement.getText(), expected);
96 public void checkAddButton(String[] rootElements){
97 String previousAddButton = null;
98 for (String root : rootElements) {
99 String currentButton = Constants.DrawingBoard.NODE_PREFIX + root + Constants.DrawingBoard.ADD_BUTTON;
100 checkThatButtonNotExist(currentButton);
101 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + root);
102 checkThatButtonExist(currentButton);
103 if (previousAddButton != null) {
104 checkThatButtonNotExist(previousAddButton);
106 Click.byTestId(currentButton);
107 previousAddButton = currentButton;
111 public void clickAddButtonByNodeName(String treeNodeId) {
112 String nodeElement = "node-"+ treeNodeId;
113 String addButtonTestId = Constants.DrawingBoard.NODE_PREFIX + treeNodeId + Constants.DrawingBoard.ADD_BUTTON;
114 GeneralUIUtils.hoverOnAreaByTestId(nodeElement);
115 GeneralUIUtils.hoverOnAreaByTestId(addButtonTestId);
116 Click.byTestId(addButtonTestId);
119 private void checkThatButtonNotExist(String dataTestId){
120 // Assert.assertFalse(GeneralUIUtils.isElementVisibleByTestId(dataTestId),"button " + dataTestId + " should not exist");
123 private void checkThatButtonExist(String dataTestId){
124 // Assert.assertTrue(GeneralUIUtils.isElementVisibleByTestId(dataTestId), "button " + dataTestId + " should exist");
127 private void checkThatPseudoElementNotExist(String dataTestId) {
128 assertPseudoElementDisplayProp(dataTestId, "none");
131 private void assertPseudoElementDisplayProp(String dataTestId, String expectedCssDisplayProp){
132 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
133 final Object cssDisplayProp = javascriptExecutor.executeScript("" +
134 "return window.getComputedStyle(" +
135 " document.querySelector('[data-tests-id=\""+dataTestId+"\"]'),':before'" +
136 ").getPropertyValue('display')"
138 assertThat("button " + dataTestId + " should exist", cssDisplayProp, is(expectedCssDisplayProp));
141 private void checkThatPseudoElementExist(String dataTestId) {
142 assertPseudoElementDisplayProp(dataTestId, "inline-block");
145 public void checkThatContextMenuExist(String contextMenu){
146 Assert.assertTrue(GeneralUIUtils.isWebElementExistByTestId(contextMenu), "context menu should appear");
149 public void checkThatContextMenuNotExist(String contextMenu){
150 Assert.assertFalse(GeneralUIUtils.isWebElementExistByTestId(contextMenu), "context menu should not appear");
153 public void checkNodesVisible(String[] children, boolean shouldExist) {
154 checkElements(ImmutableList.copyOf(children),
155 childName -> GeneralUIUtils.isWebElementExistByTestId(Constants.DrawingBoard.NODE_PREFIX + childName) ? "exists" : "absent",
156 shouldExist ? "exists" : "absent", "visibility");
159 public void checkNodesHighlighted(String[] children) {
160 checkElements(ImmutableList.copyOf(children),
162 final WebElement webElement = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + childName);
163 final String color = webElement.getCssValue("color");
166 HIGHLIGHTED_COLOR, "highlightning");
169 public void checkNodesVisibleAndMatchIsHighlighted(String searchString, String... children) {
170 checkElements(ImmutableList.copyOf(children),
172 final WebElement webElement = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + childName);
173 String visible = webElement.isDisplayed() ? "visible" : "hidden";
174 String highlightedText;
177 final WebElement highlighted = webElement.findElement(By.cssSelector(".highlight"));
178 highlightedText = highlighted.getText();
179 bgColor = highlighted.getCssValue("background-color");
180 } catch (NoSuchElementException e) {
181 highlightedText = "";
184 return String.join("", visible, " and '", highlightedText, "' in ", bgColor);
186 "visible and '" + searchString + "' in rgb(157, 217, 239)", "match highlightning");
189 private void checkElements(Collection<String> elements, Function<String, String> predicate, String expected, final String description) {
190 final Map<String, String> expectedMap = elements.stream().collect(Collectors.toMap(
191 childName -> childName,
194 final Map<String, String> actual = elements.stream().collect(Collectors.toMap(
195 childName -> childName,
199 assertThat("There was an error in " + description + " of elements", actual, equalTo(expectedMap));
202 public void navigateToServicePlanningPage() {
203 navigateTo("/vid/app/ui/#/servicePlanning");
206 public void navigateToEmptyServicePlanningPage() {
207 navigateTo("/vid/app/ui/#/servicePlanningEmpty");
210 public void checkContextMenu(String node){
211 String contextMenuButton = Constants.DrawingBoard.NODE_PREFIX + node + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
212 final String contextMenu = Constants.DrawingBoard.CONTEXT_MENU_EDIT;
214 checkThatPseudoElementNotExist(contextMenuButton);
215 checkThatContextMenuNotExist(contextMenu);
217 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + node);
218 checkThatPseudoElementExist(contextMenuButton);
219 Click.byTestId(contextMenuButton);
221 checkThatContextMenuExist(contextMenu);
224 public void checkSearch(){
225 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???
226 Assert.assertTrue(GeneralUIUtils.isWebElementExistByTestId(searchElement), "search " + searchElement + " should exist");
229 public void showTooltipByHoverAboveAlertIcon(String element){
230 assertThat("tooltip should not appear before click",
231 GeneralUIUtils.getDriver().findElements(By.xpath("//*[contains(@class, '" + "tooltip-inner" + "')]")),
235 GeneralUIUtils.hoverOnAreaByTestId(Constants.DrawingBoard.NODE_PREFIX + element + Constants.DrawingBoard.ALERT_ICON);
237 final WebElement webElement = GeneralUIUtils.getWebElementByContainsClassName("tooltip-inner");
238 assertThat(webElement.getText(), is("Missing required information. Please open and fill in the details."));
241 private void clickDeployButton(){
242 GeneralUIUtils.ultimateWait();
245 GeneralUIUtils.clickOnElementByTestId(DEPLOY_BUTTON);
246 } catch (org.openqa.selenium.WebDriverException e) {
247 // "deploy" replaces the iframe, so "TypeError: can't access dead object" exception is eventually thrown
248 if (!e.getMessage().startsWith("TypeError: can't access dead object")) {
255 public void deploy() {
257 logger.info("Redux state before deploy:");
258 logger.info(getReduxState());
260 catch (Exception e) {
261 //do nothing just logging
265 VidBasePage.goOutFromIframe();
266 GeneralUIUtils.ultimateWait();
267 VidBasePage.goToIframe();
268 GeneralUIUtils.ultimateWait();
271 public void checkDeployButtonDisabled(){
272 Assert.assertFalse(Get.byTestId(DEPLOY_BUTTON).isEnabled(),"Deploy button is enabled and should be disabled");
275 public void checkExistsAndEnabled(String dataTestId){
276 Assert.assertFalse(GeneralUIUtils.isElementDisabled(dataTestId),"Element " + dataTestId + " should exist and be enabled");
279 public void checkServiceInstanceName(String expectedServiceName){
280 Assert.assertEquals(SERVICE_INSTANCE_VALUE, Get.byTestId(SERVICE_INSTANCE_TEST_ID).getText());
281 Assert.assertEquals(Get.byTestId(SERVICE_NAME).getText(),expectedServiceName);
284 public void checkServiceStatus() {
285 Assert.assertEquals(Get.byTestId(SERVICE_STATUS).getText(),STATUS_TEXT);
288 public void checkQuantityNumberIsCorrect(int expectedQuantity) {
289 Assert.assertEquals(Get.byTestId(QUANTITY_LABEL_TEST_ID).getText(), (String.valueOf(QUANTITY_LABEL_VALUE)));
290 Assert.assertEquals(Get.byTestId(SERVICE_QUANTITY).getText(), (String.valueOf(expectedQuantity)));
293 public static class ServiceStatusChecker implements Predicate<Boolean> {
294 private String uniqueText;
295 private Set<String> expectedStatuses;
296 private Set<String> columnClassesSet;
298 public ServiceStatusChecker(String uniqueText, Set<String> expectedStatuses) {
299 this.uniqueText = uniqueText;
300 this.expectedStatuses = expectedStatuses;
304 public boolean test(Boolean noMeaning) {
305 InstantiationStatusPage.clickRefreshButton();
306 final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(uniqueText);
308 System.err.println("**********************" + uniqueText + "************************************************");
309 columnClassesSet = Collections.singleton(uniqueText + " NOT FOUND");
310 return false; // treat missing row as if test condition not fulfilled
312 columnClassesSet = new HashSet<>(Arrays.asList(
313 row.findElements(By.xpath(".//*[@id='" + "jobStatus" + "']")).get(0).getAttribute("class").split(" ")));
314 return !(Sets.intersection(expectedStatuses, columnClassesSet).isEmpty());
318 public Set<String> getColumnClassesSet() {
319 return columnClassesSet;
323 public void verifyServiceCompletedOnTime(String uniqueStatusText, String nameToDisplay) {
324 DrawingBoardPage.ServiceStatusChecker serviceStatusChecker =
325 new DrawingBoardPage.ServiceStatusChecker(uniqueStatusText, Collections.singleton(NewServiceInstanceTest.COMPLETED));
326 boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 20, 2);
327 assertTrue(nameToDisplay + " wasn't completed in time", statusIsShown);
328 VidBasePage.goOutFromIframe();