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
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 java.util.List;
23 import lombok.AllArgsConstructor;
25 import org.onap.sdc.frontend.ci.tests.datatypes.ResourceCreateData;
26 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
27 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.Keys;
30 import org.openqa.selenium.WebDriver;
31 import org.openqa.selenium.WebElement;
32 import org.openqa.selenium.support.ui.Select;
35 * Handles the Resource Create Page UI actions
37 public class ResourceCreatePage extends ComponentPage {
39 private final LoaderHelper loaderHelper;
40 private final NotificationComponent notificationComponent;
41 private final ResourceWorkspaceTopBarComponent topBarComponent;
42 private final ResourceLeftSideMenu resourceLeftSideMenu;
44 public ResourceCreatePage(final WebDriver webDriver) {
46 this.loaderHelper = new LoaderHelper(webDriver);
47 this.notificationComponent = new NotificationComponent(webDriver);
48 this.resourceLeftSideMenu = new ResourceLeftSideMenu(webDriver);
49 this.topBarComponent = new ResourceWorkspaceTopBarComponent(webDriver);
54 public void isLoaded() {
56 waitForElementVisibility(By.xpath(XpathSelector.NAME_INPUT.getXpath()));
57 waitForElementVisibility(By.xpath(XpathSelector.MODEL_SELECT.getXpath()));
58 waitForElementVisibility(By.xpath(XpathSelector.CATEGORY_SELECT.getXpath()));
59 waitForElementVisibility(By.xpath(XpathSelector.DESCRIPTION_TEXT_AREA.getXpath()));
62 public void fillForm(final ResourceCreateData resourceCreateData) {
63 fillName(resourceCreateData.getName());
64 setModel(resourceCreateData.getModel());
65 setCategory(resourceCreateData.getCategory());
66 defineTags(resourceCreateData.getTagList());
67 fillDescription(resourceCreateData.getDescription());
68 fillContactId(resourceCreateData.getContactId());
69 fillVendorName(resourceCreateData.getVendorName());
70 fillVendorRelease(resourceCreateData.getVendorRelease());
71 fillVendorModelNumber(resourceCreateData.getVendorModelNumber());
74 private void fillName(final String name) {
75 setInputField(By.xpath(XpathSelector.NAME_INPUT.getXpath()), name);
79 * Gets the name field value.
81 * @return the name field value
83 public String getName() {
84 return findElement(XpathSelector.NAME_INPUT.getXpath()).getText();
87 private void setModel(final String model) {
91 setSelectField(By.xpath(XpathSelector.MODEL_SELECT.getXpath()), model);
94 private void setCategory(final String category) {
95 setSelectField(By.xpath(XpathSelector.CATEGORY_SELECT.getXpath()), category);
98 private void defineTags(final List<String> tagList) {
99 final WebElement tagsTextbox = findElement(By.xpath(XpathSelector.TAGS.getXpath()));
100 for (final String tag : tagList) {
102 tagsTextbox.sendKeys(tag);
103 tagsTextbox.sendKeys(Keys.ENTER);
107 private void fillDescription(final String description) {
108 setInputField(By.xpath(XpathSelector.DESCRIPTION_TEXT_AREA.getXpath()), description);
111 private void fillContactId(final String contactId) {
112 setInputField(By.xpath(XpathSelector.CONTACT_ID_INPUT.getXpath()), contactId);
115 private void fillVendorName(final String vendorName) {
116 setInputField(By.xpath(XpathSelector.VENDOR_NAME_INPUT.getXpath()), vendorName);
119 private void fillVendorRelease(final String vendorRelease) {
120 setInputField(By.xpath(XpathSelector.VENDOR_RELEASE_INPUT.getXpath()), vendorRelease);
123 private void fillVendorModelNumber(final String vendorModelNumber) {
124 setInputField(By.xpath(XpathSelector.VENDOR_MODEL_NUMBER_INPUT.getXpath()), vendorModelNumber);
127 private void setSelectField(final By locator, final String value) {
131 new Select(findElement(locator)).selectByVisibleText(value);
134 private void setInputField(final By locator, final String value) {
138 findElement(locator).sendKeys(value);
142 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
145 private enum XpathSelector {
146 NAME_INPUT("name", "//input[@data-tests-id='%s']"),
147 MODEL_SELECT("selectModelName", "//select[@data-tests-id='%s']"),
148 CATEGORY_SELECT("selectGeneralCategory", "//select[@data-tests-id='%s']"),
149 TAGS("i-sdc-tag-input", "//input[@data-tests-id='%s']"),
150 DESCRIPTION_TEXT_AREA("description", "//textarea[@data-tests-id='%s']"),
151 CONTACT_ID_INPUT("contactId", "//input[@data-tests-id='%s']"),
152 VENDOR_NAME_INPUT("vendorName", "//input[@data-tests-id='%s']"),
153 VENDOR_RELEASE_INPUT("vendorRelease", "//input[@data-tests-id='%s']"),
154 APPROVE_MESSAGE("checkindialog", "//textarea[@data-tests-id='%s']"),
155 VENDOR_MODEL_NUMBER_INPUT("resourceVendorModelNumber", "//input[@data-tests-id='%s']");
158 private final String id;
159 private final String xpathFormat;
161 public String getXpath() {
162 return String.format(xpathFormat, id);