2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.onap.sdc.frontend.ci.tests.datatypes.DirectiveType;
26 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
27 import org.onap.sdc.frontend.ci.tests.pages.ServiceDependenciesEditor;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebDriver;
30 import org.openqa.selenium.support.ui.Select;
32 import lombok.AllArgsConstructor;
36 * Represents the composition page, details panel, Directives and Node Filters tab
38 public class CompositionDirectiveNodeFilterTab extends AbstractPageObject {
40 public CompositionDirectiveNodeFilterTab(final WebDriver webDriver) {
45 public void isLoaded() {
46 waitForElementVisibility(By.xpath(XpathSelector.NODE_FILTER_TAB.xPath));
50 * Select option from the directive ng-select web element
53 public void selectDirective() {
54 waitToBeClickable(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_DROPDOWN.getXPath())).click();
55 waitToBeClickable(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_OPTIONS_SELECTABLE.getXPath())).click();
56 saveDirectivesSelected();
59 * Select multiple options from the directive ng-select web element
62 public void updateDirectives() {
63 waitToBeClickable(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_EDIT_BTN.getXPath())).click();
64 waitToBeClickable(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_DROPDOWN.getXPath())).click();
65 waitToBeClickable(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_OPTIONS_SUBSTITUTABLE.getXPath())).click();
66 saveDirectivesSelected();
70 * Returns a ServiceDependenciesEditor when the add node filter button is clicked
72 * @param index an index indicating which add node filter button to click
73 * @return a new ServiceDependenciesEditor component instance
75 public ServiceDependenciesEditor clickAddNodeFilter(final int index) {
76 waitForElementInvisibility(By.xpath(XpathSelector.LOADER_HELPER.getXPath()));
77 waitForElementVisibility(By.xpath(XpathSelector.ADD_RULE_BUTTON.formatXPath(index))).click();
78 return new ServiceDependenciesEditor(webDriver);
82 * Verify a rule has been created
84 * @param propertyName name of the created rule
85 * @return true if the rule is present on screen otherwise false
87 public boolean isRulePresent(final String propertyName) {
89 return waitForElementVisibility(By.xpath(XpathSelector.RULE_DESC.formatXPath(propertyName))) != null;
90 } catch (final Exception ignored) {
96 * Return all available directive types from the directive ng-select web element
98 * @return list of strings in lower case based on visible text of the ng-select's web element options.
99 * The List values should correspond to {@link DirectiveType}
101 public List<String> getDirectiveSelectOptions() {
102 final List<String> directiveOptions = new ArrayList<>();
103 directiveOptions.add(DirectiveType.SELECT.getName());
104 directiveOptions.add(DirectiveType.SELECTABLE.getName());
105 directiveOptions.add(DirectiveType.SUBSTITUTE.getName());
106 directiveOptions.add(DirectiveType.SUBSTITUTABLE.getName());
107 return directiveOptions;
111 * Verify a directive has been selected
113 * @param type which directive type to verify
114 * @return true if the directive type is selected on screen otherwise false
116 public boolean isDirectiveSelected(final DirectiveType type) {
118 return waitForElementVisibility(
119 By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_SELECTED
120 .formatXPath(type.getName().toUpperCase())), 2) != null;
121 } catch (final Exception ignored) {
126 private Select getDirectiveSelect() {
127 return new Select(findElement(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_SELECT.xPath)));
130 private void saveDirectivesSelected() {
131 waitToBeClickable(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_APPLY_BTN.formatXPath("Apply"))).click();
136 private enum XpathSelector {
137 NODE_FILTER_TAB("//service-dependencies-tab"),
138 NODE_FILTER_DIRECTIVE_DROPDOWN("//div[@class='select-directives']//div[@class='ng-input']"),
139 NODE_FILTER_DIRECTIVE_SELECT("//select[@id='singleSelect']"),
140 NODE_FILTER_DIRECTIVE_SELECTED("//label[contains(text(),': %s')]"),
141 NODE_FILTER_DIRECTIVE_OPTIONS_SELECTABLE("//div[@class='select-directives']//*[contains(text(), 'selectable')]"),
142 NODE_FILTER_DIRECTIVE_APPLY_BTN("//*[@id=\"multi-select-apply\"]"),
143 NODE_FILTER_DIRECTIVE_EDIT_BTN("//*[@data-tests-id='directive-edit-icon']"),
144 NODE_FILTER_DIRECTIVE_OPTIONS_SUBSTITUTABLE("//div[@class='select-directives']//*[contains(text(), 'substitutable')]"),
145 ADD_RULE_BUTTON("(//*[@data-tests-id='add-rule-button'])[%d]"),
146 RULE_DESC("//*[contains(text(),'%s')]"),
147 LOADER_HELPER("//div[@class='tlv-loader-back tlv-loader-relative']");
149 private final String xPath;
151 public String formatXPath(Object value) {
152 return String.format(xPath, value);