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