Top Banner
Selenium Grid Workshop
27

Selenium grid workshop london 2016

Apr 06, 2017

Download

Engineering

Marcus Merrell
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Selenium grid workshop london 2016

Selenium Grid Workshop

Page 2: Selenium grid workshop london 2016

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

Page 3: Selenium grid workshop london 2016

Overview● Terminology● General Flow● Hub/Node Details● Configuration● Docker Intro● Edge (if you dare)● Preview of Next Session

https://goo.gl/BWlK1a

Page 4: Selenium grid workshop london 2016

Terminology

● Hub● Node● Test Slot● Test● Thread● Proxy

Page 5: Selenium grid workshop london 2016

Grid 101

Page 6: Selenium grid workshop london 2016

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

Page 7: Selenium grid workshop london 2016

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)

Page 8: Selenium grid workshop london 2016

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

Page 9: Selenium grid workshop london 2016

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

Page 10: Selenium grid workshop london 2016

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

Page 11: Selenium grid workshop london 2016

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>

Page 12: Selenium grid workshop london 2016

Hub Parameters — Capabilities

● -throwOnCapabilityNotPresent● -capabilityMatcher

Class that implements CapabilityMatcher

DefaultCapabilityMatcher only checks Platform, Browser Name, Version, “applicationName”

Page 13: Selenium grid workshop london 2016

Node Command line options

● -nodeConfig <filename>● -hubHost <DNS entry>● -hubPort <port>● -host <localhost> ● -port <local port>● -maxSession <int>● -register● -servlets

Page 14: Selenium grid workshop london 2016

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 }

}

Page 15: Selenium grid workshop london 2016

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

Page 16: Selenium grid workshop london 2016

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!

Page 17: Selenium grid workshop london 2016

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

Page 18: Selenium grid workshop london 2016

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

Page 19: Selenium grid workshop london 2016

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

Page 20: Selenium grid workshop london 2016

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

Page 21: Selenium grid workshop london 2016

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

Page 22: Selenium grid workshop london 2016

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

Page 23: Selenium grid workshop london 2016

Q&A

Thank You All!

Marcus Merrell&

Manoj Kumar

Page 24: Selenium grid workshop london 2016

Add a Windows VM https://goo.gl/P8q7jT

Page 25: Selenium grid workshop london 2016

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

Page 26: Selenium grid workshop london 2016

Other Grid TopicsSelenium Grid Extrashttps://github.com/groupon/Selenium-Grid-Extras

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

BrowserMob Proxyhttps://bmp.lightbody.net/

Page 27: Selenium grid workshop london 2016

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