selenium grid workshop london 2016

27
Selenium Grid Workshop

Upload: marcus-merrell

Post on 06-Apr-2017

137 views

Category:

Engineering


0 download

TRANSCRIPT

Selenium Grid Workshop

Schedule

9:00-9:30 — General Set up: Power Cords, Wi-Fi, Seating, and Introductions9:30-10:30 — Grid Overview, Basic Concepts & Philosophy10:30-10:45 — Break10:45-12:00 — Hub/Node Setup and Config12:00-1:00 — Lunch1:30-3:30 — Docker, Troubleshooting, and Advanced Options3:30-3:45 — Break3: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.0Firefox 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/TE4xuvcurl --data @ChromeDockerNode.json http://localhost:4444/grid/registercurl --data @FirefoxDockerNode.json http://localhost:4444/grid/register

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 instancedocker run -d -p 5000:4444 --name selenium-hub -P selenium/hub

To check if the hub is up and runninghttp://localhost:5000/grid/console

● Run a Chrome Node and Link it to Hubdocker 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 TopicsSelenium Grid Extrashttps://github.com/groupon/Selenium-Grid-Extras

Selenium Grid Scalerhttps://github.com/mhardin/SeleniumGridScaler

BrowserMob Proxyhttps://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