[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / ProductUIUtils.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.utilities;
22
23 import java.awt.AWTException;
24 import java.util.List;
25
26 import org.junit.rules.TestName;
27 import org.openecomp.sdc.be.model.User;
28 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
30 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
31 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
32 import org.openecomp.sdc.ci.tests.pages.ProductGeneralPage;
33 import org.openqa.selenium.Keys;
34 import org.openqa.selenium.WebDriver;
35 import org.openqa.selenium.WebElement;
36
37 import com.aventstack.extentreports.Status;
38
39 /**
40  * @author al714h
41  *
42  */
43
44 public class ProductUIUtils {
45
46         protected static WebDriver driver;
47
48         public ProductUIUtils(TestName name, String className) {
49                 super();
50         }
51
52         public static void fillProductGeneralPage(ProductReqDetails product, User user) throws Exception {
53                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Fill in metadata values in general page.. "));
54                 ProductGeneralPage.defineName(product.getName());
55                 ProductGeneralPage.defineFullName(product.getFullName());
56                 ProductGeneralPage.defineDescription(product.getDescription());
57                 ProductGeneralPage.defineProjectCode(product.getProjectCode());
58                 defineTagsList2(product.getTags());
59                 ProductGeneralPage.defineContactId(product.getContactId());
60                 GeneralUIUtils.clickSomewhereOnPage();          
61         }
62     
63         public static void createProduct(ProductReqDetails product, User user) throws Exception, AWTException {
64                 clikAddProduct();
65                 fillProductGeneralPage(product, user);
66                 GeneralPageElements.clickCreateButton();
67                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Product %s created", product.getName()));
68         }
69         
70         public static void defineTagsList2(List<String> productTags){
71                 WebElement productTagsTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ProductMetadataEnum.TAGS.getValue());
72                 for (String tag : productTags) {
73                         productTagsTextbox.clear();
74                         productTagsTextbox.sendKeys(tag);
75                         GeneralUIUtils.waitForAngular();
76                         productTagsTextbox.sendKeys(Keys.ENTER);
77                 }
78         }
79         
80         public static void clikAddProduct(){
81                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking Add Product button"));
82                 try {
83                         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
84                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_PRODUCT.getValue()).click();
85                 GeneralUIUtils.ultimateWait();
86                 } catch (Exception e){
87                         SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exception on catched on Add Product button, retrying ..."));
88                         GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");                      
89                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_PRODUCT.getValue()).click();
90                         GeneralUIUtils.ultimateWait();
91                 }
92         }
93
94 }