Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / ProductGeneralPage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.frontend.ci.tests.pages;
22
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
25 import org.onap.sdc.backend.ci.tests.datatypes.ProductReqDetails;
26 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
27 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebElement;
30
31 import java.util.ArrayList;
32
33 /**
34  * @author al714h
35  */
36
37 public class ProductGeneralPage extends ResourceGeneralPage {
38
39     private ProductGeneralPage() {
40         super();
41     }
42
43     public static ProductLeftMenu getProductLeftMenu() {
44         return new ProductLeftMenu();
45     }
46
47     public static void defineName(String productName) {
48         WebElement productNameTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.PRODUCT_NAME.getValue());
49         productNameTextbox.clear();
50         productNameTextbox.sendKeys(productName);
51     }
52
53     public static void defineFullName(String productFullName) {
54         WebElement productFullNameTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.FULL_NAME.getValue());
55         productFullNameTextbox.clear();
56         productFullNameTextbox.sendKeys(productFullName);
57     }
58
59     public static void defineProjectCode(String pmat) {
60         WebElement pmattTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.PROJECT_CODE.getValue());
61         pmattTextbox.clear();
62         pmattTextbox.sendKeys(pmat);
63     }
64
65     public static String getPmattText() {
66         return getPmattField().getAttribute("value");
67     }
68
69     public static String[] getTags() {
70         return getElementsFromTagsTable().stream().map(WebElement::getText).toArray(String[]::new);
71     }
72
73     private static WebElement getPmattField() {
74         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.PROJECT_CODE.getValue());
75     }
76
77     public static void deleteOldTags(ProductReqDetails product) {
78         // Delete tag elements
79         int i = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-delete").size();
80         while (i > 0) {
81             GeneralUIUtils.getWebElementByTestID("i-sdc-tag-delete").click();
82             i--;
83         }
84
85         product.setTags(new ArrayList<String>());
86     }
87
88     public static void clickAddWorkflow() {
89         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding workflow..."));
90         GeneralUIUtils.clickOnElementByText("Add Workflow");
91     }
92
93     public static void fillAndAddNewWorkflow(String name, String description) throws InterruptedException {
94         GeneralUIUtils.ultimateWait();
95         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling name field with %s", name));
96         insertText(name, "label + input");
97         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling description filed with %s", name));
98         insertText(description, "label + textarea");
99         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking save button "));
100         clickSave();
101     }
102
103     public static void insertText(String artifactDescriptoin, String element) throws InterruptedException {
104         GeneralUIUtils.getElementsByCSS("div[class='modal-content']");
105         WebElement artifactDescriptionTextbox = GeneralUIUtils.getWebElementBy(By.cssSelector(element));
106         artifactDescriptionTextbox.clear();
107         artifactDescriptionTextbox.sendKeys(artifactDescriptoin);
108         GeneralUIUtils.ultimateWait();
109     }
110
111     public static void clickSave() {
112         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Save button"));
113         GeneralUIUtils.clickOnElementByText("Save");
114         GeneralUIUtils.ultimateWait();
115     }
116
117 }