From eb56e572aa3755048d67757799455a5619e7cd82 Mon Sep 17 00:00:00 2001 From: Mark Collin Date: Tue, 14 Jan 2014 09:40:12 +0000 Subject: [PATCH] Updated to use Selenium 2.39.0 Updated to use driver-binary-downloader-maven-plugin 1.0.0 Now supports ghostdriver with no additional downloads --- RepositoryMap.xml | 66 +++-- pom.xml | 8 +- .../com/lazerycode/selenium/SeleniumBase.java | 271 +++++++++--------- 3 files changed, 197 insertions(+), 148 deletions(-) diff --git a/RepositoryMap.xml b/RepositoryMap.xml index 01993883..6ca5459a 100644 --- a/RepositoryMap.xml +++ b/RepositoryMap.xml @@ -2,24 +2,33 @@ - + - https://selenium.googlecode.com/files/IEDriverServer_x64_2.35.3.zip - 55bbd8f9034753a1cd2ca019b64692df835b56fb + https://selenium.googlecode.com/files/IEDriverServer_x64_2.39.0.zip + c7ffa258de34d0934120b269a5af76e14a62d2d4 sha1 - https://selenium.googlecode.com/files/IEDriverServer_Win32_2.35.3.zip - 38b48b706267cfb5d4c5694c64481d9deeff7076 + https://selenium.googlecode.com/files/IEDriverServer_Win32_2.39.0.zip + 71b8fad1dadc72a1b7e45ade3f5c3f72d4f02def sha1 - + - http://chromedriver.storage.googleapis.com/2.4/chromedriver_win32.zip - 79a1eb1320e25b3666adeab87dac5173216e9956 + http://chromedriver.storage.googleapis.com/2.8/chromedriver_win32.zip + 2e5ec89661e528bf69f717953896d85896ca64db + sha1 + + + + + + + https://phantomjs.googlecode.com/files/phantomjs-1.9.2-windows.zip + 5fcfb32d9df9e603a3980139026bc33d516dae01 sha1 @@ -27,15 +36,31 @@ - + + + http://chromedriver.storage.googleapis.com/2.8/chromedriver_linux64.zip + 33112f4484145bd0bb8100bac7670d8c45793a4b + sha1 + + + http://chromedriver.storage.googleapis.com/2.8/chromedriver_linux32.zip + f3743b625e5466a82fb0e433611190588fa07357 + sha1 + + + + + - http://chromedriver.storage.googleapis.com/2.4/chromedriver_linux64.zip - 0bb42841124ee10ef83599c26f95843bb9ceb029 + https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2 + + c78c4037d98fa893e66fc516214499c58228d2f9 sha1 - http://chromedriver.storage.googleapis.com/2.4/chromedriver_linux32.zip - 7b5336993c794b4ad40363290c5516eedaf80e07 + https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-i686.tar.bz2 + + 9ead5dd275f79eaced61ce63dbeca58be4d7f090 sha1 @@ -43,10 +68,19 @@ - + + + http://chromedriver.storage.googleapis.com/2.8/chromedriver_mac32.zip + b44d4666d00531f9edc5f1e89534a789fb4ec162 + sha1 + + + + + - http://chromedriver.storage.googleapis.com/2.4/chromedriver_mac32.zip - b78a808c083fe17215069c9d0ff0e6b6455d8964 + https://phantomjs.googlecode.com/files/phantomjs-1.9.2-macosx.zip + 36357dc95c0676fb4972420ad25455f49a8f3331 sha1 diff --git a/pom.xml b/pom.xml index 9b1e2306..8944895f 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ org.seleniumhq.selenium selenium-server - 2.35.0 + 2.39.0 test @@ -60,7 +60,7 @@ com.opera operadriver - 0.18 + 1.5 test @@ -72,7 +72,7 @@ com.github.detro.ghostdriver phantomjsdriver - 1.0.4 + 1.1.0 test @@ -119,7 +119,7 @@ com.lazerycode.selenium driver-binary-downloader-maven-plugin - 0.9.2 + 1.0.0 ${standalone.binary.root.folder} ${project.basedir}/selenium_standalone_zips diff --git a/src/test/java/com/lazerycode/selenium/SeleniumBase.java b/src/test/java/com/lazerycode/selenium/SeleniumBase.java index e6cf66a0..d7031e21 100644 --- a/src/test/java/com/lazerycode/selenium/SeleniumBase.java +++ b/src/test/java/com/lazerycode/selenium/SeleniumBase.java @@ -21,142 +21,157 @@ public class SeleniumBase { - private static ResourceBundle _prop = ResourceBundle.getBundle("dev"); - private static BrowserType browserType; - private static List webDrivers = Collections.synchronizedList(new ArrayList()); - private static ThreadLocal driverForThread = new ThreadLocal() { - - @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; - } + private static ResourceBundle _prop = ResourceBundle.getBundle("dev"); + private static BrowserType browserType; + private static List webDrivers = Collections.synchronizedList(new ArrayList()); + private static ThreadLocal driverForThread = new ThreadLocal() { + + @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; + } } - if (browserType == null) { - System.err.println("Unknown browser specified, defaulting to 'Firefox'..."); - browserType = FIREFOX; + + @AfterSuite + public static void tearDown() { + for (WebDriver driver : webDrivers) { + driver.quit(); + } } - } - @AfterSuite - public static void tearDown() { - for (WebDriver driver : webDrivers) { - driver.quit(); + @AfterMethod + public static void clearCookies() { + getDriver().manage().deleteAllCookies(); } - } - - @AfterMethod - public static void clearCookies() { - getDriver().manage().deleteAllCookies(); - } - - protected static WebDriver getDriver() { - return driverForThread.get(); - } - - private static DesiredCapabilities generateDesiredCapabilities(BrowserType capabilityType) { - DesiredCapabilities capabilities; - - switch (capabilityType) { - case IE: - capabilities = DesiredCapabilities.internetExplorer(); - capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); - capabilities.setCapability(InternetExplorerDriver.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 chromePreferences = new HashMap(); - 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"); + + protected static WebDriver getDriver() { + return driverForThread.get(); } - return capabilities; - } - - 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); - - //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/2.4/chromedriver.exe"); - } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) { - System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/64bit/2.4/chromedriver"); - } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) { - System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/64bit/2.4/chromedriver"); - } - } else { - if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) { - System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/windows/googlechrome/32bit/2.4/chromedriver.exe"); - } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) { - System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/32bit/2.4/chromedriver"); - } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) { - System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/32bit/2.4/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"); + private static DesiredCapabilities generateDesiredCapabilities(BrowserType capabilityType) { + DesiredCapabilities capabilities; + + switch (capabilityType) { + case IE: + capabilities = DesiredCapabilities.internetExplorer(); + capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); + capabilities.setCapability(InternetExplorerDriver.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); + 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")) { + capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/windows/phantomjs/64bit/1.9.2/phantomjs.exe"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) { + capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/osx/phantomjs/64bit/1.9.2/phantomjs"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) { + capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/linux/phantomjs/64bit/1.9.2/phantomjs"); + } + } else { + if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) { + capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/windows/phantomjs/32bit/1.9.2/phantomjs.exe"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) { + capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/osx/phantomjs/32bit/1.9.2/phantomjs"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) { + capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, _prop.getString("binaryRootFolder") + "/linux/phantomjs/32bit/1.9.2/phantomjs"); + } + } + break; + case CHROME: + capabilities = DesiredCapabilities.chrome(); + capabilities.setCapability("chrome.switches", Arrays.asList("--no-default-browser-check")); + HashMap chromePreferences = new HashMap(); + 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"); } - break; + + return capabilities; } - //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)); + 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); + + //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/2.8/chromedriver.exe"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) { + System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/64bit/2.8/chromedriver"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) { + System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/64bit/2.8/chromedriver"); + } + } else { + if (System.getProperties().getProperty("os.name").toLowerCase().contains("windows")) { + System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/windows/googlechrome/32bit/2.8/chromedriver.exe"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("mac")) { + System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/osx/googlechrome/32bit/2.8/chromedriver"); + } else if (System.getProperties().getProperty("os.name").toLowerCase().contains("linux")) { + System.setProperty("webdriver.chrome.driver", _prop.getString("binaryRootFolder") + "/linux/googlechrome/32bit/2.8/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.39.0/IEDriverServer.exe"); + } else { + System.setProperty("webdriver.ie.driver", _prop.getString("binaryRootFolder") + "/windows/internetexplorer/32bit/2.39.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)); + } } - } }