942c32a5db4fbeb70a59d3e14c3a90dd7b2d4426
[sdc.git] /
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.openqa.selenium.By;
24 import org.openqa.selenium.WebDriver;
25 import org.openqa.selenium.WebElement;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * Represents the top bar component of the a resource workspace, which contains the resource version, status, progress bar, and some action buttons.
31  */
32 public class ResourceWorkspaceTopBarComponent extends AbstractPageObject {
33
34     private static final Logger LOGGER = LoggerFactory.getLogger(ResourceWorkspaceTopBarComponent.class);
35
36     private WebElement wrappingElement;
37     private WebElement lifecycleStateDiv;
38     private WebElement versionContainerDiv;
39     private WebElement actionButtonsDiv;
40
41     public ResourceWorkspaceTopBarComponent(final WebDriver webDriver) {
42         super(webDriver);
43     }
44
45     @Override
46     public void isLoaded() {
47         LOGGER.debug("Waiting for element visibility with xpath '{}'", XpathSelector.MAIN_DIV.getXpath());
48         wrappingElement = waitForElementVisibility(By.xpath(XpathSelector.MAIN_DIV.getXpath()), 5);
49         lifecycleStateDiv = wrappingElement.findElement(By.xpath(XpathSelector.LIFECYCLE_STATE_DIV.getXpath()));
50         versionContainerDiv = wrappingElement.findElement(By.xpath(XpathSelector.VERSION_CONTAINER_DIV.getXpath()));
51         actionButtonsDiv = wrappingElement.findElement(By.xpath(XpathSelector.ACTION_BUTTON_DIV.getXpath()));
52     }
53
54     public void clickOnCreate() {
55         waitToBeClickable(XpathSelector.CREATE_BTN.getXpath()).click();
56     }
57
58     public void clickOnCertify() {
59         waitToBeClickable(XpathSelector.CERTIFY_BTN.getXpath()).click();
60     }
61
62     public String getLifecycleState() {
63         return lifecycleStateDiv.findElement(By.xpath(XpathSelector.FORM_LIFE_CYCLE_STATE.getXpath())).getText();
64     }
65
66     /**
67      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
68      */
69     @AllArgsConstructor
70     private enum XpathSelector {
71         MAIN_DIV("sdc-workspace-top-bar", "//div[@class='%s']"),
72         LIFECYCLE_STATE_DIV("lifecycle-state", "//div[@class='%s']"),
73         VERSION_CONTAINER_DIV("version-container", "//div[@class='%s']"),
74         ACTION_BUTTON_DIV("sdc-workspace-top-bar-buttons", "//div[@class='%s']"),
75         CREATE_BTN("create/save", "//button[@data-tests-id='%s']"),
76         CERTIFY_BTN("certify", "//button[@data-tests-id='%s']"),
77         FORM_LIFE_CYCLE_STATE("formlifecyclestate", "//span[@data-tests-id='%s']");
78
79         @Getter
80         private final String id;
81         private final String xpathFormat;
82
83         public String getXpath() {
84             return String.format(xpathFormat, id);
85         }
86
87     }
88 }