Project

General

Profile

Download (3.67 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.dataportal.selenium;
5

    
6
import java.io.IOException;
7

    
8
import org.apache.log4j.Logger;
9
import org.openqa.selenium.WebDriver;
10
import org.openqa.selenium.chrome.ChromeDriver;
11
import org.openqa.selenium.firefox.FirefoxDriver;
12
import org.openqa.selenium.firefox.FirefoxProfile;
13
import org.openqa.selenium.ie.InternetExplorerDriver;
14

    
15
import eu.etaxonomy.dataportal.Browser;
16
import eu.etaxonomy.dataportal.DataPortalContext;
17
import eu.etaxonomy.dataportal.SystemUtils;
18
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
19

    
20
/**
21
 * @author andreas
22
 *
23
 */
24
public class WebDriverFactory {
25

    
26
	public static final Logger logger = Logger.getLogger(WebDriverFactory.class);
27

    
28
	public static final String SYSTEM_PROPERTY_NAME_BROWSER = "browser";
29

    
30
	private static final String FIREBUG_VERSION = "1.6.2";
31
	private static final String FIREXPATH_VERSION = "0.9.6.1";
32

    
33
	public static WebDriver newWebDriver() {
34

    
35
		WebDriver newDriver = null;
36
		try {
37
			Browser browser = Browser.valueOf(System.getProperty(SYSTEM_PROPERTY_NAME_BROWSER, Browser.firefox.name()));
38

    
39
			logger.info("Using browser: " + browser.name());
40
			switch (browser) {
41
			case firefox:
42
				newDriver = initFirefoxDriver();
43
				break;
44
			case chrome:
45
				newDriver = initChromeDriver();
46
				break;
47
			case iexplorer:
48
				newDriver = initInternetExplorerDriver();
49
				break;
50
			}
51
		} catch (NullPointerException e) {
52
			SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
53
		} catch (IllegalArgumentException e) {
54
			SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
55
		}
56
		return newDriver;
57
	}
58

    
59

    
60
	private static WebDriver initChromeDriver() {
61
		return new ChromeDriver();
62
	}
63

    
64
	private static WebDriver initInternetExplorerDriver() {
65
		return new InternetExplorerDriver();
66
	}
67

    
68
	/**
69
	 * -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
70
	 *
71
	 * See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
72
	 *
73
	 * @return
74
	 */
75
	private static WebDriver initFirefoxDriver() {
76

    
77
		WebDriver driver;
78

    
79
		CdmDataPortalTestBase.logger.info(("firefox binary:" + System.getProperty("webdriver.firefox.bin")));
80

    
81
		FirefoxProfile firefoxProfile = new FirefoxProfile();
82
		try {
83

    
84
			CdmDataPortalTestBase.logger.debug("FirefoxProfile: " + firefoxProfile.getClass().getSimpleName() + "(" + firefoxProfile.hashCode() + ")");
85
			firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
86
			firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying first run page
87

    
88
			firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firexpath-" + FIREXPATH_VERSION + "-fx.xpi");
89

    
90
			firefoxProfile.setEnableNativeEvents(true);
91

    
92
			// --- allow enabling incompatible addons
93
			// firefoxProfile.addExtension(this.getClass(), "/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi");
94
			// firefoxProfile.setPreference("extensions.acr.firstrun", false);
95
			// firefoxProfile.setPreference("extensions.enabledAddons", "fxdriver@googlecode.com,compatibility@addons.mozilla.org:0.8.3,fxdriver@googlecode.com:0.9.7376,{CAFEEFAC-0016-0000-0024-ABCDEFFEDCBA}:6.0.24,{20a82645-c095-46ed-80e3-08825760534b}:0.0.0,meetinglauncher@iconf.net:4.10.12.316,jqs@sun.com:1.0,{972ce4c6-7e08-4474-a285-3208198ce6fd}:4.0");
96
			// firefoxProfile.setPreference("extensions.checkCompatibility", false);
97
			// firefoxProfile.setPreference("extensions.checkCompatibility.4.0", false);
98
			// firefoxProfile.setPreference("extensions.checkCompatibility.4.1", false);
99

    
100
		} catch (IOException e) {
101
			CdmDataPortalTestBase.logger.error(e);
102
			System.exit(-1);
103
		}
104
		driver = new FirefoxDriver(firefoxProfile);
105

    
106
		return driver;
107
	}
108

    
109

    
110

    
111

    
112
}
(3-3/3)