Selenium Grid Workshop
Schedule
9:00-9:30 — General Set up: Power Cords, Wi-Fi, Seating, and Introductions
9:30-10:30 — Grid Overview, Basic Concepts & Philosophy
10:30-10:45 — Break
10:45-12:00 — Hub/Node Setup and Config
12:00-1:00 — Lunch
1:30-3:30 — Docker, Troubleshooting, and Advanced Options
3:30-3:45 — Break
3:45-5:00 — Extensions, Plug-ins, Auto-scaling, and Advanced Logging
— Q&A, Anecdotes, Discussion, and General Tips & Tricks
Overview
● Terminology
● General Flow
● Hub/Node Details
● Configuration
● Docker Intro
● Edge (if you dare)
● Preview of Next Session
https://goo.gl/BWlK1a
Terminology
● Hub
● Node
● Test Slot
● Test
● Thread
● Proxy
Grid 101
Hub
● The intermediary and manager
● Accepts requests to run tests
● Allocates Test Slots to nodes
● Takes instructions directly from client, and executes them
remotely on nodes
● The Hub only manages threads—it performs zero browser
work
Node
- Registers itself to Hub listed in config
- Communicates its config to the Hub at registration time:
- Test Slots per browser
- “Hey Hub, I have 1 Slot for Firefox, 5 for Chrome”
- Receives json wire protocol instructions from the Hub
- Executes instructions, keeping threads separated
- The Node does not evaluate, make judgments, or control
anything: it only receives and executes instructions (and
throws exceptions)
Start the Hub:
java -jar selenium-server-standalone-3.0.1.jar -role hub
Register a node:
java -jar selenium-server-standalone-3.0.1.jar -role node
-hub http://localhost:4444/grid/register -browser
browserName=firefox,maxInstances=3 -browser
browserName=chrome,maxInstances=5
*All commands are case sensitive!
Starting From Command-line
Hub Parameters — Configuration
● -port
Default is 4444, use this to override
● -jettyMaxThreads <int>
Maximum number of threads server will pool
● -cleanUpCycle <milliseconds>
Interval for hub to poll for inactive test sessions
Hub Parameters - Timeouts
● -timeout <seconds>
● -browserTimeout <seconds, min 60>
Timeout between receiving individual commands
60 seconds minimum value
● -newSessionWaitTimeout <milliseconds>
Timeout the server will wait for a new Session to be created
Hub Parameters —
● -prioritizer
Class (on the classpath!) that will be used to sort queued new Session requests
Must implement Prioritizer
● -servlets
Custom servlets, mainly for grid plugins
● -log <filename>
Hub Parameters — Capabilities
● -throwOnCapabilityNotPresent
● -capabilityMatcher
Class that implements CapabilityMatcher
DefaultCapabilityMatcher only checks Platform, Browser Name, Version,
“applicationName”
Node Command line options
● -nodeConfig <filename>
● -hubHost <DNS entry>
● -hubPort <port>
● -host <localhost>
● -port <local port>
● -maxSession <int>
● -register
● -servlets
Node Parameters — JSON file
● -nodeConfig <filename>
{ "capabilities": [
{ "browserName": "chrome",
"maxInstances": 5,
"platform": "WINDOWS",
"webdriver.chrome.driver": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" }, ],
"configuration": {
"_comment" : "Configuration for Node",
"cleanUpCycle": 2000,
"proxy": "org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
"port": 5555,
"host": ip,
"register": true,
"hubPort": 4444,
"maxSessions": 5 }
}
Node Command line options
● -browser param1=val1,param2=val2
Usually, only browserName, platform, version, applicationName and
maxInstances are important
● -cleanUpCycle <milliseconds>
● -registerCycle <milliseconds>
How often the node will try to register itself again. Allows you to restart the hub
without having to restart the nodes
Run It!
● We’ll write a quick javascript test
● Use node to run it
● We’ll need:
○ Node (v6.9.0) (brew install node)
○ selenium-webdriver module (npm install -g selenium-webdriver)
○ chromedriver v2.25.426935
● Paste script (https://goo.gl/sRNVVC) into test.js
● node test.js
● It will go really fast, so be sure to watch!
docker 101
● docker ps
● docker exec -it <container id> bash
● docker kill <image>
● docker run
● docker images -a
● docker rmi <image>
● docker -p
● docker -P
● docker -d
● docker --link
docker-selenium Standalone
Running a standalone machine without connecting to a hub
● selenium/standalone-chrome: Selenium standalone with Chrome installed
● selenium/standalone-firefox: Selenium standalone with Firefox installed
● selenium/standalone-chrome-debug: Selenium standalone with Chrome
installed and runs a VNC server
● selenium/standalone-firefox-debug: Selenium standalone with Firefox installed
and runs a VNC server
docker-selenium Standalone
Start docker instance:
Chrome docker run -d -p 4455:4444 selenium/standalone-chrome:2.53.0
Firefox docker run -d -p 4466:4444 selenium/standalone-firefox:2.53.0
docker run -d --name se -p 5900:5900 -p 4444:4444
selenium/standalone-chrome-debug
Check they are up and running and you can connect to them!
http://localhost:4455/wd/hub/status
http://localhost:4466/wd/hub/status
Register them to your running hub: https://goo.gl/TE4xuv
docker-selenium GRID
● selenium/hub: Image for running a Selenium Grid Hub
● selenium/node-chrome: Selenium node with Chrome installed, needs to
be connected to a Selenium Grid Hub
● selenium/node-firefox: Selenium node with Firefox installed, needs to be
connected to a Selenium Grid Hub
● selenium/node-chrome-debug: Selenium node with Chrome installed
and runs a VNC server, needs to be connected to a Selenium Grid Hub
● selenium/node-firefox-debug: Selenium node with Firefox installed and
runs a VNC server, needs to be connected to a Selenium Grid Hub
docker-selenium GRID
● Creating a docker HUB instance
docker run -d -p 5000:4444 --name selenium-hub -P selenium/hub
To check if the hub is up and running
http://localhost:5000/grid/console
● Run a Chrome Node and Link it to Hub
docker run -d --link selenium-hub:hub -P --name chrome
selenium/node-chrome-debug
● Run a Firefox Node and Link it to Hub
docker run -d --link selenium-hub:hub -P --name firefox
selenium/node-firefox-debug
Selenium GRID with docker-compose
docker-compose is a YAML file that will help manage your docker services
● Start, stop & rebuild services
● View the status and logs of services.
To get a docker-compose yml file: https://goo.gl/puYvnV
To spin up Selenium Grid: docker-compose up -d
Q&A
Thank You All!
Marcus Merrell
&
Manoj Kumar
Add a Windows VM https://goo.gl/P8q7jT
starting Edge node
java -jar
selenium-standalone-server-3.0.1.jar
-nodeConfig config.json -port 4444 -hub
http://<host>:<port>/grid/register -host <ip
address of win10 vm> -role node
config file:
https://goo.gl/LWdsGm
Other Grid Topics
Selenium Grid Extras
https://github.com/groupon/Selenium-Grid-Extras
Selenium Grid Scaler
https://github.com/mhardin/SeleniumGridScaler
BrowserMob Proxy
https://bmp.lightbody.net/
Run Via Saucelabs
java 
> -cp 
> selenium-server-standalone-3.0.1.jar; 
> sauce-grid-plugin-1.0.4.jar 
> org.openqa.grid.selenium.GridLauncher 
> -role hub 
> -servlets 
> com.saucelabs.grid.SauceOnDemandAdminServlet, 
> com.saucelabs.grid.SauceOnDemandConsoleServlet

Selenium grid workshop london 2016

  • 1.
  • 2.
    Schedule 9:00-9:30 — GeneralSet up: Power Cords, Wi-Fi, Seating, and Introductions 9:30-10:30 — Grid Overview, Basic Concepts & Philosophy 10:30-10:45 — Break 10:45-12:00 — Hub/Node Setup and Config 12:00-1:00 — Lunch 1:30-3:30 — Docker, Troubleshooting, and Advanced Options 3:30-3:45 — Break 3:45-5:00 — Extensions, Plug-ins, Auto-scaling, and Advanced Logging — Q&A, Anecdotes, Discussion, and General Tips & Tricks
  • 3.
    Overview ● Terminology ● GeneralFlow ● Hub/Node Details ● Configuration ● Docker Intro ● Edge (if you dare) ● Preview of Next Session https://goo.gl/BWlK1a
  • 4.
    Terminology ● Hub ● Node ●Test Slot ● Test ● Thread ● Proxy
  • 5.
  • 6.
    Hub ● The intermediaryand manager ● Accepts requests to run tests ● Allocates Test Slots to nodes ● Takes instructions directly from client, and executes them remotely on nodes ● The Hub only manages threads—it performs zero browser work
  • 7.
    Node - Registers itselfto Hub listed in config - Communicates its config to the Hub at registration time: - Test Slots per browser - “Hey Hub, I have 1 Slot for Firefox, 5 for Chrome” - Receives json wire protocol instructions from the Hub - Executes instructions, keeping threads separated - The Node does not evaluate, make judgments, or control anything: it only receives and executes instructions (and throws exceptions)
  • 8.
    Start the Hub: java-jar selenium-server-standalone-3.0.1.jar -role hub Register a node: java -jar selenium-server-standalone-3.0.1.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox,maxInstances=3 -browser browserName=chrome,maxInstances=5 *All commands are case sensitive! Starting From Command-line
  • 9.
    Hub Parameters —Configuration ● -port Default is 4444, use this to override ● -jettyMaxThreads <int> Maximum number of threads server will pool ● -cleanUpCycle <milliseconds> Interval for hub to poll for inactive test sessions
  • 10.
    Hub Parameters -Timeouts ● -timeout <seconds> ● -browserTimeout <seconds, min 60> Timeout between receiving individual commands 60 seconds minimum value ● -newSessionWaitTimeout <milliseconds> Timeout the server will wait for a new Session to be created
  • 11.
    Hub Parameters — ●-prioritizer Class (on the classpath!) that will be used to sort queued new Session requests Must implement Prioritizer ● -servlets Custom servlets, mainly for grid plugins ● -log <filename>
  • 12.
    Hub Parameters —Capabilities ● -throwOnCapabilityNotPresent ● -capabilityMatcher Class that implements CapabilityMatcher DefaultCapabilityMatcher only checks Platform, Browser Name, Version, “applicationName”
  • 13.
    Node Command lineoptions ● -nodeConfig <filename> ● -hubHost <DNS entry> ● -hubPort <port> ● -host <localhost> ● -port <local port> ● -maxSession <int> ● -register ● -servlets
  • 14.
    Node Parameters —JSON file ● -nodeConfig <filename> { "capabilities": [ { "browserName": "chrome", "maxInstances": 5, "platform": "WINDOWS", "webdriver.chrome.driver": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" }, ], "configuration": { "_comment" : "Configuration for Node", "cleanUpCycle": 2000, "proxy": "org.openqa.grid.selenium.proxy.WebDriverRemoteProxy", "port": 5555, "host": ip, "register": true, "hubPort": 4444, "maxSessions": 5 } }
  • 15.
    Node Command lineoptions ● -browser param1=val1,param2=val2 Usually, only browserName, platform, version, applicationName and maxInstances are important ● -cleanUpCycle <milliseconds> ● -registerCycle <milliseconds> How often the node will try to register itself again. Allows you to restart the hub without having to restart the nodes
  • 16.
    Run It! ● We’llwrite a quick javascript test ● Use node to run it ● We’ll need: ○ Node (v6.9.0) (brew install node) ○ selenium-webdriver module (npm install -g selenium-webdriver) ○ chromedriver v2.25.426935 ● Paste script (https://goo.gl/sRNVVC) into test.js ● node test.js ● It will go really fast, so be sure to watch!
  • 17.
    docker 101 ● dockerps ● docker exec -it <container id> bash ● docker kill <image> ● docker run ● docker images -a ● docker rmi <image> ● docker -p ● docker -P ● docker -d ● docker --link
  • 18.
    docker-selenium Standalone Running astandalone machine without connecting to a hub ● selenium/standalone-chrome: Selenium standalone with Chrome installed ● selenium/standalone-firefox: Selenium standalone with Firefox installed ● selenium/standalone-chrome-debug: Selenium standalone with Chrome installed and runs a VNC server ● selenium/standalone-firefox-debug: Selenium standalone with Firefox installed and runs a VNC server
  • 19.
    docker-selenium Standalone Start dockerinstance: Chrome docker run -d -p 4455:4444 selenium/standalone-chrome:2.53.0 Firefox docker run -d -p 4466:4444 selenium/standalone-firefox:2.53.0 docker run -d --name se -p 5900:5900 -p 4444:4444 selenium/standalone-chrome-debug Check they are up and running and you can connect to them! http://localhost:4455/wd/hub/status http://localhost:4466/wd/hub/status Register them to your running hub: https://goo.gl/TE4xuv
  • 20.
    docker-selenium GRID ● selenium/hub:Image for running a Selenium Grid Hub ● selenium/node-chrome: Selenium node with Chrome installed, needs to be connected to a Selenium Grid Hub ● selenium/node-firefox: Selenium node with Firefox installed, needs to be connected to a Selenium Grid Hub ● selenium/node-chrome-debug: Selenium node with Chrome installed and runs a VNC server, needs to be connected to a Selenium Grid Hub ● selenium/node-firefox-debug: Selenium node with Firefox installed and runs a VNC server, needs to be connected to a Selenium Grid Hub
  • 21.
    docker-selenium GRID ● Creatinga docker HUB instance docker run -d -p 5000:4444 --name selenium-hub -P selenium/hub To check if the hub is up and running http://localhost:5000/grid/console ● Run a Chrome Node and Link it to Hub docker run -d --link selenium-hub:hub -P --name chrome selenium/node-chrome-debug ● Run a Firefox Node and Link it to Hub docker run -d --link selenium-hub:hub -P --name firefox selenium/node-firefox-debug
  • 22.
    Selenium GRID withdocker-compose docker-compose is a YAML file that will help manage your docker services ● Start, stop & rebuild services ● View the status and logs of services. To get a docker-compose yml file: https://goo.gl/puYvnV To spin up Selenium Grid: docker-compose up -d
  • 23.
    Q&A Thank You All! MarcusMerrell & Manoj Kumar
  • 24.
    Add a WindowsVM https://goo.gl/P8q7jT
  • 25.
    starting Edge node java-jar selenium-standalone-server-3.0.1.jar -nodeConfig config.json -port 4444 -hub http://<host>:<port>/grid/register -host <ip address of win10 vm> -role node config file: https://goo.gl/LWdsGm
  • 26.
    Other Grid Topics SeleniumGrid Extras https://github.com/groupon/Selenium-Grid-Extras Selenium Grid Scaler https://github.com/mhardin/SeleniumGridScaler BrowserMob Proxy https://bmp.lightbody.net/
  • 27.
    Run Via Saucelabs java > -cp > selenium-server-standalone-3.0.1.jar; > sauce-grid-plugin-1.0.4.jar > org.openqa.grid.selenium.GridLauncher > -role hub > -servlets > com.saucelabs.grid.SauceOnDemandAdminServlet, > com.saucelabs.grid.SauceOnDemandConsoleServlet