[sdc] update code of sdc
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / HomePage.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.pages;
22
23 import java.io.File;
24 import java.util.List;
25
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.MainMenuButtonsFromInsideFrame;
28 import org.openecomp.sdc.ci.tests.utilities.DownloadManager;
29 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
30 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
31 import org.openqa.selenium.By;
32 import org.openqa.selenium.WebElement;
33 import org.openqa.selenium.support.ui.ExpectedConditions;
34 import org.openqa.selenium.support.ui.WebDriverWait;
35
36 public class HomePage extends GeneralPageElements {
37
38         public HomePage() {
39                 super();
40         }
41         
42         public static void showVspRepository(){
43                 GeneralUIUtils.waitForElementInVisibilityBy(By.className("ui-notification"), 30);
44                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.MainMenuButtons.REPOSITORY_ICON.getValue());
45         }
46         
47         public static boolean searchForVSP(String vspName){
48                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ImportVfRepository.SEARCH.getValue()).sendKeys(vspName);
49                 GeneralUIUtils.ultimateWait();
50 //              return checkElementsCountInTable(2);
51                 return true;
52         }
53         
54         public static void importVSP(String vspName){
55                 HomePage.showVspRepository();
56                 boolean vspFound = HomePage.searchForVSP(vspName);
57                 if (vspFound){
58                         List<WebElement> elemenetsFromTable = getElemenetsFromTable();
59 //                      GeneralUIUtils.waitForLoader();
60                         WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 30);
61                         WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elemenetsFromTable.get(1)));
62                         findElement.click();
63                         GeneralUIUtils.waitForLoader();
64                         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
65                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
66                 GeneralUIUtils.waitForLoader(60*10);
67                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
68                 }
69         }
70                                 
71                         
72         public static boolean navigateToHomePage() {
73                 try{
74                         System.out.println("Searching for reporsitory icon.");
75                         WebElement repositoryIcon = GeneralUIUtils.getInputElement("repository-icon");
76                         if (repositoryIcon != null){
77                                 return true;
78                         }
79                         else{
80                                 GeneralUIUtils.ultimateWait();
81                                 List<WebElement> homeButtons = GeneralUIUtils.getElemenetsFromTable(By.xpath("//a[contains(.,'HOME')]"));
82                                 if (homeButtons.size() != 0){
83                                         for (WebElement home : homeButtons){
84                                                 if (home.isDisplayed()){
85                                                         home.click();
86                                                         System.out.println("Clicked on home button");
87                                                         break;
88                                                 }
89                                         }
90                                         GeneralUIUtils.closeErrorMessage();
91                                         WebElement homeButton = GeneralUIUtils.getInputElement(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue());
92                                         return homeButton.isDisplayed();
93                                 }
94         
95                         }
96                 }
97                 catch(Exception innerException){
98                         System.out.println("Can't click on home button.");
99                         return false;
100                 }
101                 return false;
102         }
103
104         public static File downloadVspCsarToDefaultDirectory(String vspName) throws Exception {
105                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
106                 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, "");
107                 File latestFilefromDir = FileHandling.getLastModifiedFileFromDir();
108                 return latestFilefromDir;
109         }
110         
111 }