re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / 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.openecomp.sdc.ci.tests.pages;
22
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
25 import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
26 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
27 import org.openecomp.sdc.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
38 public class ProductGeneralPage extends ResourceGeneralPage {
39
40         public ProductGeneralPage() {
41                 super();
42         }
43         
44         public static ProductLeftMenu getProductLeftMenu() {
45         return new ProductLeftMenu();
46     }
47
48         public static void defineName(String productName) {
49                 WebElement productNameTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.PRODUCT_NAME.getValue());
50                 productNameTextbox.clear();
51                 productNameTextbox.sendKeys(productName);
52         }
53
54         public static void defineFullName(String productFullName) {
55                 WebElement productFullNameTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.FULL_NAME.getValue());
56                 productFullNameTextbox.clear();
57                 productFullNameTextbox.sendKeys(productFullName);
58         }
59         
60         public static void defineProjectCode(String pmat) {
61                 WebElement pmattTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.PROJECT_CODE.getValue());
62                 pmattTextbox.clear();
63                 pmattTextbox.sendKeys(pmat);
64         }
65         
66         public static String getPmattText(){
67                 return getPmattField().getAttribute("value");
68         }
69         
70         public static String[] getTags(){
71                 return ResourceGeneralPage.getElementsFromTagsTable().stream().map(WebElement::getText).toArray(String[]::new);
72         }
73         
74         private static WebElement getPmattField() {
75                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.PROJECT_CODE.getValue());
76         }
77         
78         public static void deleteOldTags(ProductReqDetails product){
79                 // Delete tag elements
80                 int i = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-delete").size();
81                 while (i > 0){                  
82                         GeneralUIUtils.getWebElementByTestID("i-sdc-tag-delete").click();
83                         i--;
84                 }
85                 
86                 product.setTags(new ArrayList<String>());
87         }
88         
89         public static void clickAddWorkflow (){
90                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding workflow..."));
91                 GeneralUIUtils.clickOnElementByText("Add Workflow");
92         }
93         
94         public static void fillAndAddNewWorkflow(String name, String description ) throws InterruptedException{
95                 GeneralUIUtils.ultimateWait();
96                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling name field with %s", name));
97                 insertText(name, "label + input");
98                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling description filed with %s", name));
99                 insertText(description,"label + textarea");
100                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking save button "));
101                 clickSave();
102         }
103         
104         public static void insertText(String artifactDescriptoin, String element) throws InterruptedException {
105                 GeneralUIUtils.getElementsByCSS("div[class='modal-content']");
106                 WebElement artifactDescriptionTextbox = GeneralUIUtils.getWebElementBy(By.cssSelector(element));
107                 artifactDescriptionTextbox.clear();
108                 artifactDescriptionTextbox.sendKeys(artifactDescriptoin);
109                 GeneralUIUtils.ultimateWait();          
110         }
111         
112         public static void clickSave() {
113                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Save button"));
114                 GeneralUIUtils.clickOnElementByText("Save");
115                 GeneralUIUtils.ultimateWait();
116         }
117
118 }