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.FirefoxBinary;
|
12
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
13
|
import org.openqa.selenium.firefox.FirefoxProfile;
|
14
|
import org.openqa.selenium.ie.InternetExplorerDriver;
|
15
|
|
16
|
import eu.etaxonomy.dataportal.Browser;
|
17
|
import eu.etaxonomy.dataportal.DataPortalContext;
|
18
|
import eu.etaxonomy.dataportal.SystemUtils;
|
19
|
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
|
20
|
|
21
|
/**
|
22
|
* @author andreas
|
23
|
*
|
24
|
*/
|
25
|
public class WebDriverFactory {
|
26
|
|
27
|
|
28
|
public static final Logger logger = Logger.getLogger(WebDriverFactory.class);
|
29
|
|
30
|
public static final String SYSTEM_PROPERTY_NAME_BROWSER = "browser";
|
31
|
|
32
|
private static final String FIREBUG_VERSION = "1.10.5";
|
33
|
private static final String FIREXPATH_VERSION = "0.9.7";
|
34
|
private static final String DISABLE_ADD_ON_COMPATIBILITY_CHECKS_VERSION = "1.3";
|
35
|
|
36
|
public static WebDriver newWebDriver() {
|
37
|
|
38
|
WebDriver newDriver = null;
|
39
|
try {
|
40
|
Browser browser = Browser.valueOf(System.getProperty(SYSTEM_PROPERTY_NAME_BROWSER, Browser.firefox.name()));
|
41
|
|
42
|
logger.info("Using browser: " + browser.name());
|
43
|
switch (browser) {
|
44
|
case firefox:
|
45
|
newDriver = initFirefoxDriver();
|
46
|
break;
|
47
|
case chrome:
|
48
|
newDriver = initChromeDriver();
|
49
|
break;
|
50
|
case iexplorer:
|
51
|
newDriver = initInternetExplorerDriver();
|
52
|
break;
|
53
|
}
|
54
|
} catch (NullPointerException e) {
|
55
|
SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
|
56
|
} catch (IllegalArgumentException e) {
|
57
|
SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
|
58
|
}
|
59
|
return newDriver;
|
60
|
}
|
61
|
|
62
|
|
63
|
private static WebDriver initChromeDriver() {
|
64
|
return new ChromeDriver();
|
65
|
}
|
66
|
|
67
|
private static WebDriver initInternetExplorerDriver() {
|
68
|
return new InternetExplorerDriver();
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
|
73
|
*
|
74
|
* See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
|
75
|
*
|
76
|
* @return
|
77
|
*/
|
78
|
private static WebDriver initFirefoxDriver() {
|
79
|
|
80
|
WebDriver driver;
|
81
|
|
82
|
CdmDataPortalTestBase.logger.info(("webdriver.firefox.bin = " + System.getProperty("webdriver.firefox.bin")));
|
83
|
CdmDataPortalTestBase.logger.info(("webdriver.firefox.library.path = " + System.getProperty("webdriver.firefox.library.path")));
|
84
|
|
85
|
FirefoxProfile firefoxProfile = new FirefoxProfile();
|
86
|
|
87
|
boolean addons = true;
|
88
|
|
89
|
if(addons){
|
90
|
try {
|
91
|
firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/disable_add_on_compatibility_checks-" + DISABLE_ADD_ON_COMPATIBILITY_CHECKS_VERSION + ".xpi");
|
92
|
firefoxProfile.setPreference("extensions.checkCompatibility", "false");
|
93
|
|
94
|
// CdmDataPortalTestBase.logger.debug("FirefoxProfile: " + firefoxProfile.getClass().getSimpleName() + "(" + firefoxProfile.hashCode() + ")");
|
95
|
// firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
|
96
|
// firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying first run page
|
97
|
//
|
98
|
// firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firepath-" + FIREXPATH_VERSION + "-fx.xpi");
|
99
|
|
100
|
} catch (IOException e) {
|
101
|
CdmDataPortalTestBase.logger.error(e);
|
102
|
System.exit(-1);
|
103
|
}
|
104
|
}
|
105
|
|
106
|
// NativeEvents can only be used with official binary releases of firefox !!!
|
107
|
// firefoxProfile.setEnableNativeEvents(true);
|
108
|
// see http://groups.google.com/group/webdriver/browse_thread/thread/ab68c413f17ae1ba/b5cbdcebe859aa56?lnk=gst&q=setEnableNativeEvents+firefox#msg_339ac1870da6d975
|
109
|
|
110
|
driver = new FirefoxDriver(firefoxProfile);
|
111
|
|
112
|
return driver;
|
113
|
}
|
114
|
|
115
|
public static void main(String[] args){
|
116
|
|
117
|
initFirefoxDriver();
|
118
|
try {
|
119
|
Thread.currentThread().sleep(1000);
|
120
|
} catch (InterruptedException e) {
|
121
|
System.err.println("InterruptedException");
|
122
|
}
|
123
|
|
124
|
}
|
125
|
|
126
|
|
127
|
|
128
|
|
129
|
}
|