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 java.util.Optional;
24 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
25 import org.openecomp.sdc.ci.tests.pages.PageObject;
26 import org.openecomp.sdc.ci.tests.pages.ResourceCreatePage;
27 import org.openecomp.sdc.ci.tests.pages.TopNavComponent;
28 import org.openecomp.sdc.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;
38 public ImportVspFlow(final WebDriver webDriver, final String resourceName) {
40 this.resourceName = resourceName;
44 public Optional<PageObject> run(final PageObject... pageObjects) {
45 final VspRepositoryModalComponent vspRepositoryModalComponent = openVspRepository();
46 searchForVsp(vspRepositoryModalComponent);
47 return Optional.of(importVsp(vspRepositoryModalComponent));
51 * Opens the VSP repository modal by clicking in its icon from the top nav menu.
53 * @return the VSP repository modal
55 private VspRepositoryModalComponent openVspRepository() {
56 extendTest.log(Status.INFO, "Opening the VSP repository");
57 final TopNavComponent topNavComponent = new TopNavComponent(webDriver);
58 topNavComponent.isLoaded();
59 final VspRepositoryModalComponent vspRepositoryModalComponent = topNavComponent.clickOnRepositoryIcon();
60 vspRepositoryModalComponent.isLoaded();
61 return vspRepositoryModalComponent;
65 * Searches for a VSP in the repository modal.
67 * @param vspRepositoryModalComponent the repository modal component
69 private void searchForVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
70 extendTest.log(Status.INFO, String.format("Searching for VSP '%s' in the repository", resourceName));
71 vspRepositoryModalComponent.searchForVSP(resourceName);
72 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-found-repository",
73 String.format("Searching for VSP '%s' found in the repository", resourceName));
77 * Imports the first VSP in the repository list.
79 * @param vspRepositoryModalComponent the repository modal component that contains the VSP list
80 * @return the resource creation page that the import action redirects
82 private ResourceCreatePage importVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
83 extendTest.log(Status.INFO, String.format("Importing VSP '%s'", resourceName));
84 final ResourceCreatePage resourceCreatePage = vspRepositoryModalComponent.clickOnImportVsp(1);
85 resourceCreatePage.isLoaded();
86 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-imported",
87 String.format("VSP '%s' was imported", resourceName));
88 return resourceCreatePage;