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
|
|
86
|
firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
|
87
|
|
88
|
firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying first run page
|
89
|
|
90
|
firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firexpath-" + FIREXPATH_VERSION + "-fx.xpi");
|
91
|
|
92
|
firefoxProfile.setEnableNativeEvents(true);
|
93
|
|
94
|
// --- allow enabling incompatible addons
|
95
|
// firefoxProfile.addExtension(this.getClass(), "/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi");
|
96
|
// firefoxProfile.setPreference("extensions.acr.firstrun", false);
|
97
|
// 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");
|
98
|
// firefoxProfile.setPreference("extensions.checkCompatibility", false);
|
99
|
// firefoxProfile.setPreference("extensions.checkCompatibility.4.0", false);
|
100
|
// firefoxProfile.setPreference("extensions.checkCompatibility.4.1", false);
|
101
|
|
102
|
} catch (IOException e) {
|
103
|
CdmDataPortalTestBase.logger.error(e);
|
104
|
System.exit(-1);
|
105
|
}
|
106
|
driver = new FirefoxDriver(firefoxProfile);
|
107
|
|
108
|
|
109
|
return driver;
|
110
|
}
|
111
|
|
112
|
|
113
|
|
114
|
|
115
|
}
|