Skip to content

Selenium Grid overhaul #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ nosetests.xml
# Developer
.project
.pydevproject

# Other
selenium-server-standalone.jar
2 changes: 1 addition & 1 deletion integrations/docker/docker_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='seleniumbase',
version='1.1.22',
version='1.1.23',
author='Michael Mintz',
author_email='@mintzworld',
maintainer='Michael Mintz',
Expand Down
29 changes: 18 additions & 11 deletions integrations/selenium_grid/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ The Selenium Grid Hub allows you to distribute tests to run in parallel across m

### Running the Selenium Grid Hub

You may need to download selenium-server-standalone-2.50.1.jar (or the latest version) separately. That file is not present with this repository to save space. You can download that file from here:
* http://docs.seleniumhq.org/download/
or here:
* http://selenium-release.storage.googleapis.com/index.html?path=2.50/
Once you have downloaded the jar file, put it in this folder (the "integrations/selenium_grid" folder).
First, download the latest selenium-server-standalone jar file to this folder (integrations/selenium_grid):
```bash
./download_selenium
```
Now you can start up the Grid Hub:
```bash
./grid-hub start
```
Now add a Grid Node to the Grid Hub:
```bash
./grid-node start
```
(NOTE: If the Grid Node is not running on the same machine as the Grid Hub, update the address from the script.)
You should be able to see the Grid Console up and running from here: [http://0.0.0.0:4444/grid/console](http://0.0.0.0:4444/grid/console) (NOTE: That's the address if you're running locally from localhost.)

More detailed info about connecting to the Selenium Grid Hub can be found here:
* https://theintern.github.io/intern/#selenium-grid
and here:
* https://github.com/SeleniumHQ/selenium/wiki/Grid2
For even more information, look here:
* https://github.com/SeleniumHQ/selenium/wiki
#### More detailed info about connecting to the Selenium Grid Hub can be found here:
* [https://theintern.github.io/intern/#selenium-grid](https://theintern.github.io/intern/#selenium-grid)
* [https://github.com/SeleniumHQ/selenium/wiki/Grid2](https://github.com/SeleniumHQ/selenium/wiki/Grid2)
* [https://github.com/SeleniumHQ/selenium/wiki](https://github.com/SeleniumHQ/selenium/wiki/Grid2)
11 changes: 11 additions & 0 deletions integrations/selenium_grid/download_selenium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
""" Download the selenium server jar file """

import os
from seleniumbase.core import selenium_launcher

if not selenium_launcher.is_available_locally():
selenium_launcher.download_selenium()

for filename in os.listdir("."):
if filename.startswith("selenium-server-standalone-"):
os.rename(filename, "selenium-server-standalone.jar")
72 changes: 72 additions & 0 deletions integrations/selenium_grid/grid-hub
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

#
# Usage: grid-hub {start|stop}
#

source $(dirname $0)/util

EXPECTED_ARGS=1
E_BADARGS=65

DO_showUsage() {
echo "Usage: $(basename $0) {start|stop}"
exit $E_BADARGS
}

if [ $# -ne $EXPECTED_ARGS ]; then
DO_showUsage
fi

################################################################################

WEBDRIVER_SERVER_JAR=./selenium-server-standalone.jar
WEBDRIVER_HUB_PARAMS="-role hub -port 4444"
WEBDRIVER_HUB_PIDFILE="/tmp/webdriver_hub.pid"

if [ ! -f $WEBDRIVER_SERVER_JAR ]; then
echo "You must place the Selenium-WebDriver standalone JAR file at ${WEBDRIVER_SERVER_JAR} before proceeding."
exit 1
fi

case "$1" in
start)
echo "Starting Selenium-WebDriver Grid2 hub..."
if [ -f $WEBDRIVER_HUB_PIDFILE ]; then
echo "${FAIL_MSG} Selenium-WebDriver Grid2 hub already running with PID $(cat $WEBDRIVER_HUB_PIDFILE). Run 'grid-hub stop' or 'grid-hub restart'."
exit 1
else
START_HUB_CMD="java -Djava.util.logging.config.file=test/logging.properties -jar ${WEBDRIVER_SERVER_JAR} ${WEBDRIVER_HUB_PARAMS}"
$START_HUB_CMD &
PID=$!
echo $PID > "${WEBDRIVER_HUB_PIDFILE}"
echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 hub started successfully."
echo "To see full log output, remove the java.util.logging.config.file parameter from script/grid-hub"
fi
;;
stop)
echo "Stopping Selenium-WebDriver Grid2 hub..."
if [ -f $WEBDRIVER_HUB_PIDFILE ]; then
PID=$(cat $WEBDRIVER_HUB_PIDFILE)
kill $PID
rm $WEBDRIVER_HUB_PIDFILE
sleep 1
if [[ $(ps -A | egrep "^${PID}") ]]; then
echo "${FAIL_MSG} Tried to kill the hub with PID ${PID}, but was unsuccessful. You need to kill it with something stronger, like 'kill -9'"
exit 1
else
echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 hub stopped successfully."
exit 0
fi
else
echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 hub has already been stopped."
exit 0
fi
;;
restart)
$0 stop
$0 start
;;
*)
DO_showUsage
esac
72 changes: 72 additions & 0 deletions integrations/selenium_grid/grid-node
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

#
# Usage: grid-node {start|stop}
#

source $(dirname $0)/util

EXPECTED_ARGS=1
E_BADARGS=65

DO_showUsage() {
echo "Usage: $(basename $0) {start|stop}"
exit $E_BADARGS
}

if [ $# -ne $EXPECTED_ARGS ]; then
DO_showUsage
fi

################################################################################

WEBDRIVER_SERVER_JAR=./selenium-server-standalone.jar
WEBDRIVER_NODE_PARAMS="-role webdriver -hubHost 127.0.0.1 -hubPort 4444 -host 127.0.0.1 -browserName=firefox"
WEBDRIVER_NODE_PIDFILE="/tmp/webdriver_node.pid"

if [ ! -f $WEBDRIVER_SERVER_JAR ]; then
echo "You must place the Selenium-WebDriver standalone JAR file at ${WEBDRIVER_SERVER_JAR} before proceeding."
exit 1
fi

case "$1" in
start)
echo "Starting Selenium-WebDriver Grid2 node..."
if [ -f $WEBDRIVER_NODE_PIDFILE ]; then
echo "${FAIL_MSG} Selenium-WebDriver Grid2 node already running with PID $(cat $WEBDRIVER_NODE_PIDFILE). Run 'grid-node stop' or 'grid-node restart'."
exit 1
else
START_NODE_CMD="java -Djava.util.logging.config.file=test/logging.properties -jar ${WEBDRIVER_SERVER_JAR} ${WEBDRIVER_NODE_PARAMS}"
$START_NODE_CMD &
PID=$!
echo $PID > "${WEBDRIVER_NODE_PIDFILE}"
echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 node started successfully."
echo "To see full log output, remove the java.util.logging.config.file parameter from script/grid-node"
fi
;;
stop)
echo "Stopping Selenium-WebDriver Grid2 node..."
if [ -f $WEBDRIVER_NODE_PIDFILE ]; then
PID=$(cat $WEBDRIVER_NODE_PIDFILE)
kill $PID
rm $WEBDRIVER_NODE_PIDFILE
sleep 1
if [[ $(ps -A | egrep "^${PID}") ]]; then
echo "${FAIL_MSG} Tried to kill the node with PID ${PID}, but was unsuccessful. You need to kill it with something stronger, like 'kill -9'"
exit 1
else
echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 node stopped successfully."
exit 0
fi
else
echo "${SUCCESS_MSG} Selenium-WebDriver Grid2 node has already been stopped."
exit 0
fi
;;
restart)
$0 stop
$0 start
;;
*)
DO_showUsage
esac
2 changes: 1 addition & 1 deletion integrations/selenium_grid/start-selenium-node.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cd c:\
java -jar selenium-server-standalone-2.50.1.jar -role node -hub http://[ENTER URL OF THE GRID HUB SERVER]:4444/grid/register -browser browserName=chrome,maxInstances=5 -browser browserName=firefox,maxInstances=5 -browser browserName="internet explorer",maxInstances=1
java -jar selenium-server-standalone.jar -role node -hub http://[ENTER URL OF THE GRID HUB SERVER]:4444/grid/register -browser browserName=chrome,maxInstances=5 -browser browserName=firefox,maxInstances=5 -browser browserName="internet explorer",maxInstances=1
2 changes: 1 addition & 1 deletion integrations/selenium_grid/start-selenium-server.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
java -jar selenium-server-standalone-2.50.1.jar -role hub
java -jar selenium-server-standalone.jar -role hub
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='seleniumbase',
version='1.1.22',
version='1.1.23',
url='https://github.com/mdmintz/SeleniumBase',
author='Michael Mintz',
author_email='@mintzworld',
Expand Down