Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / AttributesOutputsPage.java
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages;
21
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import com.aventstack.extentreports.Status;
25 import lombok.AllArgsConstructor;
26 import lombok.Getter;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionHierarchyComponent;
29 import org.openqa.selenium.By;
30 import org.openqa.selenium.WebDriver;
31
32 /**
33  * Handles the 'Attributes & Outputs' Page UI actions
34  */
35 public class AttributesOutputsPage extends ComponentPage {
36
37     private final AttributesTabComponent attributesTabComponent;
38     private final OutputsTabComponent outputsTabComponent;
39     private final CompositionHierarchyComponent compositionHierarchyComponent;
40
41     public AttributesOutputsPage(final WebDriver webDriver) {
42         super(webDriver);
43         attributesTabComponent = new AttributesTabComponent(webDriver);
44         outputsTabComponent = new OutputsTabComponent(webDriver);
45         compositionHierarchyComponent = new CompositionHierarchyComponent(webDriver);
46         setTimeout(5);
47     }
48
49     @Override
50     public void isLoaded() {
51         super.isLoaded();
52         waitForElementVisibility(By.xpath(XpathSelector.MAIN_DIV.getXpath()));
53         waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()));
54         attributesTabComponent.isLoaded();
55         compositionHierarchyComponent.isLoaded();
56     }
57
58     public void clickOnAttributeNavigation(final String id) {
59         compositionHierarchyComponent.clickOnAttributeNavigation(id);
60         assertTrue(attributesTabComponent.isInstanceSelected(id));
61     }
62
63     /**
64      * Checks if a attribute exists.
65      *
66      * @return true if exists, false if not
67      */
68     public boolean isAttributePresent(final String attributeName) {
69         ExtentTestActions.log(Status.INFO, "Going to check if Attribute '" + attributeName + "' is present");
70         return attributesTabComponent.isAttributePresent(attributeName);
71     }
72
73     /**
74      * Checks if a output exists.
75      *
76      * @return true if exists, false if not
77      */
78     public boolean isOutputPresent(final String outputName) {
79         ExtentTestActions.log(Status.INFO, "Going to check if Output '" + outputName + "' is present");
80         return outputsTabComponent.isOutputPresent(outputName);
81     }
82
83     /**
84      * Checks if a output deleted.
85      *
86      * @return true if deleted, false if not
87      */
88     public boolean isOutputDeleted(final String outputName) {
89         ExtentTestActions.log(Status.INFO, "Going to check if Output '" + outputName + "' deleted");
90         return outputsTabComponent.isOutputDeleted(outputName);
91     }
92
93     public void declareOutput(final String attributeName) {
94         ExtentTestActions.log(Status.INFO, "Going to declare Attribute '" + attributeName + "' as Output");
95         attributesTabComponent.declareOutput(attributeName);
96     }
97
98     public void deleteOutput(final String outputName) {
99         ExtentTestActions.log(Status.INFO, "Going to delete Output '" + outputName + "'");
100         outputsTabComponent.deleteOutput(outputName);
101     }
102
103     public void clickOnOutputsTab() {
104         waitForElementVisibility(By.xpath(XpathSelector.OUTPUTS_TAB.getXpath())).click();
105         outputsTabComponent.isLoaded();
106     }
107
108     public void clickOnAttributesTab() {
109         waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_TAB.getXpath())).click();
110         attributesTabComponent.isLoaded();
111     }
112
113     /**
114      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
115      */
116     @AllArgsConstructor
117     private enum XpathSelector {
118         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
119         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Attributes & Outputs')]"),
120         ATTRIBUTES_TAB("Attributes", "//*[@data-tests-id='%s']"),
121         OUTPUTS_TAB("Outputs", "//*[@data-tests-id='%s']");
122
123         @Getter
124         private final String id;
125         private final String xpathFormat;
126
127         public String getXpath() {
128             return String.format(xpathFormat, id);
129         }
130
131     }
132
133 }