gilt groupe's selenium 2 conversion challenges
DESCRIPTION
See some of the lessons learned by Gilt Groupe as they converted from Selenium 1 to Selenium 2.TRANSCRIPT
Findings and Challenges
Background Tools Past Challenges “The Decision” Benefits Conversion Present Examples
Custom framework written in Java In house test management system
TestElements ▪ Projects ▪ Test Suites Test Cases Actions Data Elements Object Store
Fully integrated with our Framework
Eclipse IDE TestElements Results Viewer
+ iPad version SauceLabs SeleniumIDE
Firebug Ivy Git -‐ version control
Selenium 1 & Selenium Grid 6 lab machines ▪ Mac’s and PCs with different browser combinations
RC for each desired browser on local machines RC for each desired browser on each remote machine running on SeleniumGrid
Maintenance of RC’s If 1 RC had an issue, must kill all RC’s, restart HUB, and restart each one again
> 800 test cases executed amongst 6 machines multiple times a day ▪ (approx. 2500/day)
Parallel execution was challenging Cross browser testing
Solved every challenge on the list Selenium RC’s in the cloud
No maintenance Video Replaced Selenium with WebDriverBackedSelenium Selenium 1 backwards compatible
New code would use WebDriver
WebDriverBackedSelenium on Sauce Each selenium 1 command would spit back javascript, causing very slow test execution times
WebDriver commands were OK Did not realize this right away Santiago the ‘Sauce Ninja’
Convert EVERYTHING… No more XPATH!
CSS_SELECTOR ▪ Native support on each browser
ID LINK_TEXT
Improve execution speed on Sauce (no more JavaScript)
Better emulation of user interactions Better API – More object oriented Stability Improve logic in codebase Don’t want to be left behind New version of Selenium all the time
Bug fixes, improvements Feel they care about the product
Fun
Line by Line conversion remove any selenium1 references
Not enough documentation existed Not everything appeared to be easily converted hover / mouseOver select from combo box attachFile
Different functionality Objects must be visible before acting on them Type mechanism does not clear the text field before filling it out * changed in 2.6
Selenium2 is blocking ▪ No more waitForPageToLoad(….)
Use ExpectedCondition class to wait for presence / visibility of element
Different names no more isElementPresent / isVisible
Simplify codebase Find Selenium2 conversion for everything and create wrapper in our Framework
SeleniumBase.java was born Custom WebDriver commands All scripts extend from this class Less clutter Maintainability
public WebDriver getWebDriver() { return webDriver;}public WebElement getWebElement(LocatorType locatorType, String locator) throws Exception { return getWebDriver().findElement(by(locatorType, locator));}public List<WebElement> getWebElements(LocatorType locatorType, String locator) throws Exception { return getWebDriver().findElements(by(locatorType, locator));}public boolean isElementPresent(LocatorType locatorType, String locator) throws Exception { return getWebElements(locatorType,locator).size() > 0;}public boolean isVisible(LocatorType locatorType, String locator) throws Exception { return getWebElement(locatorType,locator).isDisplayed();}public void waitForElementPresent(final LocatorType locatorType, final String locator) throws Exception { getWait().until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { try { return isElementPresent(locatorType, locator); } catch (Exception e) { return false; } } });}
public void clearAndSendKeys(LocatorType locatorType, String locator, String keys) throws Exception { getWebElement(locatorType, locator).clear(); getWebElement(locatorType, locator).sendKeys(keys);}public void check(LocatorType locatorType, String locator) throws Exception { if(!getWebElement(locatorType, locator).isSelected()) getWebElement(locatorType, locator).click();}public void mouseOver(LocatorType locatorType, String locator) throws Exception{ Actions action = new Actions(getWebDriver()); action.moveToElement(getWebElement(locatorType, locator)).perform();}public void selectComboBoxByVisibleText(LocatorType locatorType, String locator, String value) throws
Exception{ Select comboBox = new Select(getWebElement(locatorType, locator)); comboBox.selectByVisibleText(value);}public void switchToWindow(String windowTitle){ Set<String> windowHandles = getWebDriver().getWindowHandles();
Iterator<String> iter = windowHandles.iterator();
while(iter.hasNext()){ String currentWindowHandle = iter.next(); getWebDriver().switchTo().window(currentWindowHandle); if(getWebDriver().getTitle().equals(windowTitle)) break;
}}
clearAndSendKeys(LocatorType.ID,"Gilt Login Page","Email Address Text Field”,emailAddress);clearAndSendKeys(LocatorType.ID,"Gilt Login Page","Password Text Field”,password);getWebElement(LocatorType.ID,"Gilt Login Page","Sign In Button").click();
waitForElementPresentAndVisible(LocatorType.CSS_SELECTOR,"Gilt Carousel Bar","Selected Tab");mouseOver(LocatorType.CSS_SELECTOR,"Gilt Carousel Bar","Selected Tab");List<WebElement> saleTitle = getWebElements(LocatorType.CSS_SELECTOR,"Gilt Carousel Bar","Selected Tab Sale Links");
List<WebElement> productLookTitleAll = getWebElements(LocatorType.CSS_SELECTOR,"Gilt Product Listing Page","Product Look Title Links");List<WebElement> productLookTitleAvailable = getWebElements(LocatorType.CSS_SELECTOR,"Gilt Product Listing Page","Available Product Look Title Links");List<WebElement> productLookSoldOut = getWebElements(LocatorType.CSS_SELECTOR,"Gilt Product Listing Page","Sold Out Product Look Title Links");
99.9999% converted to Selenium2 ▪ attachFile()
Stable results Clean, easy to manage code SeleniumBase continues to grow Ivy to manage dependencies
Upgrade to Selenium 2.x quickly Push changes to team through Git
Make the switch Spread the work out to save time
Be aware of the differences b/t Sel1 and Sel2 More documentation
Modularize common selenium commands Selenium Users google group
Question??? Comments….
Email: [email protected] Invitation: http://www.gilt.com/invite/josesanchez