Project

General

Profile

Download (4.05 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.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

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

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

    
120
		return driver;
121
	}
122

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

    
133
}
(2-2/3)