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.openecomp.sdc.ci.tests.flow;
22 import com.aventstack.extentreports.Status;
23 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
24 import org.openecomp.sdc.ci.tests.pages.PageObject;
25 import org.openecomp.sdc.ci.tests.pages.ResourceCreatePage;
26 import org.openecomp.sdc.ci.tests.pages.TopNavComponent;
27 import org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent;
28 import org.openqa.selenium.WebDriver;
30 import java.util.Optional;
33 * UI Flow for importing a VSP
35 public class ImportVspFlow extends AbstractUiTestFlow {
37 private final String resourceName;
39 public ImportVspFlow(final WebDriver webDriver, final String resourceName) {
41 this.resourceName = resourceName;
45 public Optional<PageObject> run(final PageObject... pageObjects) {
46 final VspRepositoryModalComponent vspRepositoryModalComponent = openVspRepository();
47 searchForVsp(vspRepositoryModalComponent);
48 return Optional.of(importVsp(vspRepositoryModalComponent));
52 * Opens the VSP repository modal by clicking in its icon from the top nav menu.
54 * @return the VSP repository modal
56 private VspRepositoryModalComponent openVspRepository() {
57 extendTest.log(Status.INFO, "Opening the VSP repository");
58 final TopNavComponent topNavComponent = new TopNavComponent(webDriver);
59 topNavComponent.isLoaded();
60 final VspRepositoryModalComponent vspRepositoryModalComponent = topNavComponent.clickOnRepositoryIcon();
61 vspRepositoryModalComponent.isLoaded();
62 return vspRepositoryModalComponent;
66 * Searches for a VSP in the repository modal.
68 * @param vspRepositoryModalComponent the repository modal component
70 private void searchForVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
71 extendTest.log(Status.INFO, String.format("Searching for VSP '%s' in the repository", resourceName));
72 vspRepositoryModalComponent.searchForVSP(resourceName);
73 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-found-repository",
74 String.format("Searching for VSP '%s' found in the repository", resourceName));
78 * Imports the first VSP in the repository list.
80 * @param vspRepositoryModalComponent the repository modal component that contains the VSP list
81 * @return the resource creation page that the import action redirects
83 private ResourceCreatePage importVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
84 extendTest.log(Status.INFO, String.format("Importing VSP '%s'", resourceName));
85 final ResourceCreatePage resourceCreatePage = vspRepositoryModalComponent.clickOnImportVsp(1);
86 resourceCreatePage.isLoaded();
87 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-imported",
88 String.format("VSP '%s' was imported", resourceName));
89 return resourceCreatePage;