Project

General

Profile

Download (4.66 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.dataportal.selenium;
5

    
6
import java.io.IOException;
7
import java.util.concurrent.TimeUnit;
8

    
9
import org.apache.log4j.Logger;
10
import org.openqa.selenium.WebDriver;
11
import org.openqa.selenium.chrome.ChromeDriver;
12
import org.openqa.selenium.firefox.FirefoxBinary;
13
import org.openqa.selenium.firefox.FirefoxDriver;
14
import org.openqa.selenium.firefox.FirefoxProfile;
15
import org.openqa.selenium.ie.InternetExplorerDriver;
16

    
17
import eu.etaxonomy.dataportal.Browser;
18
import eu.etaxonomy.dataportal.DataPortalContext;
19
import eu.etaxonomy.dataportal.SystemUtils;
20
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
21

    
22
/**
23
 * @author andreas
24
 *
25
 */
26
public class WebDriverFactory {
27

    
28

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

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

    
33
    private static final String FIREBUG_VERSION = "1.10.5";
34
    private static final String FIREXPATH_VERSION = "0.9.7";
35
    private static final String DISABLE_ADD_ON_COMPATIBILITY_CHECKS_VERSION = "1.3";
36

    
37
    private static final long IMPLICIT_WAIT_DEFAULT = 5;
38

    
39

    
40
    public static WebDriver newWebDriver() {
41

    
42
        WebDriver newDriver = null;
43
        try {
44
            Browser browser = Browser.valueOf(System.getProperty(SYSTEM_PROPERTY_NAME_BROWSER, Browser.firefox.name()));
45

    
46
            logger.info("Using browser: " + browser.name());
47
            switch (browser) {
48
            case firefox:
49
                newDriver = initFirefoxDriver();
50
                break;
51
            case chrome:
52
                newDriver = initChromeDriver();
53
                break;
54
            case iexplorer:
55
                newDriver = initInternetExplorerDriver();
56
                break;
57
            }
58

    
59
        } catch (NullPointerException e) {
60
            SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
61
        } catch (IllegalArgumentException e) {
62
            SystemUtils.handleInvalidSystemProperty(SYSTEM_PROPERTY_NAME_BROWSER, e);
63
        }
64

    
65
//        newDriver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_DEFAULT, TimeUnit.SECONDS);
66
//        logger.info("Implicit wait set to : " + IMPLICIT_WAIT_DEFAULT + " " + TimeUnit.SECONDS);
67

    
68
        return newDriver;
69
    }
70

    
71

    
72
    private static WebDriver initChromeDriver() {
73
        return new ChromeDriver();
74
    }
75

    
76
    private static WebDriver initInternetExplorerDriver() {
77
        return new InternetExplorerDriver();
78
    }
79

    
80
    /**
81
     * -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
82
     *
83
     * See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
84
     *
85
     * @return
86
     */
87
    private static WebDriver initFirefoxDriver() {
88

    
89
        WebDriver driver;
90

    
91
        CdmDataPortalTestBase.logger.info(("webdriver.firefox.bin = " + System.getProperty("webdriver.firefox.bin")));
92
        CdmDataPortalTestBase.logger.info(("webdriver.firefox.library.path = " + System.getProperty("webdriver.firefox.library.path")));
93

    
94
        FirefoxProfile firefoxProfile = new FirefoxProfile();
95

    
96
        boolean addons = true;
97

    
98
        if(addons){
99
            try {
100
                firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/disable_add_on_compatibility_checks-" + DISABLE_ADD_ON_COMPATIBILITY_CHECKS_VERSION + ".xpi");
101
                firefoxProfile.setPreference("extensions.checkCompatibility", "false");
102

    
103
//                CdmDataPortalTestBase.logger.debug("FirefoxProfile: " + firefoxProfile.getClass().getSimpleName() + "(" + firefoxProfile.hashCode() + ")");
104
//                firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firebug-" + FIREBUG_VERSION + ".xpi");
105
//                firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION); // avoid displaying first run page
106
//
107
//                firefoxProfile.addExtension(CdmDataPortalTestBase.class, "/org/mozilla/addons/firepath-" + FIREXPATH_VERSION + "-fx.xpi");
108

    
109
            } catch (IOException e) {
110
                CdmDataPortalTestBase.logger.error(e);
111
                System.exit(-1);
112
            }
113
        }
114

    
115
        // NativeEvents can only be used with official binary releases of firefox !!!
116
        // firefoxProfile.setEnableNativeEvents(true);
117
        // see http://groups.google.com/group/webdriver/browse_thread/thread/ab68c413f17ae1ba/b5cbdcebe859aa56?lnk=gst&q=setEnableNativeEvents+firefox#msg_339ac1870da6d975
118

    
119
        driver = new FirefoxDriver(firefoxProfile);
120

    
121
        return driver;
122
    }
123

    
124
     public static void main(String[] args){
125

    
126
         initFirefoxDriver();
127
         try {
128
            Thread.currentThread().sleep(1000);
129
        } catch (InterruptedException e) {
130
            System.err.println("InterruptedException");
131
        }
132

    
133
    }
134

    
135

    
136

    
137

    
138
}
(7-7/7)