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