Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Web testing with Selenium

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 43 Anuncio

Web testing with Selenium

Descargar para leer sin conexión

Ever want to automate your web testing with Selenium? Usually it works well, but then there are times where it seems to be brittle and unreliable. Sometimes, your company might want to stop using this (and stop the automated test effort!).

How can we prevent Selenium tests from becoming Shelfware? Selenium based tests can in fact be reliable and should actively be used in the regression test effort.

Key Takeaways; Alan Ark shares techniques he uses to turn sick test automation codebases into a reliable workhorse. Techniques include AJAX-proofing, use of the Page Object model, and pop-up handling.

Ever want to automate your web testing with Selenium? Usually it works well, but then there are times where it seems to be brittle and unreliable. Sometimes, your company might want to stop using this (and stop the automated test effort!).

How can we prevent Selenium tests from becoming Shelfware? Selenium based tests can in fact be reliable and should actively be used in the regression test effort.

Key Takeaways; Alan Ark shares techniques he uses to turn sick test automation codebases into a reliable workhorse. Techniques include AJAX-proofing, use of the Page Object model, and pop-up handling.

Anuncio
Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

A los espectadores también les gustó (20)

Anuncio

Similares a Web testing with Selenium (20)

Más de XBOSoft (20)

Anuncio

Más reciente (20)

Web testing with Selenium

  1. 1. XBOSoft, Inc. All Rights Reserved. 1 Web Testing with Selenium
  2. 2. XBOSoft Founded in 2006 Dedicated to software quality Software QA Consulting Software Testing Offices in San Francisco, Beijing and Amsterdam XBOSoft, Inc. All Rights Reserved. 2
  3. 3. House Rules Everyone except the speakers are muted Questions via the gotowebinar control on the right side of your screen or through Twitter @XBOSoft Questions can be asked throughout the webinar - we’ll try to answer them at the end. You will receive info on recording after the webinar XBOSoft, Inc. All Rights Reserved. 3
  4. 4. Meet Our Speakers • VP Sales & Marketing at XBOSoft • 15 years Marketing and Sales in High Tech • Love the outdoors, reading and parenthood XBOSoft, Inc. All Rights Reserved. 4 Steve Gohre • Sr. Software Developer in Test at Eid Passport • Over 20 years of test automation experience • Veteran speaker • Quality Week 1999 • PNSQC 2007 • PNSQC 2011 • PNSQC 2013 • Better Software West 2015 (June) • Enjoys golf and fine wine Alan Ark Sabrina Gasson • Marketing Manager of XBOSoft • Emails you all regularly to join our industry hot topic webinars • And invites you all to download our latest trends in software testing whitepapers.
  5. 5. Who is Alan Ark? Sr. Software Developer in Test at Eid Passport in Hillsboro, Oregon, USA Over 20 years of automated testing experience Over 8 years with Watir About a year with Selenium
  6. 6. Agenda Intro on Selenium Tips and Tricks Pitfalls to avoid Ask questions as we go!
  7. 7. Watir? Web Application Testing in Ruby A different open source project that drives browsers for test automation
  8. 8. What is Selenium? A tool to automate browsers! Quick regression testing across many browsers Automate web based admin tasks
  9. 9. Why Selenium over Watir? Choice More widely supported More bindings available
  10. 10. Regression testing! Repetitive test efforts Reproducible tests across many browsers Time consuming
  11. 11. Automation of web based admin tasks! Creation of data Reading of records on the browser Updating of content Deletion of records
  12. 12. What version of Selenium? Don’t use Selenium 1.0 - Selenium IDE Recorder is deprecated Javascript Injection to drive a browser Selenium 2 uses WebDriver http://docs.seleniumhq.org/projects/webdriver/
  13. 13. WebDriver? A platform and language-neutral interface that allows programs or scripts to introspect into, and control the behaviour of, a web browser http://www.w3.org/TR/2013/WD-webdriver- 20130117/
  14. 14. How do I start? Pick a language! Java C# python ruby others supported as well
  15. 15. Pick your browser/driver Firefox Chrome IE Safari many more!
  16. 16. How do I interact with the browser? Dev tools are built-in to browsers Inspect the HTML to glean the locators to use var inputElement = driver.FindElement(By.Name("myButton")); inputElement.Click();
  17. 17. Built-in locators Use these if you can driver.FindElement(By.Name("myName")); driver.FindElement(By.Id("myId")); driver.FindElement(By.ClassName("myClass")); others as well
  18. 18. XPath vs. CSS XPath //div[. ='Some Text of the Div'] CSS table[id='tblBadgeInfo'] thead td Speed considerations?
  19. 19. Tips to avoid headaches…. GUI based tests sometimes thought of as fragile, brittle or unreliable How to prevent your Selenium automation from becoming shelfware
  20. 20. Use unique locators Very difficult if locators are not unique Avoid using index numbers Ask for some name/id/class on UI elements from the development team
  21. 21. Do not use hard coded sleeps Makes test scripts brittle when run on different environments. Thread.Sleep(5000); // Sleep for 5 seconds button.Click();
  22. 22. Use a polling wait Be flexible and return as soon as possible but ignore exceptions
  23. 23. Use WebDriverWait WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); IWebElement myDynamicElement = wait.Until<IWebElement>((d) => { return d.FindElement(By.Id("myButtonId")); });
  24. 24. Use ExpectedConditions Convenience methods on things that are checked often. Use these with WebDriverWait. http://selenium.googlecode.com/git/docs/api/d otnet/html/AllMembers_T_OpenQA_Seleniu m_Support_UI_ExpectedConditions.htm
  25. 25. Use Page Objects Isolate UI elements from the test cases If the UI changes, your tests only need to be modified in a single place - the Page Object that defines the UI Reduces duplicate code
  26. 26. Login Page Example
  27. 27. Login Page Object class LoginPage : BasePage { public LoginPage() {} public void Login(string username,string password) { var nameElement = driver.FindElement(By.Name("username")); nameElement .SendKeys(username); var passElement = driver.FindElement(By.Name("password")); passElement .SendKeys(password); var submitButton = driver.FindElement(By.Name("submit")); submitButton.Click(); } }
  28. 28. Login Test Case var loginPage = new LoginPage(); loginPage.Login("user","pass");
  29. 29. Verify your assumptions…. Are you where you think you are? Verify page elements on transitions Clicked links Form submission
  30. 30. Be Generous with your logging Overlogging is better than underlogging Easier to examine output files to see where failures are occurring Especially true for remote execution Use logging to get a trail on most events
  31. 31. Things I like to log URL of the page Timestamp Values used on assertions Values used on comparators Values used on loops
  32. 32. IE Considerations Sometimes click appears to do “nothing” Use SendKeys instead of Click https://www.google.com/webhp?#safe=off&q=i e+click+selenium
  33. 33. SendKeys Code Instead of button.Click(); Use button.SendKeys(Keys.Enter);
  34. 34. Handling Frames Be sure to set the focus to the frame hosting your elements. IWebElement mainFrame = driver.FindElement(By.Name("MainFrame")); driver.SwitchTo().Frame(mainFrame);
  35. 35. Handling Dialogs Javascript alerts Javascript confirm Javascript prompts
  36. 36. Example code try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { // Modal dialog not displayed return false; }
  37. 37. Handling Popup windows var windowHandles = driver.WindowHandles; // if handle 0 is the main window then handle 1 is the popup, otherwise the popup is handle 0 var popUp = (windowHandles[0] == mainWindowHandle ? windowHandles[1] : windowHandles[0]); driver.SwitchTo().Window(popUp); <do stuff> driver.SwitchTo().Window(mainWindowHandle );
  38. 38. Not the only answer... Sometimes Selenium can’t do the job. AutoIt can be used as a fall-back. https://www.autoitscript.com/site/autoit/
  39. 39. Browser login prompts
  40. 40. Advanced Topics Use with Continuous Integration tools Remote control of tests Selenium Grid
  41. 41. Summary Instrument your framework correctly and Selenium tests can be very good for you Don’t be discouraged. Try different things. Investigate to see what Selenium can do for you
  42. 42. Contact Info Email: aark@eidpassport.com LinkedIn: https://www.linkedin.com/in/arkie Come visit: http://bscwest.techwell.com/
  43. 43. Post your questions on Twitter and we'll answer them @XBOSoft Join us to keep updated on all our webinars, reports and whitepapers: facebook.com/xbosoft +xbosoft linkedin.com/company/xbosoft We post regularly on our blog – check us out! http://xbosoft.com/software-quality-blog/ Why not download our free Whitepapers, available here: http://xbosoft.com/knowledge-center/ You will receive an email with information on slides and recording. Any further queries regarding our services or ideas for future webinars please email us! Services@xbosoft.com Q+A www.xbosoft.com

×