Skip to content

Commit 8540fdd

Browse files
committed
Merge pull request #206 from kayabendroth/2.52.0-fix-xvfb-servernum
2.52.0 fix xvfb servernum
2 parents 60f677a + 1b2786e commit 8540fdd

File tree

15 files changed

+129
-12
lines changed

15 files changed

+129
-12
lines changed

NodeBase/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ RUN apt-get update -qqy \
2323
#==============================
2424
# Scripts to run Selenium Node
2525
#==============================
26-
COPY entry_point.sh /opt/bin/entry_point.sh
26+
COPY \
27+
entrypoint.sh \
28+
functions.sh \
29+
/opt/bin/
2730
RUN chmod +x /opt/bin/entry_point.sh
2831

2932
#============================

NodeBase/Dockerfile.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ RUN apt-get update -qqy \
2222
#==============================
2323
# Scripts to run Selenium Node
2424
#==============================
25-
COPY entry_point.sh /opt/bin/entry_point.sh
25+
COPY \
26+
entry_point.sh \
27+
functions.sh \
28+
/opt/bin/
2629
RUN chmod +x /opt/bin/entry_point.sh
2730

2831
#============================

NodeBase/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
if [ ! -e /opt/selenium/config.json ]; then
@@ -28,7 +31,8 @@ fi
2831

2932
# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs
3033

31-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
34+
SERVERNUM=$(get_server_num)
35+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
3236
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
3337
-role node \
3438
-hub http://$HUB_PORT_4444_TCP_ADDR:$HUB_PORT_4444_TCP_PORT/grid/register \

NodeBase/functions.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# https://github.com/SeleniumHQ/docker-selenium/issues/184
4+
function get_server_num() {
5+
echo $(echo $DISPLAY | sed -r -e 's/([^:]+)?:([0-9]+)(\.[0-9]+)?/\2/')
6+
}
7+

NodeBase/test-functions.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bats
2+
3+
source "$BATS_TEST_DIRNAME"/functions.sh
4+
5+
# Tests for function get_server_num
6+
#
7+
# Test data from http://askubuntu.com/questions/432255/what-is-display-environment-variable
8+
@test 'get_server_num of :99.1' {
9+
10+
export DISPLAY=':99.1'
11+
expected_result='99'
12+
result="$(get_server_num)"
13+
echo "result: $result"
14+
[ "$result" == "$expected_result" ]
15+
}
16+
17+
@test 'get_server_num of :0' {
18+
19+
export DISPLAY=':0'
20+
expected_result='0'
21+
result="$(get_server_num)"
22+
echo "result: $result"
23+
[ "$result" == "$expected_result" ]
24+
}
25+
26+
@test 'get_server_num of localhost:4' {
27+
28+
export DISPLAY='localhost:4'
29+
expected_result='4'
30+
result="$(get_server_num)"
31+
echo "result: $result"
32+
[ "$result" == "$expected_result" ]
33+
}
34+
35+
@test 'get_server_num of google.com:0' {
36+
37+
export DISPLAY='google.com:0'
38+
expected_result='0'
39+
result="$(get_server_num)"
40+
echo "result: $result"
41+
[ "$result" == "$expected_result" ]
42+
}
43+
44+
@test 'get_server_num of google.com:99.1' {
45+
46+
export DISPLAY='google.com:99.1'
47+
expected_result='99'
48+
result="$(get_server_num)"
49+
echo "result: $result"
50+
[ "$result" == "$expected_result" ]
51+
}
52+

NodeChromeDebug/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
if [ ! -e /opt/selenium/config.json ]; then
@@ -28,12 +31,13 @@ fi
2831

2932
# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs
3033

34+
SERVERNUM=$(get_server_num)
3135
env | cut -f 1 -d "=" | sort > asroot
3236
sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
3337
sudo -E -i -u seluser \
3438
$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done) \
3539
DISPLAY=$DISPLAY \
36-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
40+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
3741
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
3842
-role node \
3943
-hub http://$HUB_PORT_4444_TCP_ADDR:$HUB_PORT_4444_TCP_PORT/grid/register \

NodeFirefoxDebug/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
if [ ! -e /opt/selenium/config.json ]; then
@@ -28,12 +31,13 @@ fi
2831

2932
# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs
3033

34+
SERVERNUM=$(get_server_num)
3135
env | cut -f 1 -d "=" | sort > asroot
3236
sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
3337
sudo -E -i -u seluser \
3438
$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done) \
3539
DISPLAY=$DISPLAY \
36-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
40+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
3741
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
3842
-role node \
3943
-hub http://$HUB_PORT_4444_TCP_ADDR:$HUB_PORT_4444_TCP_PORT/grid/register \

Standalone/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
function shutdown {
@@ -10,7 +13,8 @@ if [ ! -z "$SE_OPTS" ]; then
1013
echo "appending selenium options: ${SE_OPTS}"
1114
fi
1215

13-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
16+
SERVERNUM=$(get_server_num)
17+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
1418
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
1519
${SE_OPTS} &
1620
NODE_PID=$!

StandaloneChrome/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
function shutdown {
@@ -10,7 +13,8 @@ if [ ! -z "$SE_OPTS" ]; then
1013
echo "appending selenium options: ${SE_OPTS}"
1114
fi
1215

13-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
16+
SERVERNUM=$(get_server_num)
17+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
1418
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
1519
${SE_OPTS} &
1620
NODE_PID=$!

StandaloneChromeDebug/entry_point.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
2-
source "/opt/bin/clear_x_locks.sh"
2+
3+
source /opt/bin/clear_x_locks.sh
4+
source /opt/bin/functions.sh
35

46
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
57

@@ -12,12 +14,13 @@ if [ ! -z "$SE_OPTS" ]; then
1214
echo "appending selenium options: ${SE_OPTS}"
1315
fi
1416

17+
SERVERNUM=$(get_server_num)
1518
env | cut -f 1 -d "=" | sort > asroot
1619
sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
1720
sudo -E -i -u seluser \
1821
$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done) \
1922
DISPLAY=$DISPLAY \
20-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
23+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
2124
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
2225
${SE_OPTS} &
2326
NODE_PID=$!

StandaloneDebug/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
function shutdown {
@@ -10,12 +13,13 @@ if [ ! -z "$SE_OPTS" ]; then
1013
echo "appending selenium options: ${SE_OPTS}"
1114
fi
1215

16+
SERVERNUM=$(get_server_num)
1317
env | cut -f 1 -d "=" | sort > asroot
1418
sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
1519
sudo -E -i -u seluser \
1620
$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done) \
1721
DISPLAY=$DISPLAY \
18-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
22+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
1923
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
2024
${SE_OPTS} &
2125
NODE_PID=$!

StandaloneFirefox/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
function shutdown {
@@ -10,7 +13,8 @@ if [ ! -z "$SE_OPTS" ]; then
1013
echo "appending selenium options: ${SE_OPTS}"
1114
fi
1215

13-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
16+
SERVERNUM=$(get_server_num)
17+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
1418
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
1519
${SE_OPTS} &
1620
NODE_PID=$!

StandaloneFirefoxDebug/entry_point.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
3+
source /opt/bin/functions.sh
4+
25
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
36

47
function shutdown {
@@ -10,12 +13,13 @@ if [ ! -z "$SE_OPTS" ]; then
1013
echo "appending selenium options: ${SE_OPTS}"
1114
fi
1215

16+
SERVERNUM=$(get_server_num)
1317
env | cut -f 1 -d "=" | sort > asroot
1418
sudo -E -u seluser -i env | cut -f 1 -d "=" | sort > asseluser
1519
sudo -E -i -u seluser \
1620
$(for E in $(grep -vxFf asseluser asroot); do echo $E=$(eval echo \$$E); done) \
1721
DISPLAY=$DISPLAY \
18-
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
22+
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
1923
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
2024
${SE_OPTS} &
2125
NODE_PID=$!

circle.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ machine:
33
- docker
44
environment:
55
DELETE_CONTAINERS: false
6+
67
dependencies:
78
override:
9+
# Install bats for testing shell scripts.
10+
- git clone https://github.com/sstephenson/bats.git && cd bats && sudo ./install.sh /usr/local
811
- docker info
912
- make build
1013

test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ if [ -n "$1" ] && [ $1 == 'debug' ]; then
55
DEBUG='-debug'
66
fi
77

8+
# Due to the dependency GNU sed, we're skipping this part when running
9+
# on Mac OS X.
10+
if [ "$(uname)" != 'Darwin' ] ; then
11+
echo 'Testing shell functions...'
12+
which bats > /dev/null 2>&1
13+
if [ $? -ne 0 ] ; then
14+
echo "Could not find 'bats'. Please install it first, e.g., following https://github.com/sstephenson/bats#installing-bats-from-source."
15+
exit 1
16+
fi
17+
NodeBase/test-functions.sh || exit 1
18+
else
19+
echo 'Skipping shell functions test on Mac OS X.'
20+
fi
21+
822
echo Building test container image
923
docker build -t selenium/test:local ./Test
1024

0 commit comments

Comments
 (0)