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; //$Id$
|
11
|
/**
|
12
|
* Copyright (C) 2009 EDIT
|
13
|
* European Distributed Institute of Taxonomy
|
14
|
* http://www.e-taxonomy.eu
|
15
|
*
|
16
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
17
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
18
|
*/
|
19
|
import org.junit.runner.RunWith;
|
20
|
import org.openqa.selenium.WebDriver;
|
21
|
import org.openqa.selenium.chrome.ChromeDriver;
|
22
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
23
|
import org.openqa.selenium.firefox.FirefoxProfile;
|
24
|
import org.openqa.selenium.ie.InternetExplorerDriver;
|
25
|
|
26
|
import eu.etaxonomy.dataportal.Browser;
|
27
|
import eu.etaxonomy.dataportal.DataPortalContextAwareRunner;
|
28
|
|
29
|
/**
|
30
|
* @author a.kohlbecker
|
31
|
*
|
32
|
*/
|
33
|
@RunWith(DataPortalContextAwareRunner.class)
|
34
|
public abstract class CdmDataPortalTestBase {
|
35
|
|
36
|
public static final Logger logger = Logger.getLogger(CdmDataPortalTestBase.class);
|
37
|
|
38
|
private static final String SYSTEM_PROPERTY_NAME_BROWSER = "browser";
|
39
|
|
40
|
private static final String FIREBUG_VERSION = "1.6.2";
|
41
|
|
42
|
protected static WebDriver driver;
|
43
|
|
44
|
@BeforeClass
|
45
|
public static void setUpDriver() {
|
46
|
Browser browser = Browser.valueOf(System.getProperty(
|
47
|
SYSTEM_PROPERTY_NAME_BROWSER, Browser.firefox.name()));
|
48
|
if (browser == null) {
|
49
|
throw new RuntimeException("Invalid system property: '"
|
50
|
+ System.getProperty(SYSTEM_PROPERTY_NAME_BROWSER) + "'");
|
51
|
}
|
52
|
logger.info("Using browser " + browser.name());
|
53
|
switch (browser) {
|
54
|
case firefox:
|
55
|
driver = initFirefoxDriver();
|
56
|
break;
|
57
|
case chrome:
|
58
|
driver = initChromeDriver();
|
59
|
break;
|
60
|
case iexplorer:
|
61
|
driver = initInternetExplorerDriver();
|
62
|
break;
|
63
|
}
|
64
|
|
65
|
}
|
66
|
|
67
|
@AfterClass
|
68
|
public static void closeDriver() {
|
69
|
if (driver != null) {
|
70
|
driver.quit();
|
71
|
}
|
72
|
}
|
73
|
|
74
|
public static WebDriver initChromeDriver() {
|
75
|
// System.setProperty("webdriver.chrome.bin",
|
76
|
// "C:\\Dokumente und Einstellungen\\a.kohlbecker.BGBM\\Lokale Einstellungen\\Anwendungsdaten\\Google\\Chrome\\Application\\chrome.exe");
|
77
|
return new ChromeDriver();
|
78
|
}
|
79
|
|
80
|
public static WebDriver initInternetExplorerDriver() {
|
81
|
return new InternetExplorerDriver();
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
|
86
|
*
|
87
|
* See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
|
88
|
*
|
89
|
* @return
|
90
|
*/
|
91
|
public static WebDriver initFirefoxDriver() {
|
92
|
// System.setProperty("webdriver.firefox.bin",
|
93
|
// "C:\\Programme\\Mozilla Firefox 3\\firefox.exe");
|
94
|
// System.out.println("##:" +
|
95
|
// System.getProperty("webdriver.firefox.bin"));
|
96
|
FirefoxProfile firefoxProfile = new FirefoxProfile();
|
97
|
try {
|
98
|
|
99
|
firefoxProfile.addExtension(CdmDataPortalTestBase.class,
|
100
|
"/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
|
101
|
firefoxProfile.setPreference("extensions.firebug.currentVersion",
|
102
|
FIREBUG_VERSION); // avoid displaying firt run page
|
103
|
|
104
|
// --- allow enabling incompatible addons
|
105
|
// firefoxProfile.addExtension(this.getClass(),
|
106
|
// "/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi");
|
107
|
// firefoxProfile.setPreference("extensions.acr.firstrun", false);
|
108
|
// firefoxProfile.setPreference("extensions.enabledAddons",
|
109
|
// "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",
|
111
|
// false);
|
112
|
// firefoxProfile.setPreference("extensions.checkCompatibility.4.0",
|
113
|
// false);
|
114
|
// firefoxProfile.setPreference("extensions.checkCompatibility.4.1",
|
115
|
// false);
|
116
|
|
117
|
} catch (IOException e) {
|
118
|
// TODO Auto-generated catch block
|
119
|
e.printStackTrace();
|
120
|
System.exit(-1);
|
121
|
}
|
122
|
driver = new FirefoxDriver(firefoxProfile);
|
123
|
|
124
|
return driver;
|
125
|
}
|
126
|
|
127
|
}
|