[SDC-29] rebase continue work to align source
[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                 return checkElementsCountInTable(2);
50         }
51         
52         public static void importVSP(String vspName){
53                 HomePage.showVspRepository();
54                 boolean vspFound = HomePage.searchForVSP(vspName);
55                 if (vspFound){
56                         List<WebElement> elemenetsFromTable = getElemenetsFromTable();
57 //                      GeneralUIUtils.waitForLoader();
58                         WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 30);
59                         WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elemenetsFromTable.get(1)));
60                         findElement.click();
61                         GeneralUIUtils.waitForLoader();
62                         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
63                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
64                 GeneralUIUtils.waitForLoader(60*10);
65                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
66                 }
67         }
68                                 
69                         
70         public static boolean navigateToHomePage() {
71                 try{
72                         System.out.println("Searching for reporsitory icon.");
73                         WebElement repositoryIcon = GeneralUIUtils.getInputElement("repository-icon");
74                         if (repositoryIcon != null){
75                                 return true;
76                         }
77                         else{
78                                 GeneralUIUtils.ultimateWait();
79                                 List<WebElement> homeButtons = GeneralUIUtils.getElemenetsFromTable(By.xpath("//a[contains(.,'HOME')]"));
80                                 if (homeButtons.size() != 0){
81                                         for (WebElement home : homeButtons){
82                                                 if (home.isDisplayed()){
83                                                         home.click();
84                                                         System.out.println("Clicked on home button");
85                                                         break;
86                                                 }
87                                         }
88                                         GeneralUIUtils.closeErrorMessage();
89                                         WebElement homeButton = GeneralUIUtils.getInputElement(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue());
90                                         return homeButton.isDisplayed();
91                                 }
92         
93                         }
94                 }
95                 catch(Exception innerException){
96                         System.out.println("Can't click on home button.");
97                         return false;
98                 }
99                 return false;
100         }
101
102         public static File downloadVspCsarToDefaultDirectory(String vspName) throws Exception {
103                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
104                 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, "");
105                 File latestFilefromDir = FileHandling.getLastModifiedFileFromDir();
106                 return latestFilefromDir;
107         }
108         
109 }