ºÝºÝߣ

ºÝºÝߣShare 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 & Con?rmations
      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
                          ? Certi?cate 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

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 eric@saucelabs.com ? 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 & Con?rmations 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 ? Certi?cate 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 eric@saucelabs.com Tuesday, March 15, 2011