Project

General

Profile

Download (4.17 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.dataportal.junit;
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

    
22
/**
23
 * @author a.kohlbecker
24
 *
25
 */
26
@RunWith(DataPortalContextSuite.class)
27
public abstract class CdmDataPortalTestBase {
28

    
29
	public static final Logger logger = Logger.getLogger(CdmDataPortalTestBase.class);
30

    
31
	public static final String SYSTEM_PROPERTY_NAME_BROWSER = "browser";
32

    
33
	private static final String FIREBUG_VERSION = "1.6.2";
34
	private static final String FIREXPATH_VERSION = "0.9.6.1";
35

    
36
	protected static WebDriver driver;
37

    
38
	private DataPortalContext context;
39

    
40
	public DataPortalContext getContext() {
41
		return context;
42
	}
43

    
44
	public void setContext(DataPortalContext context) {
45
		this.context = context;
46

    
47
	}
48

    
49
	@BeforeClass
50
	public static void setUpDriver() {
51
		try {
52
			Browser browser = Browser.valueOf(System.getProperty(SYSTEM_PROPERTY_NAME_BROWSER, Browser.firefox.name()));
53

    
54
			logger.info("Using browser: " + browser.name());
55
			switch (browser) {
56
			case firefox:
57
				driver = initFirefoxDriver();
58
				break;
59
			case chrome:
60
				driver = initChromeDriver();
61
				break;
62
			case iexplorer:
63
				driver = initInternetExplorerDriver();
64
				break;
65
			}
66

    
67
		} catch (NullPointerException e) {
68
			SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
69
		} catch (IllegalArgumentException e) {
70
			SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
71
		}
72

    
73
	}
74

    
75
	@AfterClass
76
	public static void closeDriver() {
77
		if (driver != null) {
78
			driver.quit();
79
		}
80
	}
81

    
82
	public static WebDriver initChromeDriver() {
83
		return new ChromeDriver();
84
	}
85

    
86
	public static WebDriver initInternetExplorerDriver() {
87
		return new InternetExplorerDriver();
88
	}
89

    
90
	/**
91
	 * -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
92
	 *
93
	 * See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
94
	 *
95
	 * @return
96
	 */
97
	public static WebDriver initFirefoxDriver() {
98
		CdmDataPortalTestBase.logger.debug(("##:" + System.getProperty("webdriver.firefox.bin")));
99

    
100
		FirefoxProfile firefoxProfile = new FirefoxProfile();
101
		try {
102

    
103
			firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
104
			firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying firt run page
105

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

    
108
			// --- allow enabling incompatible addons
109
			// firefoxProfile.addExtension(this.getClass(), "/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi");
110
			// firefoxProfile.setPreference("extensions.acr.firstrun", false);
111
			// 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");
112
			// firefoxProfile.setPreference("extensions.checkCompatibility", false);
113
			// firefoxProfile.setPreference("extensions.checkCompatibility.4.0", false);
114
			// firefoxProfile.setPreference("extensions.checkCompatibility.4.1", false);
115

    
116
		} catch (IOException e) {
117
			CdmDataPortalTestBase.logger.error(e);
118
			System.exit(-1);
119
		}
120
		driver = new FirefoxDriver(firefoxProfile);
121

    
122
		return driver;
123
	}
124

    
125
	/**
126
	 * Return the {@link DataPortalContext#getBaseUri()} of the currently active
127
	 * context as String
128
	 *
129
	 * @return string representatoin of the DataPortal base URI
130
	 */
131
	public String getBaseUrl() {
132
		return context.getBaseUri().toString();
133
	}
134

    
135
}
(2-2/3)