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; 022import org.openqa.selenium.chrome.ChromeDriver; 023import org.openqa.selenium.firefox.FirefoxDriver; 024import org.openqa.selenium.htmlunit.HtmlUnitDriver; 025import org.openqa.selenium.ie.InternetExplorerDriver; 026 027/** 028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 029 */ 030public enum BrowserFamily { 031 032 FIREFOX, IE, CHROME, HTML_UNIT, HTML_UNIT_JS; 033 034 public DriverFactory getDriverFactory() { 035 switch (this) { 036 case FIREFOX: 037 return new FirefoxDriverFactory(); 038 case IE: 039 return new IEDriverFactory(); 040 case CHROME: 041 return new ChromeDriverFactory(); 042 case HTML_UNIT_JS: 043 return new HtmlUnitJsDriverFactory(); 044 default: 045 return new HtmlUnitDriverFactory(); 046 } 047 } 048 049 class FirefoxDriverFactory implements DriverFactory { 050 @Override 051 public WebDriver createDriver() { 052 FirefoxDriver ff = new FirefoxDriver(); 053 // ff.manage().setSpeed(Speed.FAST); 054 return ff; 055 } 056 057 @Override 058 public void disposeDriver(WebDriver driver) { 059 } 060 061 @Override 062 public BrowserFamily getBrowserFamily() { 063 return BrowserFamily.this; 064 } 065 } 066 067 class ChromeDriverFactory implements DriverFactory { 068 @Override 069 public WebDriver createDriver() { 070 ChromeDriver ff = new ChromeDriver(); 071 // ff.manage().setSpeed(Speed.FAST); 072 return ff; 073 } 074 075 @Override 076 public void disposeDriver(WebDriver driver) { 077 } 078 079 @Override 080 public BrowserFamily getBrowserFamily() { 081 return BrowserFamily.this; 082 } 083 } 084 085 class IEDriverFactory implements DriverFactory { 086 @Override 087 public WebDriver createDriver() { 088 InternetExplorerDriver driver = new InternetExplorerDriver(); 089 // driver.manage().setSpeed(Speed.FAST); 090 return driver; 091 } 092 093 @Override 094 public void disposeDriver(WebDriver driver) { 095 } 096 097 @Override 098 public BrowserFamily getBrowserFamily() { 099 return BrowserFamily.this; 100 } 101 } 102 103 class HtmlUnitDriverFactory implements DriverFactory { 104 @Override 105 public WebDriver createDriver() { 106 return new HtmlUnitDriver(); 107 } 108 109 @Override 110 public void disposeDriver(WebDriver driver) { 111 } 112 113 @Override 114 public BrowserFamily getBrowserFamily() { 115 return BrowserFamily.this; 116 } 117 } 118 119 class HtmlUnitJsDriverFactory implements DriverFactory { 120 @Override 121 public WebDriver createDriver() { 122 HtmlUnitDriver driver = new HtmlUnitDriver(); 123 driver.setJavascriptEnabled(true); 124 return driver; 125 } 126 127 @Override 128 public void disposeDriver(WebDriver driver) { 129 } 130 131 @Override 132 public BrowserFamily getBrowserFamily() { 133 return BrowserFamily.this; 134 } 135 } 136 137 // private WebDriver _old_makeFirefoxDriver() { 138 // String Xport = System.getProperty("nuxeo.xvfb.id", ":0"); 139 // File firefoxPath = new File(System.getProperty("firefox.path", 140 // "/usr/bin/firefox")); 141 // FirefoxBinary firefox = new FirefoxBinary(firefoxPath); 142 // firefox.setEnvironmentProperty("DISPLAY", Xport); 143 // WebDriver driver = new FirefoxDriver(firefox, null); 144 // //driver.setVisible(false); 145 // driver.manage().setSpeed(Speed.FAST); 146 // return driver; 147 // } 148 149}