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