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