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.List;
23 import java.util.stream.Collectors;
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 select web element
52 * @param type which directive type to select from options
54 public void selectDirective(final DirectiveType type) {
55 final Select directiveSelect = getDirectiveSelect();
56 directiveSelect.selectByVisibleText(type.getName());
60 * Returns a ServiceDependenciesEditor when the add node filter button is clicked
62 * @param index an index indicating which add node filter button to click
63 * @return a new ServiceDependenciesEditor component instance
65 public ServiceDependenciesEditor clickAddNodeFilter(final int index) {
66 waitForElementVisibility(By.xpath(XpathSelector.ADD_RULE_BUTTON.formatXPath(index))).click();
67 return new ServiceDependenciesEditor(webDriver);
71 * Verify a rule has been created
73 * @param propertyName name of the created rule
74 * @return true if the rule is present on screen otherwise false
76 public boolean isRulePresent(final String propertyName) {
78 return waitForElementVisibility(By.xpath(XpathSelector.RULE_DESC.formatXPath(propertyName))) != null;
79 } catch (final Exception ignored) {
85 * Return all available directive types from the directive select web element
87 * @return list of strings in lower case based on visible text of the select's web element options.
88 * The List values should correspond to {@link DirectiveType}
90 public List<String> getDirectiveSelectOptions() {
91 final Select directiveSelect = getDirectiveSelect();
92 final List<String> directiveOptions = directiveSelect.getOptions().stream()
93 .map(option -> option.getText().toLowerCase()).collect(Collectors.toList());
94 directiveOptions.remove("select directive");
95 return directiveOptions;
99 * Verify a directive has been selected
101 * @param type which directive type to verify
102 * @return true if the directive type is selected on screen otherwise false
104 public boolean isDirectiveSelected(final DirectiveType type) {
106 return waitForElementVisibility(
107 By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_SELECTED
108 .formatXPath(type.getName().toUpperCase())), 2) != null;
109 } catch (final Exception ignored) {
114 private Select getDirectiveSelect() {
115 return new Select(findElement(By.xpath(XpathSelector.NODE_FILTER_DIRECTIVE_SELECT.xPath)));
120 private enum XpathSelector {
121 NODE_FILTER_TAB("//service-dependencies-tab"),
122 NODE_FILTER_DIRECTIVE_SELECT("//select[@id='singleSelect']"),
123 NODE_FILTER_DIRECTIVE_SELECTED("//label[contains(text(),': %s')]"),
124 ADD_RULE_BUTTON("(//*[@data-tests-id='add-rule-button'])[%d]"),
125 RULE_DESC("//*[contains(text(),'%s')]");
127 private final String xPath;
129 public String formatXPath(Object value) {
130 return String.format(xPath, value);