Successfully reported this slideshow.

Introduction to selenium_grid_workshop

4,058 views

Published on

Published in: Technology

Introduction to selenium_grid_workshop

  1. 1. Introduction toSelenium Grid Kevin Menard SeleniumConf 2012
  2. 2. What is Selenium Grid?• Maintain a clu ster of Seleniu m nod es• Configu re tests for d ifferent environm ents• Parallelize you r tests
  3. 3. How Does it Work?Seleniu m Grid H u b Seleniu m Grid N od e Seleniu m Server WebDriver WebDriver Brow ser Brow ser host_a Brow ser Client Client Client Client Seleniu m Grid N od e Seleniu m Server host_b Brow ser Brow ser Brow ser
  4. 4. Starting up our Hub• Prerequ isites: • A Java 5+ JRE • seleniu m -server-stand alone.jar• Ru n:$ java –jar selenium-server-standalone.jar –role hub
  5. 5. The Grid Console• Web console to see grid state and config• Open a w eb brow ser to: • http://localhost:4444/grid/console• Beta console available at: • http://localhost:4444/grid/beta/console
  6. 6. Configuring the Hub• Three options (in ord er of preced ence): • Grid 1 com patible YAML file • JSON configu ration file • Com m and -line flags• View current hu b config in console • Click “View Config” link
  7. 7. CLI Configuration• Find config option in console• H over over config nam e for valid options• Use that nam e as a CLI option• Exam ple to block u ntil a capability is p resent:$ java –jar selenium-server-standalone.jar –role hub –throwOnCapabilityNotPresent false
  8. 8. JSON Configuration• Each option in console is a JSON key w ith appropriate d ata type.• E.g., { “throwOnCapabilityNotPresent” : false }• Start the hu b w ith –hu bConfig option:$ java –jar selenium-server-standalone.jar –role hub –hubConfig hub_config.json
  9. 9. Grid1 YAML Config• Sam e config file form at as Seleniu m Grid 1• If you ’ve never used grid 1, d on’t w orry abou t it• Start the hu b w ith -grid 1Ym l option:$ java –jar selenium-server-standalone.jar –role hub –grid1Yml grid_configuration.yml
  10. 10. Starting up a Node• Prerequ isites: • A Java 5+ JRE • seleniu m -server-stand alone.jar• Ru n:$ java –jar selenium-server-standalone.jar –role node –hubHost localhost
  11. 11. Running a Browser Session• WebDriver • Alw ays use a Rem oteWebDriver• RC • N o special consid erations• Treat hu b as you r rem ote server• Let’s start u p Firefox on ou r grid
  12. 12. Configuring the Node• Tw o options (in ord er of preced ence): • JSON configu ration file • Com m and -line flags• View current nod e config in beta console • Click “Configu ration” tab for nod e
  13. 13. CLI Configuration• Find config option by ru nning w ith “-h” flag• Exam ple to change the p ort the nod e bind s to:$ java –jar selenium-server-standalone.jar –role node –hubHost localhost –port 5556
  14. 14. JSON Configuration• Each option in console is a JSON key w ith appropriate d ata type.• E.g., { “port” : 5556 }• Start the hu b w ith –nod eConfig option:$ java –jar selenium-server-standalone.jar –role node –nodeConfig node_config.json
  15. 15. Parallelizing Tests• Grid helps you organize resou rces and spread load• You still need to p arallelize you r tests• TestN G m akes this p retty straightforw ard• Ju nit is m ore w ork, bu t d oable • See article Ad am Gou cher w rote for Sau ceLabs’s blog• Ou tsid e the scope of this w orkshop
  16. 16. Extending Grid• Prim ary w ays to extend grid : • Contribu te a new servlet • Provid e a new Prioritizer im pl. • Provid e a new CapabilityMatcher im pl. • Provid e a new Rem oteProxy im pl.
  17. 17. Creating a New API Servlet • Any Servlet class w ill w ork • Su bclass RegistryBased Servlet to gain access to Registry (central grid d atastore) • Make su re it’s on the hu b’s classpath • Start hu b like so:$ java –cp selenium-server-standalone.jar:my_console.jarorg.openqa.grid.selenium.GridLauncher –role hub –servletscom.example.grid.servlets.Sessions
  18. 18. Let’s Build a Servlet• Will list all the ru nning test sessions• Retu rns resu lts in JSON • Provid es qu eryable API• Accessible from : • http://localhost:4444/grid/admin/Sessions
  19. 19. Altering Grid’s Execution• org.openqa.grid .internal.listeners.Prioritizer• org.openqa.grid .internal.u tils.CapabilityMatcher• org.openqa.grid .internal.Rem oteProxy
  20. 20. Prioritizer • Cu stom ize the execu tion ord er of tests • Com pares requ ests by d esired capabilities • Defau lts to FIFO behavior • Provid ed as hu b configu ration:$ java –cp selenium-server-standalone.jar:my_console.jarorg.openqa.grid.selenium.GridLauncher –role hub –prioritizercom.example.MyPrioritizer
  21. 21. CapabilityMatcher • Define custom strategy for m atching clients and nod es • Defau lt is any nod e that m atches d esired capabilities is a cand id ate • Provid ed as hu b configu ration:$ java –cp selenium-server-standalone.jar:my_console.jarorg.openqa.grid.selenium.GridLauncher –role hub–capabilityMatcher com.example.MyCapabilityMatcher
  22. 22. RemoteProxy• H u b’s interface to a nod e• Fu rther refined throu gh: • RegistrationListener • TestSessionListener • Com m and Listener • SelfH ealingProxy • Tim eou tListener • H tm lRend erer
  23. 23. RegistrationListener• Ru n ju st before a nod e is registered on the grid• Typical u ses: • Mod ify nod e’s configu ration • Facilitate m ass nod e m anagem ent
  24. 24. TestSessionListener• Ru n ju st before a test session is created• Ru n ju st after a test session end s• Typical u ses: • Gather inform ation abou t w hat ran on the nod e • Ensu re clean state of the OS
  25. 25. CommandListener• Ru n ju st before each com m and starts• Ru n ju st after each com m and finishes• Sim ilar to TestSessionListener bu t finer grain• Typical u ses: • Gather inform ation abou t w hat ran on the nod e • Ensu re clean state of the OS
  26. 26. SelfHealingProxy• Monitors grid health and takes corrective action• Defau lt & typical u se: • Ensu re hu b & nod es can talk to each other• You likely d on’t w ant to change the check, bu t m aybe the corrective action • E.g., restart VMs if nod e is d ow n
  27. 27. TimeoutListener• H and le client crashes• Defau lt & typical u se: • Shu td ow n any session that appears orphaned• You likely d on’t w ant to change the check, bu t m aybe the corrective action • E.g., restart VMs if nod e is d ow n
  28. 28. HtmlRender• N ot im plem ented by Rem oteProxy, bu t retu rned from it• Dictates how nod e is rend ered in Web console• Sim ple m ethod , very free-form• Mapping a custom servlet m ay m ake m ore sense
  29. 29. Let’s Build a RemoteProxy• Start by extend ing Defau ltRem oteProxy• We’ll interface w ith Brow serMob Proxy throu gh TestSessionListener • Start a new proxy on nod e the test w ill ru n on based on d esired capabilities • Stop proxy w hen the test session is over
  30. 30. Recap• Tod ay w e: • Set u p a sm all grid • Learned how to configu re the grid • Ran a brow ser session on the grid • Ad d ed a cu stom servlet to provid e a sim ple API • Created a cu stom Rem oteProxy to w ork w ith Brow serMob Proxy
  31. 31. The End• Qu estions?• Kevin Menard • kevin@m ogotest.com • Tw itter: @nirvd ru m • IRC: “nirvd ru m ” on FreeN od e channel #seleniu m

×