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