Selenium Grid

3,948 views

Published on

A presentation I gave for Boston Selenium User Meetup Group on Selenium Grid. Jan. 25, 2011

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,948
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
189
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • When running headless on *nix you’ll want to set the display value. Xvfb is a great way to do this.\n\nWhen running headless on Windows you’ll want to set up VNC so the window session remains active (RDP won’t work).\n\nThe HOST value must be a routable host from the hub’s point of view. Unless you’re running the hub and the node on the same machine, this value should not be “localhost.”\n\nThe hub URL must not end in a “/”, otherwise the node will fail to register. Yes, this is not a proper URL.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Since Selenium RC Server works over HTTP, you could maintain your own list of known servers and parameterize your tests accordingly, but grid affords additional benefits.\n
  • \n
  • Some people are doing this with Hudson.\n\nI’m running tests using resque as an asynchronous job queuing system.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Selenium Grid

    1. 1. Selenium Grid Kevin Menard Maintainer, Selenium Grid Founder, Mogotest
    2. 2. What is Selenium Grid?• Maintain a cluster of Selenium RC servers• Configure tests for different environments• Parallelize your tests
    3. 3. How Does it Work?Selenium Grid Hub Selenium Grid Node Selenium RC Server Selenium Grid Node Selenium RC Server host_a Client Client Selenium Grid Node Selenium RC Server Client Client host_b
    4. 4. How Does it Work?Selenium Grid Hub Selenium Grid Node Selenium RC Server Selenium Grid Node Selenium RC Server host_a Client Client Selenium Grid Node Selenium RC Server Client Client host_b
    5. 5. How Does it Work?Selenium Grid Hub Selenium Grid Node Selenium RC Server Selenium Grid Node Selenium RC Server host_a Client Client Selenium Grid Node Selenium RC Server Client Client host_b
    6. 6. Environments • Map descriptive names to browser strings • Configured in Selenium Grid Hubhub: environments: - name: "linux_firefox_3_6" browser: "*firefox /opt/firefox-3.6/firefox-bin" - name: "windows_firefox_3_5" browser: "*firefox" - name: "windows_firefox_3_6" browser: "*firefox"
    7. 7. Starting the Hub • Edit grid_configuration.ymlRake: $ rake hub:start $ BACKGROUND=true nohup rake hub:start &>/dev/nullant: $ ant launch-hub $ nohup ant launch-hub >> log_file 2>&1
    8. 8. Selenium Grid Console• Open http://localhost:4444/console
    9. 9. Starting Up a NodeRake: $ rake rc:start $ DISPLAY=:99.0 BACKGROUND=true HOST=host_b PORT=5000 ENVIRONMENT=linux_firefox_3_6 HUB_URL=http://hub_host:4444 SELENIUM_ARGS=-ensureCleanSession -noBrowserSessionReuse nohup rake rc:start &>/dev/nullant: $ ant launch-remote-control $ DISPLAY=:99.0 nohup ant -Dhost=host_b -Dport=5000 -Denvironment=linux_firefox_3_6 -DhubURL=http://hub_host:4444 -DseleniumArgs=-ensureCleanSession -noBrowserSessionReuse launch-remote-control >> log_file 2>&1
    10. 10. Node Registration 1. Node connects to hubSelenium Grid Node Selenium Grid Hub environment windows_firefox_3_6 host host_b port 5000
    11. 11. Node Registration 1. Node connects to hubSelenium Grid Node Selenium Grid Hub environment windows_firefox_3_6 host host_b port 5000 2. Hub adds node to environment queue windows_chrome windows_firefox_3_6 host_c:5000 host_a:5000 linux_firefox_3_6 host_a:5001 host_d:5000 host_b:5000
    12. 12. Available Node in Console
    13. 13. Client Connection• Client connects with environment name as browser string• Hub looks up by environment & reserves a node • Blocks until one is available• Client communicates with hub at all times • Hub forwards traffic to correct node
    14. 14. Client Connection CodeOld: New:require rubygems require rubygemsrequire selenium/client require selenium/clientbrowser = browser = Selenium::Client::Driver.new Selenium::Client::Driver.new :host => localhost, :host => localhost, :port => 4444, :port => 4444, :browser => *firefox, :browser => linux_firefox_3_6, :url => http://mogotest.com/ :url => http://mogotest.com/browser.start_new_browser_session browser.start_new_browser_sessionbrowser.open http://mogotest.com/ browser.open http://mogotest.com/browser.close_current_browser_session browser.close_current_browser_session
    15. 15. Makes Testing Simpler• Client always connects to known endpoint• Hub takes care of browser allocation• Nodes can be added dynamically• Hub handles bad nodes
    16. 16. Grid Resiliency• Hub can send heartbeat requests to node to tell if it has gone down• Hub can gracefully kill idle sessions• Hub can kill sessions that take too long to create
    17. 17. Parallel Testing• Need a way to execute in parallel • Java: TestNG or parallel-jUnit • Ruby: DeepTest • Python: nose• Need a way to parameterize your tests for each node’s environment• Your tests must maintain their own state
    18. 18. Shortcomings• Selenium 1 API compatible only • Using an old version of Selenium RC at that• 1 request per RC • Doesn’t scale vertically very well• Historically has had multi-threaded problems • Fixed as of 1.0.8
    19. 19. Selenium Grid’s Future• Combine Selenium Grid & RC • De facto single-node grid • Grid available out of the box• Auto-discovery of other nodes on network
    20. 20. Selenium Grid 2.0• Proposal on dev list for new grid 2.0• Project rewrite by François Reynaud• Supports Selenium 1 & 2 APIs• Nicer Web interface• Very extensible with callback points & listeners
    21. 21. Selenium Grid 2.0 Listeners• Possible uses • Priority queue for test execution • Stat tracking • OS environment preparation
    22. 22. Conclusion• Selenium Grid is alive and well • 4 releases in the last 9 months• Pushing towards a Selenium 2 compatible grid• If you have time, please review the proposed new grid code
    23. 23. Resources
    24. 24. Resources• Project: • Source: http://github.com/nirvdrum/selenium-grid • Issues: http://selenium.googlecode.com/ • Blog: http://seleniumhq.wordpress.com/• Personal: • Twitter: @nirvdrum • Email: kevin@mogotest.com

    ×