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 static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.equalToIgnoringCase;
24 import static org.hamcrest.core.Is.is;
26 import lombok.AllArgsConstructor;
28 import org.onap.sdc.frontend.ci.tests.datatypes.LifeCycleStateEnum;
29 import org.onap.sdc.frontend.ci.tests.datatypes.ServiceCreateData;
30 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
31 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
32 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
33 import org.openqa.selenium.By;
34 import org.openqa.selenium.WebDriver;
35 import org.openqa.selenium.support.ui.Select;
38 * Represents the Service Create Page
40 public class ServiceCreatePage extends ComponentPage {
42 private final LoaderHelper loaderHelper;
43 private final NotificationComponent notificationComponent;
44 private final ResourceWorkspaceTopBarComponent topBarComponent;
46 public ServiceCreatePage(final WebDriver webDriver) {
48 this.loaderHelper = new LoaderHelper(webDriver);
49 this.notificationComponent = new NotificationComponent(webDriver);
50 this.topBarComponent = new ResourceWorkspaceTopBarComponent(webDriver);
54 public void isLoaded() {
55 topBarComponent.isLoaded();
56 final String lifeCycleState = topBarComponent.getLifecycleState();
57 assertThat("Life cycle state should be as expected",
58 lifeCycleState, is(equalToIgnoringCase(LifeCycleStateEnum.IN_DESIGN.getValue())));
62 * Fill the service create form based on the given ServiceCreateData
64 * @param serviceCreateData the form data
66 public void fillForm(final ServiceCreateData serviceCreateData) {
67 fillName(serviceCreateData.getName());
68 setModel(serviceCreateData.getModel());
69 setCategory(serviceCreateData.getCategory());
70 setEtsiVersion(serviceCreateData.getEtsiVersion());
71 fillDescription(serviceCreateData.getDescription());
74 private void setEtsiVersion(final String etsiVersion) {
75 if (etsiVersion == null) {
78 final Select categorySelect = new Select(waitForElementVisibility(By.xpath(XpathSelector.ETSI_VERSION_SELECT.getXpath())));
79 categorySelect.selectByVisibleText(etsiVersion);
82 private void setModel(final String model) {
86 final Select modelSelect = new Select(findElement(By.xpath(XpathSelector.MODEL_SELECT.getXpath())));
87 modelSelect.selectByVisibleText(model);
90 private void setCategory(final String category) {
91 if (category == null) {
94 final Select categorySelect = new Select(findElement(By.xpath(XpathSelector.CATEGORY_SELECT.getXpath())));
95 categorySelect.selectByVisibleText(category);
98 public void fillDescription(final String description) {
99 if (description == null) {
102 findElement(By.xpath(XpathSelector.DESCRIPTION_TEXT_AREA.getXpath()))
103 .sendKeys(description);
106 public void fillName(final String name) {
110 findElement(By.xpath(XpathSelector.NAME_INPUT.getXpath()))
114 public void clickOnCreate() {
115 topBarComponent.clickOnCreate();
116 loaderHelper.waitForLoader(20);
117 notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
121 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
124 private enum XpathSelector {
125 NAME_INPUT("name", "//input[@data-tests-id='%s']"),
126 MODEL_SELECT("selectModelName", "//select[@data-tests-id='%s']"),
127 CATEGORY_SELECT("selectGeneralCategory", "//select[@data-tests-id='%s']"),
128 ETSI_VERSION_SELECT("ETSI Version", "//select[@data-tests-id='%s']"),
129 DESCRIPTION_TEXT_AREA("description", "//textarea[@data-tests-id='%s']");
132 private final String id;
133 private final String xpathFormat;
135 public String getXpath() {
136 return String.format(xpathFormat, id);