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.flow;
22 import com.aventstack.extentreports.Status;
23 import java.util.Optional;
24 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
25 import org.onap.sdc.frontend.ci.tests.pages.PageObject;
26 import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
27 import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
28 import org.onap.sdc.frontend.ci.tests.pages.VspRepositoryModalComponent;
29 import org.openqa.selenium.WebDriver;
32 * UI Flow for importing a VSP
34 public class ImportVspFlow extends AbstractUiTestFlow {
36 private final String resourceName;
37 private ResourceCreatePage resourceCreatePage;
39 public ImportVspFlow(final WebDriver webDriver, final String resourceName) {
41 this.resourceName = resourceName;
45 public Optional<ResourceCreatePage> run(final PageObject... pageObjects) {
46 final VspRepositoryModalComponent vspRepositoryModalComponent = openVspRepository();
47 searchForVsp(vspRepositoryModalComponent);
48 resourceCreatePage = importVsp(vspRepositoryModalComponent);
49 return Optional.of(resourceCreatePage);
53 public Optional<ResourceCreatePage> getLandedPage() {
54 return Optional.ofNullable(resourceCreatePage);
58 * Opens the VSP repository modal by clicking in its icon from the top nav menu.
60 * @return the VSP repository modal
62 private VspRepositoryModalComponent openVspRepository() {
63 extendTest.log(Status.INFO, "Opening the VSP repository");
64 final TopNavComponent topNavComponent = new TopNavComponent(webDriver);
65 topNavComponent.isLoaded();
66 final VspRepositoryModalComponent vspRepositoryModalComponent = topNavComponent.clickOnRepositoryIcon();
67 vspRepositoryModalComponent.isLoaded();
68 return vspRepositoryModalComponent;
72 * Searches for a VSP in the repository modal.
74 * @param vspRepositoryModalComponent the repository modal component
76 private void searchForVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
77 extendTest.log(Status.INFO, String.format("Searching for VSP '%s' in the repository", resourceName));
78 vspRepositoryModalComponent.searchForVSP(resourceName);
79 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-found-repository",
80 String.format("Searching for VSP '%s' found in the repository", resourceName));
84 * Imports the first VSP in the repository list.
86 * @param vspRepositoryModalComponent the repository modal component that contains the VSP list
87 * @return the resource creation page that the import action redirects
89 private ResourceCreatePage importVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
90 extendTest.log(Status.INFO, String.format("Importing VSP '%s'", resourceName));
91 final ResourceCreatePage resourceCreatePage = vspRepositoryModalComponent.clickOnImportVsp(1);
92 resourceCreatePage.isLoaded();
93 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-imported",
94 String.format("VSP '%s' was imported", resourceName));
95 return resourceCreatePage;