Skip to content

Commit

Permalink
Reverted back to Selenium 2.30.0 to fix Ardesco#2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardesco committed Mar 14, 2013
1 parent d955ab6 commit e58dd73
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 180 deletions.
26 changes: 13 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.31.0</version>
<version>2.30.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -110,18 +110,6 @@
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<includes>
<include>**/*ST.java</include>
</includes>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
</configuration>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
Expand All @@ -139,6 +127,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<includes>
<include>**/*ST.java</include>
</includes>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down
30 changes: 15 additions & 15 deletions src/test/java/com/lazerycode/selenium/BrowserType.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.lazerycode.selenium;

public enum BrowserType {
FIREFOX("firefox"),
CHROME("chrome"),
IE("ie"),
SAFARI("safari"),
OPERA("opera"),
GHOSTDRIVER("ghostdriver"),
REMOTE("remote"),
HTMLUNIT("htmlunit");
FIREFOX("firefox"),
CHROME("chrome"),
IE("ie"),
SAFARI("safari"),
OPERA("opera"),
GHOSTDRIVER("ghostdriver"),
REMOTE("remote"),
HTMLUNIT("htmlunit");

private final String browser;
private final String browser;

BrowserType(String browser) {
this.browser = browser;
}
BrowserType(String browser) {
this.browser = browser;
}

public String getBrowser() {
return browser;
}
public String getBrowser() {
return browser;
}
}
235 changes: 119 additions & 116 deletions src/test/java/com/lazerycode/selenium/SeleniumBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand All @@ -19,135 +20,137 @@

public class SeleniumBase {

private static ResourceBundle _prop = ResourceBundle.getBundle("dev");
private static BrowserType browserType;
private static List<WebDriver> webDrivers = Collections.synchronizedList(new ArrayList<WebDriver>());
private static ThreadLocal<WebDriver> driverForThread = new ThreadLocal<WebDriver>() {
private static ResourceBundle _prop = ResourceBundle.getBundle("dev");
private static BrowserType browserType;
private static List<WebDriver> webDrivers = Collections.synchronizedList(new ArrayList<WebDriver>());
private static ThreadLocal<WebDriver> driverForThread = new ThreadLocal<WebDriver>() {

@Override
protected WebDriver initialValue() {
WebDriver driver = loadWebDriver();
webDrivers.add(driver);
return driver;
}
};

@BeforeSuite
public static void setUpTest() {
for (BrowserType browser : BrowserType.values()) {
if (browser.toString().toLowerCase().equals(_prop.getString("browser").toLowerCase())) {
browserType = browser;
}
}
if (browserType == null) {
System.err.println("Unknown browser specified, defaulting to 'Firefox'...");
browserType = FIREFOX;
}
@Override
protected WebDriver initialValue() {
WebDriver driver = loadWebDriver();
webDrivers.add(driver);
return driver;
}
};

@AfterSuite
public static void tearDown() {
for (WebDriver driver : webDrivers) {
driver.quit();
}
@BeforeSuite
public static void setUpTest() {
for (BrowserType browser : BrowserType.values()) {
if (browser.toString().toLowerCase().equals(_prop.getString("browser").toLowerCase())) {
browserType = browser;
}
}
if (browserType == null) {
System.err.println("Unknown browser specified, defaulting to 'Firefox'...");
browserType = FIREFOX;
}
}

protected static WebDriver getDriver() {
return driverForThread.get();
@AfterSuite
public static void tearDown() {
for (WebDriver driver : webDrivers) {
driver.quit();
}
}

private static DesiredCapabilities generateDesiredCapabilities(BrowserType capabilityType) {
DesiredCapabilities capabilities;
protected static WebDriver getDriver() {
return driverForThread.get();
}

switch (capabilityType) {
case IE:
capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.ENABLE_PERSISTENT_HOVERING, true);
capabilities.setCapability("requireWindowFocus", true);
break;
case SAFARI:
capabilities = DesiredCapabilities.safari();
capabilities.setCapability("safari.cleanSession", true);
break;
case OPERA:
capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.arguments", "-nowin -nomail");
break;
case GHOSTDRIVER:
capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability("takesScreenshot", true);
//Need to set an environmental variable that points to the location of the PhantomJS Binary for GhostDriver support
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, System.getProperty("PHANTOMJS_BINARY"));
break;
case CHROME:
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--no-default-browser-check"));
HashMap<String, String> chromePreferences = new HashMap<String, String>();
chromePreferences.put("profile.password_manager_enabled", "false");
capabilities.setCapability("chrome.prefs", chromePreferences);
break;
case FIREFOX:
capabilities = DesiredCapabilities.firefox();
break;
case HTMLUNIT:
default:
capabilities = DesiredCapabilities.htmlUnit();
capabilities.setCapability("javascriptEnabled", "true");
}
private static DesiredCapabilities generateDesiredCapabilities(BrowserType capabilityType) {
DesiredCapabilities capabilities;

return capabilities;
switch (capabilityType) {
case IE:
capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.ENABLE_PERSISTENT_HOVERING, true);
capabilities.setCapability("requireWindowFocus", true);
break;
case SAFARI:
capabilities = DesiredCapabilities.safari();
capabilities.setCapability("safari.cleanSession", true);
break;
case OPERA:
capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.arguments", "-nowin -nomail");
break;
case GHOSTDRIVER:
capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability("takesScreenshot", true);
//Need to set an environmental variable that points to the location of the PhantomJS Binary for GhostDriver support
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, System.getProperty("PHANTOMJS_BINARY"));
break;
case CHROME:
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--no-default-browser-check"));
HashMap<String, String> chromePreferences = new HashMap<String, String>();
chromePreferences.put("profile.password_manager_enabled", "false");
capabilities.setCapability("chrome.prefs", chromePreferences);
break;
case FIREFOX:
capabilities = DesiredCapabilities.firefox();
break;
case HTMLUNIT:
default:
capabilities = DesiredCapabilities.htmlUnit();
capabilities.setCapability("javascriptEnabled", "true");
}

private static WebDriver loadWebDriver() {
System.out.println("Current Operating System: " + System.getProperties().getProperty("os.name"));
System.out.println("Current Architecture: " + System.getProperties().getProperty("os.arch"));
System.out.println("Current Browser Selection: " + browserType);
return capabilities;
}

//Load standalone executable if required
switch (browserType) {
case CHROME:
if (System.getProperties().getProperty("os.arch").toLowerCase().equals("x86_64") || System.getProperties().getProperty("os.arch").toLowerCase().equals("amd64")) {
if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/windows/googlechrome/64bit/26/chromedriver.exe");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/64bit/26/chromedriver");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/64bit/26/chromedriver");
}
} else {
if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/windows/googlechrome/32bit/26/chromedriver.exe");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/32bit/26/chromedriver");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/32bit/26/chromedriver");
}
}
break;
case IE:
if (System.getProperties().getProperty("os.arch").toLowerCase().equals("x86_64") || System.getProperties().getProperty("os.arch").toLowerCase().equals("amd64")) {
System.setProperty("webdriver.ie.driver", _prop.getString("binaryRootFolder") + "/windows/internetexplorer/64bit/2.29.0/IEDriverServer.exe");
} else {
System.setProperty("webdriver.ie.driver", _prop.getString("binaryRootFolder") + "/windows/internetexplorer/32bit/2.29.0/IEDriverServer.exe");
}
break;
}
private static WebDriver loadWebDriver() {
System.out.println("Current Operating System: " + System.getProperties().getProperty("os.name"));
System.out.println("Current Architecture: " + System.getProperties().getProperty("os.arch"));
System.out.println("Current Browser Selection: " + browserType);

//Instantiate driver object
switch (browserType) {
case FIREFOX:
return new FirefoxDriver(generateDesiredCapabilities(browserType));
case CHROME:
return new ChromeDriver(generateDesiredCapabilities(browserType));
case IE:
return new InternetExplorerDriver(generateDesiredCapabilities(browserType));
case SAFARI:
return new SafariDriver(generateDesiredCapabilities(browserType));
case OPERA:
return new OperaDriver(generateDesiredCapabilities(browserType));
default:
return new HtmlUnitDriver(generateDesiredCapabilities(browserType));
//Load standalone executable if required
switch (browserType) {
case CHROME:
if (System.getProperties().getProperty("os.arch").toLowerCase().equals("x86_64") || System.getProperties().getProperty("os.arch").toLowerCase().equals("amd64")) {
if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/windows/googlechrome/64bit/26/chromedriver.exe");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/64bit/26/chromedriver");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/64bit/26/chromedriver");
}
} else {
if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/windows/googlechrome/32bit/26/chromedriver.exe");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/32bit/26/chromedriver");
} else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) {
System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/32bit/26/chromedriver");
}
}
break;
case IE:
if (System.getProperties().getProperty("os.arch").toLowerCase().equals("x86_64") || System.getProperties().getProperty("os.arch").toLowerCase().equals("amd64")) {
System.setProperty("webdriver.ie.driver", _prop.getString("binaryRootFolder") + "/windows/internetexplorer/64bit/2.29.0/IEDriverServer.exe");
} else {
System.setProperty("webdriver.ie.driver", _prop.getString("binaryRootFolder") + "/windows/internetexplorer/32bit/2.29.0/IEDriverServer.exe");
}
break;
}

//Instantiate driver object
switch (browserType) {
case FIREFOX:
return new FirefoxDriver(generateDesiredCapabilities(browserType));
case CHROME:
return new ChromeDriver(generateDesiredCapabilities(browserType));
case IE:
return new InternetExplorerDriver(generateDesiredCapabilities(browserType));
case SAFARI:
return new SafariDriver(generateDesiredCapabilities(browserType));
case OPERA:
return new OperaDriver(generateDesiredCapabilities(browserType));
case GHOSTDRIVER:
return new PhantomJSDriver(generateDesiredCapabilities(browserType));
default:
return new HtmlUnitDriver(generateDesiredCapabilities(browserType));
}
}
}
Loading

0 comments on commit e58dd73

Please sign in to comment.