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 / ResourceWorkspaceTopBarComponent.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 package org.onap.sdc.frontend.ci.tests.pages;
20
21 import lombok.AllArgsConstructor;
22 import lombok.Getter;
23 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
24 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
25 import org.openqa.selenium.By;
26 import org.openqa.selenium.WebDriver;
27 import org.openqa.selenium.WebElement;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * Represents the top bar component of the a resource workspace, which contains the resource version, status, progress bar, and some action buttons.
33  */
34 public class ResourceWorkspaceTopBarComponent extends AbstractPageObject {
35
36     private static final Logger LOGGER = LoggerFactory.getLogger(ResourceWorkspaceTopBarComponent.class);
37
38     private final NotificationComponent notificationComponent;
39
40     private WebElement wrappingElement;
41     private WebElement lifecycleStateDiv;
42     private WebElement versionContainerDiv;
43     private WebElement actionButtonsDiv;
44
45     public ResourceWorkspaceTopBarComponent(final WebDriver webDriver) {
46         super(webDriver);
47         notificationComponent = new NotificationComponent(webDriver);
48     }
49
50     @Override
51     public void isLoaded() {
52         LOGGER.debug("Waiting for element visibility with xpath '{}'", XpathSelector.MAIN_DIV.getXpath());
53         wrappingElement = waitForElementVisibility(By.xpath(XpathSelector.MAIN_DIV.getXpath()), 5);
54         lifecycleStateDiv = wrappingElement.findElement(By.xpath(XpathSelector.LIFECYCLE_STATE_DIV.getXpath()));
55         versionContainerDiv = wrappingElement.findElement(By.xpath(XpathSelector.VERSION_CONTAINER_DIV.getXpath()));
56         actionButtonsDiv = wrappingElement.findElement(By.xpath(XpathSelector.ACTION_BUTTON_DIV.getXpath()));
57     }
58
59     public void clickOnCreate() {
60         waitToBeClickable(XpathSelector.CREATE_BTN.getXpath()).click();
61     }
62
63     public ComponentCertificationModal clickOnCertify() {
64         waitToBeClickable(XpathSelector.CERTIFY_BTN.getXpath()).click();
65         return new ComponentCertificationModal(webDriver);
66     }
67
68     /**
69      * Certify the resource and wait for success notification.
70      */
71     public void certifyResource() {
72         final ComponentCertificationModal componentCertificationModal = clickOnCertify();
73         componentCertificationModal.isLoaded();
74         componentCertificationModal.fillComment("Certifying for the UI Integration Test");
75         componentCertificationModal.clickOnOkButton();
76         notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
77     }
78
79     public String getLifecycleState() {
80         return lifecycleStateDiv.findElement(By.xpath(XpathSelector.FORM_LIFE_CYCLE_STATE.getXpath())).getText();
81     }
82
83     /**
84      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
85      */
86     @AllArgsConstructor
87     private enum XpathSelector {
88         MAIN_DIV("sdc-workspace-top-bar", "//div[@class='%s']"),
89         LIFECYCLE_STATE_DIV("lifecycle-state", "//div[@class='%s']"),
90         VERSION_CONTAINER_DIV("version-container", "//div[@class='%s']"),
91         ACTION_BUTTON_DIV("sdc-workspace-top-bar-buttons", "//div[@class='%s']"),
92         CREATE_BTN("create/save", "//button[@data-tests-id='%s']"),
93         CERTIFY_BTN("certify", "//button[@data-tests-id='%s']"),
94         FORM_LIFE_CYCLE_STATE("formlifecyclestate", "//span[@data-tests-id='%s']");
95
96         @Getter
97         private final String id;
98         private final String xpathFormat;
99
100         public String getXpath() {
101             return String.format(xpathFormat, id);
102         }
103
104     }
105 }