001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and contributors. 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 * bstefanescu 018 */ 019package org.nuxeo.runtime.test.runner.web; 020 021import org.openqa.selenium.WebDriver; 022 023/** 024 * WebDriver test configuration that can be configured either from system properties or for annotations. 025 * 026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 027 */ 028public class Configuration { 029 030 /** 031 * The current driver 032 */ 033 protected WebDriver driver; 034 035 /** 036 * Custom factory to create the driver 037 */ 038 protected DriverFactory factory; 039 040 /** 041 * Initial URL (the one to be used by the home page) 042 */ 043 protected String home; 044 045 /** 046 * The home page class 047 */ 048 protected Class<?> homePageClass; 049 050 public Configuration(DriverFactory factory) { 051 this.factory = factory; 052 } 053 054 protected WebDriver createDriver() { 055 return factory.createDriver(); 056 } 057 058 protected void disposeDriver(WebDriver driver) { 059 factory.disposeDriver(driver); 060 } 061 062 public BrowserFamily getBrowserFamily() { 063 return factory.getBrowserFamily(); 064 } 065 066 public void setFactory(DriverFactory factory) { 067 resetDriver(); 068 this.factory = factory; 069 } 070 071 public DriverFactory getFactory() { 072 return factory; 073 } 074 075 public void setHome(String url) { 076 this.home = url; 077 } 078 079 public String getHome() { 080 return home; 081 } 082 083 public void setHomePageClass(Class<?> homePageClass) { 084 this.homePageClass = homePageClass; 085 } 086 087 public Class<?> getHomePageClass() { 088 return homePageClass; 089 } 090 091 public void home() { 092 if (home != null && driver != null) { 093 driver.get(home); 094 } 095 } 096 097 public WebDriver getDriver() { 098 if (driver == null) { 099 driver = createDriver(); 100 home(); 101 } 102 return driver; 103 } 104 105 public void resetDriver() { 106 if (driver != null) { 107 driver.quit(); 108 disposeDriver(driver); 109 driver = null; 110 } 111 } 112 113}