[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / HomeUtils.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 org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
24 import org.openecomp.sdc.ci.tests.datatypes.CheckBoxStatusEnum;
25 import org.openecomp.sdc.ci.tests.datatypes.CreateAndImportButtonsEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebDriver;
30 import org.openqa.selenium.WebElement;
31 import org.testng.Assert;
32
33 import com.aventstack.extentreports.Status;
34
35 public final class HomeUtils {
36
37         public static WebElement createAndImportButtons(CreateAndImportButtonsEnum type, WebDriver driver)
38                         throws InterruptedException {
39                 switch (type) {
40                 case IMPORT_CP:
41                 case IMPORT_VFC:
42                 case IMPORT_VL:
43                         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.IMPORT_AREA.getValue());
44                         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.IMPORT_VFC.getValue());
45
46                 case IMPORT_VF:
47                         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.IMPORT_AREA.getValue());
48                         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.IMPORT_VFC.getValue());
49                 case CREATE_SERVICE:
50                         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
51                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
52                         ;
53                         break;
54
55                 case CREATE_PRODUCT:
56                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
57                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
58                         break;
59
60                 default:
61                         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
62                         driver.findElement(By.xpath("//*[@data-tests-id='createResourceButton']")).click();
63                         break;
64                 }
65                 return null;
66
67         }
68
69         public static String checkBoxLifeCyclestate(CheckBoxStatusEnum lifeCycle) {
70                 String Status = "IN DESIGN CHECK OUT";
71                 switch (lifeCycle) {
72                 case CHECKIN:
73                         Status = "IN DESIGN CHECK IN";
74                         if (GeneralUIUtils.getWebElementByTestID(lifeCycle.getValue()).isDisplayed()) {
75                                 GeneralUIUtils.getWebElementByTestID(lifeCycle.getValue()).click();
76                         }
77                         break;
78                 case CHECKOUT:
79                         GeneralUIUtils.getWebElementByTestID(lifeCycle.getValue()).click();
80                         Status = "IN DESIGN CHECK OUT";
81                         break;
82                 case IN_TESTING:
83                         GeneralUIUtils.getWebElementByTestID(lifeCycle.getValue()).click();
84                         Status = "IN TESTING";
85                         break;
86                 case READY_FOR_TESTING:
87                         GeneralUIUtils.getWebElementByTestID(lifeCycle.getValue()).click();
88                         Status = "READY FOR TESTING";
89                         break;
90                 case CERTIFIED:
91                         GeneralUIUtils.getWebElementByTestID(lifeCycle.getValue()).click();
92                         Status = "CERTIFIED";
93                         break;
94                 }
95                 return Status;
96         }
97         
98         public static void findComponentAndClick(String componentName) throws Exception {
99                 SetupCDTest.getExtendTest().log(Status.INFO, "finding component " + componentName);
100                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue()).sendKeys(componentName);
101                 WebElement foundComp = null;
102                 try {
103                         foundComp = GeneralUIUtils.getWebElementByTestID(componentName);
104                         foundComp.click();
105                         GeneralUIUtils.waitForLoader();
106                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
107                 } catch (Exception e) {
108                         String msg = String.format("DID NOT FIND A COMPONENT NAMED %s", componentName);
109                         SetupCDTest.getExtendTest().log(Status.FAIL, msg);
110                         System.out.println(msg);
111                         Assert.fail(msg);
112                 }
113         }
114         
115         
116
117 }