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.junit.AfterClass;
|
10
|
import org.junit.BeforeClass;
|
11
|
import org.junit.runner.RunWith;
|
12
|
import org.openqa.selenium.WebDriver;
|
13
|
import org.openqa.selenium.chrome.ChromeDriver;
|
14
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
15
|
import org.openqa.selenium.firefox.FirefoxProfile;
|
16
|
import org.openqa.selenium.ie.InternetExplorerDriver;
|
17
|
|
18
|
import eu.etaxonomy.dataportal.Browser;
|
19
|
import eu.etaxonomy.dataportal.DataPortalContext;
|
20
|
import eu.etaxonomy.dataportal.SystemUtils;
|
21
|
import eu.etaxonomy.dataportal.junit.DataPortalContextSuite;
|
22
|
|
23
|
/**
|
24
|
* @author a.kohlbecker
|
25
|
*
|
26
|
*/
|
27
|
@RunWith(DataPortalContextSuite.class)
|
28
|
public abstract class CdmDataPortalTestBase {
|
29
|
|
30
|
public static final Logger logger = Logger.getLogger(CdmDataPortalTestBase.class);
|
31
|
|
32
|
public static final String SYSTEM_PROPERTY_NAME_BROWSER = "browser";
|
33
|
|
34
|
private static final String FIREBUG_VERSION = "1.6.2";
|
35
|
private static final String FIREXPATH_VERSION = "0.9.6.1";
|
36
|
|
37
|
protected static WebDriver driver;
|
38
|
|
39
|
private DataPortalContext context;
|
40
|
|
41
|
public DataPortalContext getContext() {
|
42
|
return context;
|
43
|
}
|
44
|
|
45
|
public void setContext(DataPortalContext context) {
|
46
|
this.context = context;
|
47
|
|
48
|
}
|
49
|
|
50
|
@BeforeClass
|
51
|
public static void setUpDriver() {
|
52
|
try {
|
53
|
Browser browser = Browser.valueOf(System.getProperty(SYSTEM_PROPERTY_NAME_BROWSER, Browser.firefox.name()));
|
54
|
|
55
|
logger.info("Using browser: " + browser.name());
|
56
|
switch (browser) {
|
57
|
case firefox:
|
58
|
driver = initFirefoxDriver();
|
59
|
break;
|
60
|
case chrome:
|
61
|
driver = initChromeDriver();
|
62
|
break;
|
63
|
case iexplorer:
|
64
|
driver = initInternetExplorerDriver();
|
65
|
break;
|
66
|
}
|
67
|
|
68
|
} catch (NullPointerException e) {
|
69
|
SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
|
70
|
} catch (IllegalArgumentException e) {
|
71
|
SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
|
72
|
}
|
73
|
|
74
|
}
|
75
|
|
76
|
@AfterClass
|
77
|
public static void closeDriver() {
|
78
|
if (driver != null) {
|
79
|
driver.quit();
|
80
|
}
|
81
|
}
|
82
|
|
83
|
public static WebDriver initChromeDriver() {
|
84
|
return new ChromeDriver();
|
85
|
}
|
86
|
|
87
|
public static WebDriver initInternetExplorerDriver() {
|
88
|
return new InternetExplorerDriver();
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
|
93
|
*
|
94
|
* See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
|
95
|
*
|
96
|
* @return
|
97
|
*/
|
98
|
public static WebDriver initFirefoxDriver() {
|
99
|
CdmDataPortalTestBase.logger.debug(("##:" + System.getProperty("webdriver.firefox.bin")));
|
100
|
|
101
|
FirefoxProfile firefoxProfile = new FirefoxProfile();
|
102
|
try {
|
103
|
|
104
|
firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
|
105
|
firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying firt run page
|
106
|
|
107
|
firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firexpath-" + FIREXPATH_VERSION + "-fx.xpi");
|
108
|
|
109
|
// --- allow enabling incompatible addons
|
110
|
// firefoxProfile.addExtension(this.getClass(), "/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi");
|
111
|
// firefoxProfile.setPreference("extensions.acr.firstrun", false);
|
112
|
// 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");
|
113
|
// firefoxProfile.setPreference("extensions.checkCompatibility", false);
|
114
|
// firefoxProfile.setPreference("extensions.checkCompatibility.4.0", false);
|
115
|
// firefoxProfile.setPreference("extensions.checkCompatibility.4.1", false);
|
116
|
|
117
|
} catch (IOException e) {
|
118
|
CdmDataPortalTestBase.logger.error(e);
|
119
|
System.exit(-1);
|
120
|
}
|
121
|
driver = new FirefoxDriver(firefoxProfile);
|
122
|
|
123
|
return driver;
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Return the {@link DataPortalContext#getBaseUri()} of the currently active
|
128
|
* context as String
|
129
|
*
|
130
|
* @return string representatoin of the DataPortal base URI
|
131
|
*/
|
132
|
public String getBaseUrl() {
|
133
|
return context.getBaseUri().toString();
|
134
|
}
|
135
|
|
136
|
}
|