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