Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Selenium intro

Introduction to Selenium for web testing, covering how to get started and how to deal with some common pitfalls.

  • Loggen Sie sich ein, um Kommentare anzuzeigen.

  • Gehören Sie zu den Ersten, denen das gefällt!

Selenium intro

  1. 1. Selenium An Introduction
  2. 2. Selenium ❖ What is it? ❖ What is it good for? ❖ How do I get started? ❖ What are the gotchas?
  3. 3. Selenium? ❖ AKA Webdriver ❖ Web automation/testing framework ❖ Tests run on real browsers
  4. 4. wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() Yesss Master...
  5. 5. Pros ❖ Realistic test conditions ❖ Cross-browser testing ❖ Popular & mature tech
  6. 6. Cons ❖ Slow ❖ Changing HTML may break tests
  7. 7. Uses ❖ Acceptance Testing ❖ Continuous Integration ❖ Monitoring ❖ TDD? Maybe?
  8. 8. Python example from selenium.webdriver.firefox.webdriver import WebDriver wd = WebDriver() wd.implicitly_wait(60) wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() assert "How do I sign up for a MetaFilter account?" in wd.find_element_by_tag_name("html").text
  9. 9. PHP! require_once 'php-webdriver'; $wd = new WebDriver(); $session = $wd->session(); $session->open("http://www.metafilter.com/"); $session->element("link text", "FAQ")->click(); $session->close(); assert(strpos( $session->element("tag name", "html")->text(), "How do I sign up for a MetaFilter account?"));
  10. 10. Java! import org.openqa.selenium.*; import static java.util.concurrent.TimeUnit.*; FirefoxDriver wd = new FirefoxDriver(); wd.manage().timeouts().implicitlyWait(60, SECONDS); wd.get("http://www.metafilter.com/"); wd.findElement(By.linkText("FAQ")).click(); assert wd.findElement(By.tagName("html")).getText() .contains("How do I sign up for a MetaFilter account?") wd.quit();
  11. 11. Getting started, option A ❖ Get Selenium server from seleniumhq.org ❖ Download language binding of your choice ❖ Write some code & play it back
  12. 12. Getting started, option B ➔ Get Selenium Builder from sebuilder.com ➔ Record your actions as tests ➔ Play back locally, or via server ➔ Export to code or JSON ➔ Run JSON via interpreters
  13. 13. Gotcha 1: Visibility ❖ Selenium respects display: none ❖ You can’t interact with something invisible ❖ Even if it’s in the HTML
  14. 14. Gotcha 2: Timing ❖ Page needs to load first ❖ Some Javascript has to execute too? ❖ Page changes dynamically?
  15. 15. Gotcha 2: Timing ❖ Wait for page elements ❖ Implicitly or explicitly ❖ Don’t use pause!
  16. 16. Gotcha 2: Timing from selenium.webdriver.firefox.webdriver import WebDriver wd = WebDriver() wd.implicitly_wait(60) wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() assert "How do I sign up for a MetaFilter account?" in wd.find_element_by_tag_name("html").text
  17. 17. Gotcha 3: Locators from selenium.webdriver.firefox.webdriver import WebDriver wd = WebDriver() wd.implicitly_wait(60) wd.get("http://www.metafilter.com/") wd.find_element_by_link_text("FAQ").click() assert "How do I sign up for a MetaFilter account?" in wd.find_element_by_tag_name("html").text
  18. 18. Gotcha 3: Locators ❖ Locators identify UI elements ❖ HTML changes can break locators
  19. 19. Gotcha 3: Locators ❖ Use simple, clean, robust locators ❖ Depends on your approach ❖ Text vs ID vs CSS ❖ Careful XPATH for the tough cases
  20. 20. Good & bad locators id: home_link id: 12094b css: span.green css: #rightbar > .menu > li:nth-of-type(3) > h5 css: .logout xpath: //*[@id='menu']//input[3] xpath: //header/div/div[1]/div[1]/a/h1/span[2]
  21. 21. Good & bad locators id: home_link id: 12094b css: span.green css: #rightbar > .menu > li:nth-of-type(3) > h5 css: .logout xpath: //*[@id='menu']//input[3] xpath: //header/div/div[1]/div[1]/a/h1/span[2]
  22. 22. Resources ❖ Selenium HQ ❖ A CI solution with Builder, Travis & Sauce ❖ Obligatory self-promotion!
  23. 23. Thank you! Questions? @zarkonnen_com

×