fix ui-ci tests
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / VspCommitModal.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.utilities.GeneralUIUtils;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.WebDriver;
25 import org.openqa.selenium.WebElement;
26 import org.openqa.selenium.support.ui.ExpectedConditions;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import static org.openecomp.sdc.ci.tests.pages.VspCommitModal.XpathSelector.COMMIT_AND_SUBMIT_BTN;
31 import static org.openecomp.sdc.ci.tests.pages.VspCommitModal.XpathSelector.COMMIT_COMMENT_TXT;
32 import static org.openecomp.sdc.ci.tests.pages.VspCommitModal.XpathSelector.MODAL_CANCEL_BTN;
33 import static org.openecomp.sdc.ci.tests.pages.VspCommitModal.XpathSelector.MODAL_DIV;
34 import static org.openecomp.sdc.ci.tests.pages.VspCommitModal.XpathSelector.SUCCESS_MODAL_DIV;
35
36 /**
37  * Handles the VSP Commit Modal UI actions
38  */
39 public class VspCommitModal extends AbstractPageObject {
40
41     private static final Logger LOGGER = LoggerFactory.getLogger(VspCommitModal.class);
42
43     private WebElement wrappingElement;
44
45     public VspCommitModal(final WebDriver webDriver) {
46         super(webDriver);
47     }
48
49     public void isLoaded() {
50         LOGGER.debug("Finding element with xpath '{}'", MODAL_DIV.getXpath());
51         wrappingElement = waitForElementVisibility(MODAL_DIV.getXpath());
52     }
53
54     /**
55      * Fills the comment text area with a default message.
56      */
57     public void fillCommentWithDefaulMessage() {
58         final WebElement commentTxt = wrappingElement.findElement(By.xpath(COMMIT_COMMENT_TXT.getXpath()));
59         commentTxt.sendKeys("First VSP version");
60     }
61
62     /**
63      * Clicks on the modal submit and confirms success.
64      */
65     public void submit() {
66         final WebElement commitAndSubmitBtn = wrappingElement.findElement(By.xpath(COMMIT_AND_SUBMIT_BTN.getXpath()));
67         commitAndSubmitBtn.click();
68         GeneralUIUtils.ultimateWait();
69         confirmSuccess();
70     }
71
72     /**
73      * Confirms the success of the modal submission.
74      */
75     private void confirmSuccess() {
76         final WebElement successModal = getWait()
77             .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(SUCCESS_MODAL_DIV.getXpath())));
78         successModal.findElement(By.xpath(MODAL_CANCEL_BTN.getXpath())).click();
79     }
80
81     /**
82      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
83      */
84     public enum XpathSelector {
85         MODAL_DIV("sdc-modal-type-custom", "//div[contains(@class, '%s')]"),
86         COMMIT_AND_SUBMIT_BTN("form-submit-button", "//button[@data-test-id='%s']"),
87         COMMIT_COMMENT_TXT("commit-comment-text", "//textarea[@data-test-id='%s']"),
88         SUCCESS_MODAL_DIV("sdc-modal-type-info", "//div[contains(@class, '%s')]"),
89         MODAL_CANCEL_BTN("sdc-modal-cancel-button", "//button[@data-test-id='%s']");
90
91         private final String id;
92         private final String xpath;
93
94         XpathSelector(final String id, final String xpath) {
95             this.id = id;
96             this.xpath = xpath;
97         }
98
99         public String getId() {
100             return id;
101         }
102
103         public String getXpath() {
104             return String.format(xpath, id);
105         }
106     }
107
108 }