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 static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.core.Is.is;
25 import com.aventstack.extentreports.Status;
26 import java.util.Optional;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.onap.sdc.frontend.ci.tests.pages.OnboardHomePage;
29 import org.onap.sdc.frontend.ci.tests.pages.PageObject;
30 import org.onap.sdc.frontend.ci.tests.pages.SoftwareProductOnboarding;
31 import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
32 import org.onap.sdc.frontend.ci.tests.pages.VspCreationModal;
33 import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
34 import org.openqa.selenium.WebDriver;
37 * UI Flow for VSP creation
39 public class CreateVspFlow extends AbstractUiTestFlow {
41 private final String resourceName;
42 private final String packageFile;
43 private final String rootFolder;
44 private HomePage homePage;
46 public CreateVspFlow(final WebDriver webDriver, final String resourceName, final String packageFile,
47 final String rootFolder) {
49 this.resourceName = resourceName;
50 this.packageFile = packageFile;
51 this.rootFolder = rootFolder;
55 public Optional<PageObject> run(final PageObject... pageObjects) {
56 extendTest.log(Status.INFO,
57 String.format("Creating VSP '%s' by onboarding ETSI VNF/CNF package '%s'", resourceName, packageFile));
58 final TopNavComponent topNavComponent = findParameter(pageObjects, TopNavComponent.class);
59 extendTest.log(Status.INFO, "Accessing the Onboard Home Page");
60 topNavComponent.isLoaded();
61 final OnboardHomePage onboardHomePage = goToOnboardHomePage(topNavComponent);
62 final SoftwareProductOnboarding softwareProductOnboarding = createNewVsp(onboardHomePage);
63 uploadPackage(softwareProductOnboarding);
64 submitVsp(softwareProductOnboarding);
65 goToHomePage(topNavComponent);
66 return Optional.empty();
70 public Optional<HomePage> getLandedPage() {
71 return Optional.ofNullable(homePage);
75 * Goes to the onboard home page by clicking in the onboard tab in the top nav component.
77 * @param topNavComponent the top nav component
78 * @return the onboard home page
80 private OnboardHomePage goToOnboardHomePage(final TopNavComponent topNavComponent) {
81 final OnboardHomePage onboardHomePage = topNavComponent.clickOnOnboard();
82 onboardHomePage.isLoaded();
83 ExtentTestActions.takeScreenshot(Status.INFO, "onboard-homepage", "Onboard homepage is loaded");
84 return onboardHomePage;
88 * Creates a new VSP in the onboard home page.
90 * @param onboardHomePage the onboard home page representation
91 * @return the software product onboarding page
93 private SoftwareProductOnboarding createNewVsp(final OnboardHomePage onboardHomePage) {
94 extendTest.log(Status.INFO, "Creating a new VSP");
95 final VspCreationModal vspCreationModal = onboardHomePage.clickOnCreateNewVsp();
96 vspCreationModal.isLoaded();
97 vspCreationModal.fillCreationForm(resourceName);
98 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-creation-form",
99 "Creating VSP with given information");
100 final SoftwareProductOnboarding softwareProductOnboarding = vspCreationModal.clickOnCreate();
101 softwareProductOnboarding.isLoaded();
102 extendTest.log(Status.INFO, String.format("VSP '%s' created", resourceName));
103 final String actualResourceName = softwareProductOnboarding.getResourceName();
104 assertThat(String.format("Should be in the Software Product '%s' page", resourceName),
105 actualResourceName, is(resourceName));
106 return softwareProductOnboarding;
110 * Uploads a package in the software product onboarding page.
112 * @param softwareProductOnboarding the software product onboarding page
114 private void uploadPackage(final SoftwareProductOnboarding softwareProductOnboarding) {
115 extendTest.log(Status.INFO,
116 String.format("Uploading package '%s' to VSP '%s'", packageFile, resourceName)
118 softwareProductOnboarding.uploadFile(rootFolder + packageFile);
119 softwareProductOnboarding.attachmentScreenIsLoaded();
120 extendTest.log(Status.INFO,
121 String.format("Package '%s' was uploaded to VSP '%s'.", packageFile, resourceName)
126 * Submits the VSP through the software product onboarding page.
128 * @param softwareProductOnboarding the software product onboarding page
130 private void submitVsp(final SoftwareProductOnboarding softwareProductOnboarding) {
131 extendTest.log(Status.INFO, "Submitting the first VSP version.");
132 softwareProductOnboarding.submit();
133 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-submitted", "The first VSP version was submitted");
137 * Go to the system home page through the top nav menu.
139 * @param topNavComponent the top nav component
141 private void goToHomePage(final TopNavComponent topNavComponent) {
142 extendTest.log(Status.INFO, "Accessing the Home page to import the created VSP");
143 topNavComponent.isLoaded();
144 this.homePage = topNavComponent.clickOnHome();
146 ExtentTestActions.takeScreenshot(Status.INFO, "home-is-loaded", "The Home page is loaded.");