SlideShare a Scribd company logo
Selenium 2
                          The future of web testing




Tuesday, March 15, 2011
Eric Allen
                               Software Developer, Sauce Labs
                                        @ericpallen
                                    eric@saucelabs.com


                          •   Selenium user for 2+ years
                          •   Selenium contributor
                          •   Developer @ Sauce Labs
                          •   Implemented Selenium 2 for
                              Sauce OnDemand




Tuesday, March 15, 2011
Agenda

                    • Selenium 2 Overview
                    • Side-by-side Examples
                    • Exclusive Selenium 2 Features
                    • Wrap-up
                    • Q & A (Get your questions ready!)

Tuesday, March 15, 2011
Selenium 2 Overview



Tuesday, March 15, 2011
Selenium 2: Why?
                    • Native events
                    • Mobile (iOS Simulator, Android Emulator)
                    • No same-origin freakiness
                    • Better dialog handling
                    • Cleaner API
                    • Future-proof
Tuesday, March 15, 2011
Selenium 2: What?
                    • Object-oriented, native bindings
                          Java, Ruby, C#, Python
                    • Custom browser bindings

                          JavaScript   COM    JavaScript   Native




Tuesday, March 15, 2011
Selenium 2: How?
                                                                     Browser
           Selenium 1:                                               JavaScript      Web
                                                                                     Page
           Your              Selenium             Selenium       Selenium
           tests             RC Client            RC Server        Core           JavaScript


                    native bindings       HTTP
                                                         More HTTP

           Selenium 2:

                             Your tests         Selenium 2         Browser
                                      native bindings    browser-native
                                                            bindings


Tuesday, March 15, 2011
Side-by-side Examples



Tuesday, March 15, 2011
Clicking & Querying
      Selenium 1                                            Selenium 2
      se1.open("http://bing.com/");                         se2.get("http://bing.com/");
      se1.type("q", "Selenium");                            WebElement field = se2.findElement(By.id
      se1.click("go");                                  ("sb_form_q"));
      se1.waitForPageToLoad("30000");                       field.sendKeys("Selenium");
      assert se1.isTextPresent("testing");                  field.submit();
      se1.click("css=li.sa_wr:nth-child(2) h3 a");          assert se2.getPageSource().indexOf("testing") != -1;
      se1.waitForPageToLoad("30000");
      assert se1.getTitle().equals(                         se2.findElements(By.cssSelector("li.sa_wr h3 a"))
          "Selenium web application testing system");           .get(1).click();
                                                            assert se2.getTitle().equals(
                                                                "Selenium web application testing system");




Tuesday, March 15, 2011
Alerts & Confirmations
      Selenium 1                                   Selenium 2
      se1.open("http://svallens.com/selenium/");   se2.get("http://svallens.com/selenium/");
      se1.waitForPageToLoad("30000");              se2.findElement(By.linkText("Alert")).click();
      se1.click("link=Alert");                     se2.switchTo().alert().accept();
      se1.getAlert();                              se2.findElement(By.linkText("Confirm")).click();
      se1.chooseOkOnNextConfirmation();            se2.switchTo().alert().accept();
      se1.click("link=Confirm");                   se2.switchTo().defaultContent();
      se1.getConfirmation();                       assert se2.getPageSource().indexOf("Selenium") != -1;
      se1.refresh();
      assert se1.isTextPresent("Selenium");




Tuesday, March 15, 2011
Navigating Frames
      Selenium 1                                           Selenium 2
    se1.open("http://svallens.com/selenium/seltests/       se2.get("http://svallens.com/selenium/seltests/html/
html/NestedFrames.html");                              NestedFrames.html");
    se1.waitForPageToLoad("30000");                        assert se2.getPageSource().indexOf("This is a test")
    assert !se1.isTextPresent("This is a test");       == -1;
    assert se1.getTitle().equals("NestedFrames");          assert se2.getTitle().equals("NestedFrames");
    assert se1.isElementPresent("id=foo");                 assert se2.findElement(By.id("foo")) != null;


    se1.selectFrame("bottomFrame");                        se2.switchTo().frame("bottomFrame");
    assert se1.getText("id=changeTop").equals              assert se2.findElement(By.id("changeTop")).getText()
("changeTop");                                                 .equals("changeTop");


      se1.selectFrame("relative=top");                     se2.switchTo().defaultContent();
      assert se1.isElementPresent("id=foo");               assert se2.findElement(By.id("foo")) != null;




Tuesday, March 15, 2011
Exclusive Selenium 2
                                Features


Tuesday, March 15, 2011
PageFactory
                        // Create a new instance of a driver
                        WebDriver driver = new HtmlUnitDriver();

                        // Navigate to the right place
                        driver.get("http://www.google.com/");

                        // Create a new instance of the search page class
                        // and initialize any WebElement fields in it.
                        GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class);

                        // And now do the search.
                        page.searchFor("Cheese");




Tuesday, March 15, 2011
User Actions API
                                            (Coming soon!)
                           More   More at http://www.viddler.com/explore/saucelabs/videos/41/

                   ActionChainsGenerator builder = ((HasInputDevices) driver).actionsBuilder();

                     Action dragAndDrop = builder.clickAndHold(someElement)
                         .moveToElement(otherElement)
                         .release(otherElement)
                         .build();

                   dragAndDrop.perform();




Tuesday, March 15, 2011
Should I hurry up and re-
                 write my entire test suite
                      for Selenium 2?


Tuesday, March 15, 2011
Maybe!



Tuesday, March 15, 2011
Selenium 2:Yes!
                    •     Cleaner, leaner API
                    •     No pesky “server” to set up
                    •     Mobile
                    •     Speed
                    •     Improved cross-domain testing
                          Facebook Connect? Sure!
                    •     Future-proof for modal dialogs
                          ✓ Alerts
                          • Authentication
                          • Certificate warnings
                          • File upload/download
Tuesday, March 15, 2011
Selenium 2: No!
                    • Still pre-release quality
                    • Works best in Firefox, other browsers
                          getting there
                    • Completely different API is spotty
                      backwards compatibility layer
                    •     No Selenium IDE
                    •     Selenium RC ain’t goin’ anywhere


Tuesday, March 15, 2011
Selenium 1: It’s hiding
                  • “Selenium 2.0b2” = Selenium 1 + Selenium 2
                  • Since 1.0.3...
                   • Safari CyberVillainsCA
                   • Nicer error messages
                   • Sizzle (jQuery) CSS selectors
                   • Many More!
                           The Selenium 1 inside Selenium 2.0b2
                                IS PRODUCTION QUALITY
Tuesday, March 15, 2011
More Information
   ➡ http://code.google.com/p/selenium/wiki/AdvancedUserInteractions
   ➡ http://code.google.com/p/selenium/wiki/PageFactory
   ➡ https://github.com/epall/selenium-examples


   ➡ http://www.slideshare.net/hugs/selenium-2-webinar-the-next-
     generation-of-web-and-mobile-application-testing
   ➡ http://www.slideshare.net/davehunt82/from-ide-to-selenium-2
   ➡ http://www.slideshare.net/AutomatedTester/selenium-2-the-future-of-
     selenium-is-now
                                Eric Allen
                             Software Developer, Sauce Labs
                                      @ericpallen
                                  eric@saucelabs.com
Tuesday, March 15, 2011

More Related Content

What's hot (15)

PPTX
How to Configure Selenium WebDriver (java)
Dasun Eranthika
 
PDF
Selenium webdriver interview questions and answers
ITeLearn
 
PPTX
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Edureka!
 
PDF
Selenium presentation
P.V.G'S COET, PUNE - 09
 
PPTX
Selenium web driver
Roman Savitskiy
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPTX
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
Edureka!
 
PPTX
Selenium
Batch2016
 
PPTX
Selenium Interview Questions & Answers
Techcanvass
 
DOCX
Selenium WebDriver FAQ's
Praveen Gorantla
 
PPTX
Selenium using Java
F K
 
PDF
Selenium Tutorial
prad_123
 
PDF
Selenium Basics Tutorial
Clever Moe
 
PDF
Selenium Handbook
Suresh Thammishetty
 
PPTX
Basic Selenium Training
Dipesh Bhatewara
 
How to Configure Selenium WebDriver (java)
Dasun Eranthika
 
Selenium webdriver interview questions and answers
ITeLearn
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Edureka!
 
Selenium presentation
P.V.G'S COET, PUNE - 09
 
Selenium web driver
Roman Savitskiy
 
Introduction to Selenium Web Driver
Return on Intelligence
 
Selenium IDE Tutorial For Beginners | What Is Selenium IDE? | Selenium Tutori...
Edureka!
 
Selenium
Batch2016
 
Selenium Interview Questions & Answers
Techcanvass
 
Selenium WebDriver FAQ's
Praveen Gorantla
 
Selenium using Java
F K
 
Selenium Tutorial
prad_123
 
Selenium Basics Tutorial
Clever Moe
 
Selenium Handbook
Suresh Thammishetty
 
Basic Selenium Training
Dipesh Bhatewara
 

Similar to Boston selenium meetup: Selenium 2 (20)

PDF
Browser-level testing
Martin Kleppmann
 
PPT
selenium training | selenium course | selenium video tutorial | selenium for ...
Nancy Thomas
 
KEY
Getting started with Selenium 2
Sebastiano Armeli
 
PDF
Selenium
eduquer
 
PDF
Berlin.JS Meetup
Adam Christian
 
PPTX
Selenium
mdfkhan625
 
PPTX
Selenium Automation
Anuradha Malalasena
 
PPTX
Automation Testing
AbdulImrankhan7
 
PPT
Intro Of Selenium
Kai Feng Zhang
 
PDF
Selenium course training institute ameerpet hyderabad – Best software trainin...
Sathya Technologies
 
PDF
Selenium course training institute ameerpet hyderabad
Sathya Technologies
 
PPT
selenium.ppt
ssuser7b4894
 
PPT
selenium.ppt
AmenSheikh
 
PPT
selenium.ppt
rajnexient
 
PPTX
Selenium web driver
Sun Technlogies
 
PPTX
Selenium presentation
shivani thakur
 
PPTX
Selenium- A Software Testing Tool
Zeba Tahseen
 
PDF
Interview Question & Answers for Selenium Freshers | LearningSlot
Learning Slot
 
PPTX
Selenium Testing
Shreshtt Bhatt
 
Browser-level testing
Martin Kleppmann
 
selenium training | selenium course | selenium video tutorial | selenium for ...
Nancy Thomas
 
Getting started with Selenium 2
Sebastiano Armeli
 
Selenium
eduquer
 
Berlin.JS Meetup
Adam Christian
 
Selenium
mdfkhan625
 
Selenium Automation
Anuradha Malalasena
 
Automation Testing
AbdulImrankhan7
 
Intro Of Selenium
Kai Feng Zhang
 
Selenium course training institute ameerpet hyderabad – Best software trainin...
Sathya Technologies
 
Selenium course training institute ameerpet hyderabad
Sathya Technologies
 
selenium.ppt
ssuser7b4894
 
selenium.ppt
AmenSheikh
 
selenium.ppt
rajnexient
 
Selenium web driver
Sun Technlogies
 
Selenium presentation
shivani thakur
 
Selenium- A Software Testing Tool
Zeba Tahseen
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Learning Slot
 
Selenium Testing
Shreshtt Bhatt
 
Ad

Boston selenium meetup: Selenium 2

  • 1. Selenium 2 The future of web testing Tuesday, March 15, 2011
  • 2. Eric Allen Software Developer, Sauce Labs @ericpallen [email protected] • Selenium user for 2+ years • Selenium contributor • Developer @ Sauce Labs • Implemented Selenium 2 for Sauce OnDemand Tuesday, March 15, 2011
  • 3. Agenda • Selenium 2 Overview • Side-by-side Examples • Exclusive Selenium 2 Features • Wrap-up • Q & A (Get your questions ready!) Tuesday, March 15, 2011
  • 5. Selenium 2: Why? • Native events • Mobile (iOS Simulator, Android Emulator) • No same-origin freakiness • Better dialog handling • Cleaner API • Future-proof Tuesday, March 15, 2011
  • 6. Selenium 2: What? • Object-oriented, native bindings Java, Ruby, C#, Python • Custom browser bindings JavaScript COM JavaScript Native Tuesday, March 15, 2011
  • 7. Selenium 2: How? Browser Selenium 1: JavaScript Web Page Your Selenium Selenium Selenium tests RC Client RC Server Core JavaScript native bindings HTTP More HTTP Selenium 2: Your tests Selenium 2 Browser native bindings browser-native bindings Tuesday, March 15, 2011
  • 9. Clicking & Querying Selenium 1 Selenium 2 se1.open("http://bing.com/"); se2.get("http://bing.com/"); se1.type("q", "Selenium"); WebElement field = se2.findElement(By.id se1.click("go"); ("sb_form_q")); se1.waitForPageToLoad("30000"); field.sendKeys("Selenium"); assert se1.isTextPresent("testing"); field.submit(); se1.click("css=li.sa_wr:nth-child(2) h3 a"); assert se2.getPageSource().indexOf("testing") != -1; se1.waitForPageToLoad("30000"); assert se1.getTitle().equals( se2.findElements(By.cssSelector("li.sa_wr h3 a")) "Selenium web application testing system"); .get(1).click(); assert se2.getTitle().equals( "Selenium web application testing system"); Tuesday, March 15, 2011
  • 10. Alerts & Confirmations Selenium 1 Selenium 2 se1.open("http://svallens.com/selenium/"); se2.get("http://svallens.com/selenium/"); se1.waitForPageToLoad("30000"); se2.findElement(By.linkText("Alert")).click(); se1.click("link=Alert"); se2.switchTo().alert().accept(); se1.getAlert(); se2.findElement(By.linkText("Confirm")).click(); se1.chooseOkOnNextConfirmation(); se2.switchTo().alert().accept(); se1.click("link=Confirm"); se2.switchTo().defaultContent(); se1.getConfirmation(); assert se2.getPageSource().indexOf("Selenium") != -1; se1.refresh(); assert se1.isTextPresent("Selenium"); Tuesday, March 15, 2011
  • 11. Navigating Frames Selenium 1 Selenium 2 se1.open("http://svallens.com/selenium/seltests/ se2.get("http://svallens.com/selenium/seltests/html/ html/NestedFrames.html"); NestedFrames.html"); se1.waitForPageToLoad("30000"); assert se2.getPageSource().indexOf("This is a test") assert !se1.isTextPresent("This is a test"); == -1; assert se1.getTitle().equals("NestedFrames"); assert se2.getTitle().equals("NestedFrames"); assert se1.isElementPresent("id=foo"); assert se2.findElement(By.id("foo")) != null; se1.selectFrame("bottomFrame"); se2.switchTo().frame("bottomFrame"); assert se1.getText("id=changeTop").equals assert se2.findElement(By.id("changeTop")).getText() ("changeTop"); .equals("changeTop"); se1.selectFrame("relative=top"); se2.switchTo().defaultContent(); assert se1.isElementPresent("id=foo"); assert se2.findElement(By.id("foo")) != null; Tuesday, March 15, 2011
  • 12. Exclusive Selenium 2 Features Tuesday, March 15, 2011
  • 13. PageFactory         // Create a new instance of a driver         WebDriver driver = new HtmlUnitDriver();         // Navigate to the right place         driver.get("http://www.google.com/");         // Create a new instance of the search page class         // and initialize any WebElement fields in it.         GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class);         // And now do the search.         page.searchFor("Cheese"); Tuesday, March 15, 2011
  • 14. User Actions API (Coming soon!) More More at http://www.viddler.com/explore/saucelabs/videos/41/    ActionChainsGenerator builder = ((HasInputDevices) driver).actionsBuilder();    Action dragAndDrop = builder.clickAndHold(someElement)        .moveToElement(otherElement)        .release(otherElement)        .build();    dragAndDrop.perform(); Tuesday, March 15, 2011
  • 15. Should I hurry up and re- write my entire test suite for Selenium 2? Tuesday, March 15, 2011
  • 17. Selenium 2:Yes! • Cleaner, leaner API • No pesky “server” to set up • Mobile • Speed • Improved cross-domain testing Facebook Connect? Sure! • Future-proof for modal dialogs ✓ Alerts • Authentication • Certificate warnings • File upload/download Tuesday, March 15, 2011
  • 18. Selenium 2: No! • Still pre-release quality • Works best in Firefox, other browsers getting there • Completely different API is spotty backwards compatibility layer • No Selenium IDE • Selenium RC ain’t goin’ anywhere Tuesday, March 15, 2011
  • 19. Selenium 1: It’s hiding • “Selenium 2.0b2” = Selenium 1 + Selenium 2 • Since 1.0.3... • Safari CyberVillainsCA • Nicer error messages • Sizzle (jQuery) CSS selectors • Many More! The Selenium 1 inside Selenium 2.0b2 IS PRODUCTION QUALITY Tuesday, March 15, 2011
  • 20. More Information ➡ http://code.google.com/p/selenium/wiki/AdvancedUserInteractions ➡ http://code.google.com/p/selenium/wiki/PageFactory ➡ https://github.com/epall/selenium-examples ➡ http://www.slideshare.net/hugs/selenium-2-webinar-the-next- generation-of-web-and-mobile-application-testing ➡ http://www.slideshare.net/davehunt82/from-ide-to-selenium-2 ➡ http://www.slideshare.net/AutomatedTester/selenium-2-the-future-of- selenium-is-now Eric Allen Software Developer, Sauce Labs @ericpallen [email protected] Tuesday, March 15, 2011