re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / HomeUtils.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * SDC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.sdc.ci.tests.utilities;\r
22 \r
23 import com.aventstack.extentreports.Status;\r
24 import org.openecomp.sdc.ci.tests.datatypes.CreateAndImportButtonsEnum;\r
25 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;\r
26 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;\r
27 import org.openqa.selenium.By;\r
28 import org.openqa.selenium.WebDriver;\r
29 import org.openqa.selenium.WebElement;\r
30 import org.testng.Assert;\r
31 \r
32 import java.util.List;\r
33 \r
34 public final class HomeUtils {\r
35 \r
36     public static WebElement createAndImportButtons(CreateAndImportButtonsEnum type, WebDriver driver)\r
37             throws InterruptedException {\r
38         switch (type) {\r
39             case IMPORT_CP:\r
40             case IMPORT_VFC:\r
41             case IMPORT_VL:\r
42             case IMPORT_VF:\r
43                 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.IMPORT_AREA.getValue());\r
44                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.IMPORT_VFC.getValue());\r
45             case CREATE_SERVICE:\r
46                 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());\r
47                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();\r
48                 break;\r
49 \r
50             case CREATE_PRODUCT:\r
51                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();\r
52                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();\r
53                 break;\r
54 \r
55             default:\r
56                 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());\r
57                 driver.findElement(By.xpath("//*[@data-tests-id='createResourceButton']")).click();\r
58                 break;\r
59         }\r
60         return null;\r
61 \r
62     }\r
63 \r
64     public static void findComponentAndClick(String componentName) throws Exception {\r
65         SetupCDTest.getExtendTest().log(Status.INFO, "finding component " + componentName);\r
66         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue()).sendKeys(componentName);\r
67         WebElement foundComp = null;\r
68         try {\r
69             foundComp = GeneralUIUtils.getWebElementByTestID(componentName);\r
70             foundComp.click();\r
71             GeneralUIUtils.waitForLoader();\r
72             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());\r
73         } catch (Exception e) {\r
74             String msg = String.format("DID NOT FIND A COMPONENT NAMED %s", componentName);\r
75             SetupCDTest.getExtendTest().log(Status.FAIL, msg);\r
76             System.out.println(msg);\r
77             Assert.fail(msg);\r
78         }\r
79     }\r
80 \r
81     public static void findComponentAndClickByVersion(String componentName, String version) throws Exception {\r
82         SetupCDTest.getExtendTest().log(Status.INFO, String.format("finding component %s v%s", componentName, version));\r
83         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue()).sendKeys(componentName);\r
84         List<WebElement> foundComp = null;\r
85         try {\r
86             foundComp = GeneralUIUtils.getWebElementsListByTestID(componentName + "Version");\r
87 \r
88             for (WebElement webElement : foundComp) {\r
89                 if (webElement.getText().contains(version)) {\r
90                     webElement.click();\r
91                     GeneralUIUtils.ultimateWait();\r
92                     break;\r
93                 }\r
94             }\r
95         } catch (Exception e) {\r
96             String msg = String.format("DID NOT FIND A COMPONENT NAMED %s", componentName);\r
97             SetupCDTest.getExtendTest().log(Status.FAIL, msg);\r
98             System.out.println(msg);\r
99             Assert.fail(msg);\r
100         }\r
101     }\r
102 }\r