Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
23   116   10   2.88
4   92   0.43   8
8     1.25  
1    
 
 
  SeleniumManager       Line # 17 23 10 0% 0.0
 
No Tests
 
1    package org.itracker.selenium;
2   
3    import com.thoughtworks.selenium.DefaultSelenium;
4    import com.thoughtworks.selenium.Selenium;
5    import java.io.IOException;
6    import java.io.InputStream;
7    import java.util.Properties;
8   
9    import com.thoughtworks.selenium.SeleniumException;
10    import org.apache.log4j.Logger;
11    import org.jfree.util.Log;
12   
13    /**
14    *
15    * @author Andrey Sergievskiy <seas@andreysergievskiy.com>
16    */
 
17    public class SeleniumManager {
18    private final static String PROPERTY_SELENIUM_BROWSER = "selenium.browser";
19    private final static String PROPERTY_SELENIUM_HOST = "selenium.host";
20    private final static String PROPERTY_SELENIUM_PORT = "selenium.port";
21    private final static String PROPERTY_APPLICATION_HOST = "application.host";
22    private final static String PROPERTY_APPLICATION_PORT = "application.port";
23    private final static String PROPERTY_APPLICATION_PATH = "application.path";
24   
25    private static Selenium selenium = null;
26   
27    private static String seleniumHost = null;
28    private static int seleniumPort = 4444;
29    private static String seleniumBrowser = null;
30    private static String applicationHost = null;
31    private static int applicationPort = 8080;
32    private static String applicationPath = null;
33   
34    private static final Logger log = Logger.getLogger(SeleniumManager.class);
35   
 
36    toggle static {
37    Runtime.getRuntime().addShutdownHook(new Thread() {
 
38    toggle @Override
39    public void run() {
40    if (null != SeleniumManager.selenium) {
41    try {
42    SeleniumManager.selenium.stop();
43    } catch (SeleniumException e) {
44    log.warn("could not stop running selenium: " + selenium);
45    log.debug("exception caught", e);
46    }
47   
48    }
49    }
50    });
51    }
52   
 
53  0 toggle public static Selenium getSelenium() throws IOException {
54  0 if (null == selenium) {
55  0 log.info("starting new selenium");
56  0 final InputStream inputStream = SeleniumManager.class
57    .getResourceAsStream("SeleniumManager.properties");
58  0 final Properties properties = new Properties();
59  0 properties.load(inputStream);
60  0 seleniumBrowser =
61    properties.getProperty(PROPERTY_SELENIUM_BROWSER, "*firefox");
62  0 seleniumHost =
63    properties.getProperty(PROPERTY_SELENIUM_HOST, "localhost");
64  0 seleniumPort =
65    Integer.valueOf(properties.getProperty(PROPERTY_SELENIUM_PORT, "5555"));
66  0 applicationHost =
67    properties.getProperty(PROPERTY_APPLICATION_HOST, "localhost");
68  0 applicationPort =
69    Integer.valueOf(properties.getProperty(PROPERTY_APPLICATION_PORT, "8888"));
70  0 applicationPath =
71    properties.getProperty(PROPERTY_APPLICATION_PATH, "itracker");
72  0 selenium = new DefaultSelenium(seleniumHost, seleniumPort,
73    seleniumBrowser,
74    "http://" + applicationHost + ":" + applicationPort + "/"
75    + applicationPath);
76  0 selenium.start();
77    }
78  0 return selenium;
79    }
80   
81    /**
82    * This will initialize a new selenium session for this test scope.
83    */
 
84  0 toggle protected static void closeSession(Selenium selenium) {
85  0 if (log.isDebugEnabled()) {
86  0 log.debug("closeSession: " + selenium);
87    }
88  0 selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
89    + applicationPath + "/logoff.do");
90   
91    }
92   
 
93  0 toggle public static String getSeleniumHost() {
94  0 return seleniumHost;
95    }
96   
 
97  0 toggle public static int getSeleniumPort() {
98  0 return seleniumPort;
99    }
100   
 
101  0 toggle public static String getSeleniumBrowser() {
102  0 return seleniumBrowser;
103    }
104   
 
105  0 toggle public static String getApplicationHost() {
106  0 return applicationHost;
107    }
108   
 
109  0 toggle public static int getApplicationPort() {
110  0 return applicationPort;
111    }
112   
 
113  0 toggle public static String getApplicationPath() {
114  0 return applicationPath;
115    }
116    }