Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / ResourceCreatePage.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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.openecomp.sdc.ci.tests.pages;
21
22 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
23 import org.openecomp.sdc.ci.tests.utilities.LoaderHelper;
24 import org.openecomp.sdc.ci.tests.utilities.NotificationHelper;
25 import org.openecomp.sdc.ci.tests.utilities.NotificationHelper.NotificationType;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
29 import org.openqa.selenium.support.ui.ExpectedConditions;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 import static org.hamcrest.Matchers.equalToIgnoringCase;
34 import static org.hamcrest.core.Is.is;
35 import static org.junit.Assert.assertThat;
36 import static org.openecomp.sdc.ci.tests.pages.ResourceCreatePage.XpathSelector.FORM_LIFE_CYCLE_STATE;
37
38 /**
39  * Handles the Resource Create Page UI actions
40  */
41 public class ResourceCreatePage extends AbstractPageObject {
42
43     private static final Logger LOGGER = LoggerFactory.getLogger(ResourceCreatePage.class);
44     private final LoaderHelper loaderHelper;
45     private final NotificationHelper notificationHelper;
46     private WebElement createBtn;
47
48     public ResourceCreatePage(final WebDriver webDriver, final LoaderHelper loaderHelper,
49                               final NotificationHelper notificationHelper) {
50         super(webDriver);
51         this.loaderHelper = loaderHelper;
52         this.notificationHelper = notificationHelper;
53         timeoutInSeconds = 5;
54     }
55
56     @Override
57     public void isLoaded() {
58         LOGGER.debug("Waiting for element visibility with xpath '{}'", FORM_LIFE_CYCLE_STATE.getXpath());
59         final WebElement lifeCycleState = waitForElementVisibility(FORM_LIFE_CYCLE_STATE.getXpath());
60         assertThat("Life cycle state should be as expected",
61             lifeCycleState.getText(), is(equalToIgnoringCase(LifeCycleStateEnum.IN_DESIGN.getValue())));
62         createBtn = getWait()
63             .until(ExpectedConditions.elementToBeClickable(By.xpath(XpathSelector.CREATE_BTN.getXpath())));
64     }
65
66     /**
67      * Creates the resource and wait for success notification.
68      */
69     public void createResource() {
70         createBtn.click();
71         loaderHelper.waitForLoader(60);
72         notificationHelper.waitForNotification(NotificationType.SUCCESS, 60);
73     }
74
75     /**
76      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
77      */
78     public enum XpathSelector {
79         CREATE_BTN("create/save", "//button[@data-tests-id='%s']"),
80         FORM_LIFE_CYCLE_STATE("formlifecyclestate", "//span[@data-tests-id='%s']");
81
82         private final String id;
83         private final String xpathFormat;
84
85         XpathSelector(final String id, final String xpathFormat) {
86             this.id = id;
87             this.xpathFormat = xpathFormat;
88         }
89
90         public String getId() {
91             return id;
92         }
93
94         public String getXpath() {
95             return String.format(xpathFormat, id);
96         }
97     }
98
99 }