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(By.xpath("//input[@type='submit' and @value='Restart server']")); 044 if (restartButton != null) { 045 restartButton.click(); 046 // Trying wait until on failing alert.accept on some machine: 047 // org.openqa.selenium.WebDriverException: 048 // a.document.getElementsByTagName("dialog")[0] is undefined 049 050 // Confirmation alert is disabled during integration tests 051 // (hostInfo.xhtml), 052 // because sometimes webdriver fails to focus on it. 053 054 // new WaitUntil(4000) { 055 // @Override 056 // public boolean condition() { 057 // Alert alert = driver.switchTo().alert(); 058 // alert.accept(); 059 // return true; 060 // } 061 // }.waitUntil(); 062 } else { 063 return null; 064 } 065 findElementWithTimeout(By.id("username"), RESTART_TIMEOUT_MINUTES * 60 * 1000); 066 return asPage(LoginPage.class); 067 } 068 069 public boolean setConfig(String id, String value) { 070 if (!SETUP_SUBTAB.equals(getSelectedSubTab())) { 071 selectSubTab(SETUP_SUBTAB); 072 } 073 WebElement input = findElementWithTimeout(By.xpath("//td[@id='" + id + "']/input")); 074 if (input != null) { 075 input.sendKeys(value); 076 return true; 077 } 078 return false; 079 } 080 081 public String getConfig(String id) { 082 if (!SETUP_SUBTAB.equals(getSelectedSubTab())) { 083 selectSubTab(SETUP_SUBTAB); 084 } 085 WebElement input = findElementWithTimeout(By.xpath("//td[@id='" + id + "']/input")); 086 if (input != null) { 087 return input.getAttribute("value"); 088 } 089 return null; 090 } 091 092}