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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.frontend.ci.tests.pages;
22 import lombok.AllArgsConstructor;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebDriver;
26 import org.openqa.selenium.WebElement;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Handles the VLM Creation Modal UI actions
33 public class VlmCreationModal extends AbstractPageObject {
35 private static final Logger LOGGER = LoggerFactory.getLogger(VlmCreationModal.class);
37 private WebElement wrappingElement;
39 public VlmCreationModal(final WebDriver webDriver) {
45 public void isLoaded() {
46 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_XPATH.getXpath());
47 wrappingElement = waitForElementVisibility(XpathSelector.MODAL_XPATH.getXpath());
51 * Fills VLM mandatory entries
52 * @param vendorName the VLM vendor name
53 * @param description the VLM description
55 public void fillCreationForm(final String vendorName, final String description) {
56 fillVendorName(vendorName);
57 fillDescription(description);
61 * Fills the VLM Vendor Name field
62 * @param vendorName the VLM vendor name
64 private void fillVendorName(final String vendorName) {
65 setInputValue(XpathSelector.VENDOR_NAME_TXT, vendorName);
69 * Fills the VLM description field.
71 * @param description the VLM description
73 public void fillDescription(final String description) {
74 setInputValue(XpathSelector.DESCRIPTION_TXT, description);
78 * Sets input value to the given Xpath
79 * @param inputTestId the Xpath selected
80 * @param value the value
82 private void setInputValue(final XpathSelector inputTestId, final String value) {
83 findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
87 * Clicks on the create button.
88 * @return the next page object
90 public VlmOverviewPage clickOnCreate() {
91 clickElement(XpathSelector.CREATE_BTN);
92 return new VlmOverviewPage(webDriver, new VlmSubmitModal(webDriver));
96 * Clicks on the given Xpath element
97 * @param elementTestId the ui element
99 private void clickElement(final XpathSelector elementTestId) {
100 wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
104 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
107 private enum XpathSelector {
108 MODAL_XPATH("license-model-modal", "//div[@class='%s']"),
109 VENDOR_NAME_TXT("vendor-name", "//*[@data-test-id='%s']"),
110 DESCRIPTION_TXT("vendor-description", "//*[@data-test-id='%s']"),
111 CREATE_BTN("form-submit-button", "//*[@data-test-id='%s']");
114 private final String id;
115 private final String xpathFormat;
117 public String getXpath() {
118 return String.format(xpathFormat, id);