001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019 020package org.nuxeo.functionaltests.pages.admincenter; 021 022import org.nuxeo.functionaltests.pages.LoginPage; 023import org.openqa.selenium.By; 024import org.openqa.selenium.WebDriver; 025import org.openqa.selenium.WebElement; 026 027public class SystemHomePage extends AdminCenterBasePage { 028 029 public static final String HOST_SUBTAB = "Host"; 030 031 public static final String SETUP_SUBTAB = "Setup"; 032 033 private static final int RESTART_TIMEOUT_MINUTES = 10; 034 035 public SystemHomePage(WebDriver driver) { 036 super(driver); 037 } 038 039 public LoginPage restart() { 040 if (!HOST_SUBTAB.equals(getSelectedSubTab())) { 041 selectSubTab(HOST_SUBTAB); 042 } 043 WebElement restartButton = findElementWithTimeout( 044 By.xpath("//input[@type='submit' and @value='Restart server']")); 045 if (restartButton != null) { 046 restartButton.click(); 047 // Trying wait until on failing alert.accept on some machine: 048 // org.openqa.selenium.WebDriverException: 049 // a.document.getElementsByTagName("dialog")[0] is undefined 050 051 // Confirmation alert is disabled during integration tests 052 // (hostInfo.xhtml), 053 // because sometimes webdriver fails to focus on it. 054 055 // new WaitUntil(4000) { 056 // @Override 057 // public boolean condition() { 058 // Alert alert = driver.switchTo().alert(); 059 // alert.accept(); 060 // return true; 061 // } 062 // }.waitUntil(); 063 } else { 064 return null; 065 } 066 findElementWithTimeout(By.id("username"), RESTART_TIMEOUT_MINUTES * 60 * 1000); 067 return asPage(LoginPage.class); 068 } 069 070 public boolean setConfig(String id, String value) { 071 if (!SETUP_SUBTAB.equals(getSelectedSubTab())) { 072 selectSubTab(SETUP_SUBTAB); 073 } 074 WebElement input = findElementWithTimeout(By.xpath("//td[@id='" + id + "']/input")); 075 if (input != null) { 076 input.sendKeys(value); 077 return true; 078 } 079 return false; 080 } 081 082 public String getConfig(String id) { 083 if (!SETUP_SUBTAB.equals(getSelectedSubTab())) { 084 selectSubTab(SETUP_SUBTAB); 085 } 086 WebElement input = findElementWithTimeout(By.xpath("//td[@id='" + id + "']/input")); 087 if (input != null) { 088 return input.getAttribute("value"); 089 } 090 return null; 091 } 092 093}