Revision a740abba
Added by Andreas Kohlbecker almost 13 years ago
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
import java.io.IOException; |
7 | 7 |
|
8 |
import org.apache.log4j.Logger; |
|
8 | 9 |
import org.junit.AfterClass; |
9 |
import org.junit.BeforeClass; |
|
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 |
*/ |
|
10 | 19 |
import org.junit.runner.RunWith; |
11 | 20 |
import org.openqa.selenium.WebDriver; |
12 | 21 |
import org.openqa.selenium.chrome.ChromeDriver; |
... | ... | |
14 | 23 |
import org.openqa.selenium.firefox.FirefoxProfile; |
15 | 24 |
import org.openqa.selenium.ie.InternetExplorerDriver; |
16 | 25 |
|
26 |
import eu.etaxonomy.dataportal.Browser; |
|
17 | 27 |
import eu.etaxonomy.dataportal.DataPortalContextAwareRunner; |
18 | 28 |
|
19 | 29 |
/** |
20 | 30 |
* @author a.kohlbecker |
21 |
* |
|
31 |
*
|
|
22 | 32 |
*/ |
23 | 33 |
@RunWith(DataPortalContextAwareRunner.class) |
24 | 34 |
public abstract class CdmDataPortalTestBase { |
25 | 35 |
|
36 |
public static final Logger logger = Logger.getLogger(CdmDataPortalTestBase.class); |
|
37 |
|
|
38 |
private static final String SYSTEM_PROPERTY_NAME_BROWSER = "browser"; |
|
39 |
|
|
26 | 40 |
private static final String FIREBUG_VERSION = "1.6.2"; |
27 | 41 |
|
28 | 42 |
protected static WebDriver driver; |
29 | 43 |
|
30 |
@BeforeClass |
|
31 |
public static void setUpDriver() { |
|
32 |
driver = initFirefoxDriver(); |
|
33 |
} |
|
34 |
|
|
35 |
|
|
36 |
@AfterClass |
|
37 |
public static void closeDriver() { |
|
38 |
if(driver != null){ |
|
39 |
driver.quit(); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
public WebDriver initChromeDriver() { |
|
44 |
//System.setProperty("webdriver.chrome.bin", "C:\\Dokumente und Einstellungen\\a.kohlbecker.BGBM\\Lokale Einstellungen\\Anwendungsdaten\\Google\\Chrome\\Application\\chrome.exe"); |
|
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"); |
|
45 | 77 |
return new ChromeDriver(); |
46 | 78 |
} |
47 |
|
|
48 |
public WebDriver initInternetExplorerDriver() { |
|
79 |
|
|
80 |
public static WebDriver initInternetExplorerDriver() {
|
|
49 | 81 |
return new InternetExplorerDriver(); |
50 | 82 |
} |
51 |
|
|
83 |
|
|
52 | 84 |
/** |
53 | 85 |
* -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin |
54 | 86 |
* |
55 | 87 |
* See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals |
88 |
* |
|
56 | 89 |
* @return |
57 | 90 |
*/ |
58 | 91 |
public static WebDriver initFirefoxDriver() { |
59 |
//System.setProperty("webdriver.firefox.bin", "C:\\Programme\\Mozilla Firefox 3\\firefox.exe"); |
|
60 |
//System.out.println("##:" + System.getProperty("webdriver.firefox.bin")); |
|
92 |
// System.setProperty("webdriver.firefox.bin", |
|
93 |
// "C:\\Programme\\Mozilla Firefox 3\\firefox.exe"); |
|
94 |
// System.out.println("##:" + |
|
95 |
// System.getProperty("webdriver.firefox.bin")); |
|
61 | 96 |
FirefoxProfile firefoxProfile = new FirefoxProfile(); |
62 |
try { |
|
63 |
|
|
64 |
firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi"); |
|
65 |
firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying firt run page |
|
66 |
|
|
67 |
// --- allow enabling incompatible addons |
|
68 |
// firefoxProfile.addExtension(this.getClass(), "/org/mozilla/addons/add_on_compatibility_reporter-0.8.3-fx+tb+sm.xpi"); |
|
69 |
// firefoxProfile.setPreference("extensions.acr.firstrun", false); |
|
70 |
// 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"); |
|
71 |
// firefoxProfile.setPreference("extensions.checkCompatibility", false); |
|
72 |
// firefoxProfile.setPreference("extensions.checkCompatibility.4.0", false); |
|
73 |
// firefoxProfile.setPreference("extensions.checkCompatibility.4.1", false); |
|
74 |
|
|
75 |
} catch (IOException e) { |
|
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) { |
|
76 | 118 |
// TODO Auto-generated catch block |
77 | 119 |
e.printStackTrace(); |
78 | 120 |
System.exit(-1); |
79 | 121 |
} |
80 | 122 |
driver = new FirefoxDriver(firefoxProfile); |
81 |
|
|
82 |
return driver;
|
|
123 |
|
|
124 |
return driver;
|
|
83 | 125 |
} |
84 |
|
|
85 | 126 |
|
86 | 127 |
} |
Also available in: Unified diff
licence comments, log4j, browser configurable via -Dbrowser=[firefox,iexplorer,chrome]