| 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 |
| 16 |
|
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 10 |
Complexity Density: 0.43 |
|
| 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 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 36 |
|
static {... |
| 37 |
|
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 38 |
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
| 53 |
0
|
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 |
|
|
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 84 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
0
|
public static String getSeleniumHost() {... |
| 94 |
0
|
return seleniumHost; |
| 95 |
|
} |
| 96 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
0
|
public static int getSeleniumPort() {... |
| 98 |
0
|
return seleniumPort; |
| 99 |
|
} |
| 100 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
0
|
public static String getSeleniumBrowser() {... |
| 102 |
0
|
return seleniumBrowser; |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
0
|
public static String getApplicationHost() {... |
| 106 |
0
|
return applicationHost; |
| 107 |
|
} |
| 108 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 109 |
0
|
public static int getApplicationPort() {... |
| 110 |
0
|
return applicationPort; |
| 111 |
|
} |
| 112 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 113 |
0
|
public static String getApplicationPath() {... |
| 114 |
0
|
return applicationPath; |
| 115 |
|
} |
| 116 |
|
} |