From e58dd736c7f3bad93631a9c307c91af653d442cc Mon Sep 17 00:00:00 2001 From: Mark Collin Date: Thu, 14 Mar 2013 10:29:04 +0000 Subject: [PATCH] Reverted back to Selenium 2.30.0 to fix #2 --- pom.xml | 26 +- .../com/lazerycode/selenium/BrowserType.java | 30 +-- .../com/lazerycode/selenium/SeleniumBase.java | 235 +++++++++--------- .../selenium/Tests/Selenium2ExampleST.java | 72 +++--- 4 files changed, 183 insertions(+), 180 deletions(-) diff --git a/pom.xml b/pom.xml index 7aa1ecdf..ced8d9ff 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ org.seleniumhq.selenium selenium-server - 2.31.0 + 2.30.0 test @@ -110,18 +110,6 @@ selenium-tests - - org.apache.maven.plugins - maven-surefire-plugin - 2.13 - - - **/*ST.java - - methods - ${threads} - - com.lazerycode.selenium driver-binary-downloader-maven-plugin @@ -139,6 +127,18 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.7.2 + + + **/*ST.java + + methods + ${threads} + + diff --git a/src/test/java/com/lazerycode/selenium/BrowserType.java b/src/test/java/com/lazerycode/selenium/BrowserType.java index 5fdd93cd..82450f55 100644 --- a/src/test/java/com/lazerycode/selenium/BrowserType.java +++ b/src/test/java/com/lazerycode/selenium/BrowserType.java @@ -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; + } } diff --git a/src/test/java/com/lazerycode/selenium/SeleniumBase.java b/src/test/java/com/lazerycode/selenium/SeleniumBase.java index 85368b59..026e6840 100644 --- a/src/test/java/com/lazerycode/selenium/SeleniumBase.java +++ b/src/test/java/com/lazerycode/selenium/SeleniumBase.java @@ -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; @@ -19,135 +20,137 @@ 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() { + 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; - } + @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 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"); - } + 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 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"); } - 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)); } + } } diff --git a/src/test/java/com/lazerycode/selenium/Tests/Selenium2ExampleST.java b/src/test/java/com/lazerycode/selenium/Tests/Selenium2ExampleST.java index efe3899a..44bb6928 100644 --- a/src/test/java/com/lazerycode/selenium/Tests/Selenium2ExampleST.java +++ b/src/test/java/com/lazerycode/selenium/Tests/Selenium2ExampleST.java @@ -1,7 +1,7 @@ package com.lazerycode.selenium.Tests; -import com.lazerycode.selenium.SeleniumBase; import com.lazerycode.selenium.ScreenshotListener; +import com.lazerycode.selenium.SeleniumBase; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -49,39 +49,39 @@ public Boolean apply(WebDriver d) { System.out.println("Page title is: " + driver.getTitle()); } - @Test - public void googleMilkExample() { - // Create a new WebDriver instance - // Notice that the remainder of the code relies on the interface, - // not the implementation. - WebDriver driver = getDriver(); - - // And now use this to visit Google - driver.get("http://www.google.com"); - // Alternatively the same thing can be done like this - // driver.navigate().to("http://www.google.com"); - - // Find the text input element by its name - WebElement element = driver.findElement(By.name("q")); - - // Enter something to search for - element.sendKeys("Milk!"); - - // Now submit the form. WebDriver will find the form for us from the element - element.submit(); - - // Check the title of the page - System.out.println("Page title is: " + driver.getTitle()); - - // Google's search is rendered dynamically with JavaScript. - // Wait for the page to load, timeout after 10 seconds - (new WebDriverWait(driver, 10)).until(new ExpectedCondition() { - public Boolean apply(WebDriver d) { - return d.getTitle().toLowerCase().startsWith("milk!"); - } - }); - - // Should see: "cheese! - Google Search" - System.out.println("Page title is: " + driver.getTitle()); - } + @Test + public void googleMilkExample() { + // Create a new WebDriver instance + // Notice that the remainder of the code relies on the interface, + // not the implementation. + WebDriver driver = getDriver(); + + // And now use this to visit Google + driver.get("http://www.google.com"); + // Alternatively the same thing can be done like this + // driver.navigate().to("http://www.google.com"); + + // Find the text input element by its name + WebElement element = driver.findElement(By.name("q")); + + // Enter something to search for + element.sendKeys("Milk!"); + + // Now submit the form. WebDriver will find the form for us from the element + element.submit(); + + // Check the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + // Google's search is rendered dynamically with JavaScript. + // Wait for the page to load, timeout after 10 seconds + (new WebDriverWait(driver, 10)).until(new ExpectedCondition() { + public Boolean apply(WebDriver d) { + return d.getTitle().toLowerCase().startsWith("milk!"); + } + }); + + // Should see: "cheese! - Google Search" + System.out.println("Page title is: " + driver.getTitle()); + } } \ No newline at end of file