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 static org.hamcrest.core.Is.is;
23 import static org.junit.Assert.assertThat;
25 import com.aventstack.extentreports.Status;
26 import java.util.Optional;
27 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
28 import org.openecomp.sdc.ci.tests.pages.OnboardHomePage;
29 import org.openecomp.sdc.ci.tests.pages.PageObject;
30 import org.openecomp.sdc.ci.tests.pages.SoftwareProductOnboarding;
31 import org.openecomp.sdc.ci.tests.pages.TopNavComponent;
32 import org.openecomp.sdc.ci.tests.pages.VspCreationModal;
33 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
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;
45 public CreateVspFlow(final WebDriver webDriver, final String resourceName, final String packageFile,
46 final String rootFolder) {
48 this.resourceName = resourceName;
49 this.packageFile = packageFile;
50 this.rootFolder = rootFolder;
54 public Optional<PageObject> run(final PageObject... pageObjects) {
55 final TopNavComponent topNavComponent = findParameter(pageObjects, TopNavComponent.class);
56 extendTest.log(Status.INFO, "Accessing the Onboard Home Page");
57 topNavComponent.isLoaded();
58 final OnboardHomePage onboardHomePage = goToOnboardHomePage(topNavComponent);
59 final SoftwareProductOnboarding softwareProductOnboarding = createNewVsp(onboardHomePage);
60 uploadPackage(softwareProductOnboarding);
61 submitVsp(softwareProductOnboarding);
62 goToHomePage(topNavComponent);
63 return Optional.empty();
67 * Goes to the onboard home page by clicking in the onboard tab in the top nav component.
69 * @param topNavComponent the top nav component
70 * @return the onboard home page
72 private OnboardHomePage goToOnboardHomePage(final TopNavComponent topNavComponent) {
73 final OnboardHomePage onboardHomePage = topNavComponent.clickOnOnboard();
74 onboardHomePage.isLoaded();
75 ExtentTestActions.takeScreenshot(Status.INFO, "onboard-homepage", "Onboard homepage is loaded");
76 return onboardHomePage;
80 * Creates a new VSP in the onboard home page.
82 * @param onboardHomePage the onboard home page representation
83 * @return the software product onboarding page
85 private SoftwareProductOnboarding createNewVsp(final OnboardHomePage onboardHomePage) {
86 extendTest.log(Status.INFO, "Creating a new VSP");
87 final VspCreationModal vspCreationModal = onboardHomePage.clickOnCreateNewVsp();
88 vspCreationModal.isLoaded();
89 vspCreationModal.fillCreationForm(resourceName);
90 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-creation-form",
91 "Creating VSP with given information");
92 final SoftwareProductOnboarding softwareProductOnboarding = vspCreationModal.clickOnCreate();
93 softwareProductOnboarding.isLoaded();
94 extendTest.log(Status.INFO, String.format("VSP '%s' created", resourceName));
95 final String actualResourceName = softwareProductOnboarding.getResourceName();
96 assertThat(String.format("Should be in the Software Product '%s' page", resourceName),
97 actualResourceName, is(resourceName));
98 return softwareProductOnboarding;
102 * Uploads a package in the software product onboarding page.
104 * @param softwareProductOnboarding the software product onboarding page
106 private void uploadPackage(final SoftwareProductOnboarding softwareProductOnboarding) {
107 extendTest.log(Status.INFO,
108 String.format("Uploading package '%s' to VSP '%s'", packageFile, resourceName)
110 softwareProductOnboarding.uploadFile(rootFolder + packageFile);
111 softwareProductOnboarding.attachmentScreenIsLoaded();
112 extendTest.log(Status.INFO,
113 String.format("Package '%s' was uploaded to VSP '%s'.", packageFile, resourceName)
118 * Submits the VSP through the software product onboarding page.
120 * @param softwareProductOnboarding the software product onboarding page
122 private void submitVsp(final SoftwareProductOnboarding softwareProductOnboarding) {
123 extendTest.log(Status.INFO, "Submitting the first VSP version.");
124 softwareProductOnboarding.submit();
125 ExtentTestActions.takeScreenshot(Status.INFO, "vsp-submitted", "The first VSP version was submitted");
129 * Go to the system home page through the top nav menu.
131 * @param topNavComponent the top nav component
133 private void goToHomePage(final TopNavComponent topNavComponent) {
134 extendTest.log(Status.INFO, "Accessing the Home page to import the created VSP");
135 topNavComponent.isLoaded();
136 topNavComponent.clickOnHome();
137 GeneralUIUtils.ultimateWait();
138 topNavComponent.isLoaded();
139 ExtentTestActions.takeScreenshot(Status.INFO, "home-is-loaded", "The Home page is loaded.");