-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functionality to connect to selenium grid (#43)
* Added functionality to connect to selenium grid * Dynamically get device properties, test for config creation * Added bats-mock module for testing * Selenium grid functionality tests with mocks
- Loading branch information
1 parent
004ae91
commit ea5cc15
Showing
7 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "Appium/tests/helpers/mocks"] | ||
path = Appium/tests/helpers/mocks | ||
url = https://github.com/jasonkarns/bats-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
NODE_CONFIG_JSON="/root/nodeconfig.json" | ||
CMD="xvfb-run appium" | ||
|
||
if [ ! -z "$CONNECT_TO_GRID" ]; then | ||
/root/generate_config.sh $NODE_CONFIG_JSON | ||
CMD+=" --nodeconfig $NODE_CONFIG_JSON" | ||
fi | ||
|
||
$CMD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
node_config_json=$1 | ||
|
||
if [ -z "$PLATFORM_NAME" ]; then | ||
PLATFORM_NAME="Android" | ||
fi | ||
|
||
if [ -z "$APPIUM_HOST" ]; then | ||
APPIUM_HOST="127.0.0.1" | ||
fi | ||
|
||
if [ -z "$APPIUM_PORT" ]; then | ||
APPIUM_PORT=4723 | ||
fi | ||
|
||
if [ -z "$SELENIUM_HOST" ]; then | ||
SELENIUM_HOST="172.17.0.1" | ||
fi | ||
|
||
if [ -z "$SELENIUM_PORT" ]; then | ||
SELENIUM_PORT=4444 | ||
fi | ||
|
||
if [ -z "$BROWSER_NAME" ]; then | ||
BROWSER_NAME="android" | ||
fi | ||
|
||
#Get device names | ||
devices=($(adb devices | grep -oP "\K(\w+)(?=\sdevice(\W|$))")) | ||
|
||
#Create capabilities json configs | ||
function create_capabilities() { | ||
capabilities="" | ||
for name in ${devices[@]}; do | ||
os_version="$(adb -s $name shell getprop ro.build.version.release | tr -d '\r')" | ||
capabilities+=$(cat <<_EOF | ||
{ | ||
"platform": "$PLATFORM_NAME", | ||
"platformName": "$PLATFORM_NAME", | ||
"version": "$os_version", | ||
"browserName": "$BROWSER_NAME", | ||
"deviceName": "$name", | ||
"maxInstances": 1 | ||
} | ||
_EOF | ||
) | ||
if [ ${devices[-1]} != $name ]; then | ||
capabilities+=', ' | ||
fi | ||
done | ||
echo "$capabilities" | ||
} | ||
|
||
#Final node configuration json string | ||
nodeconfig=$(cat <<_EOF | ||
{ | ||
"capabilities": [$(create_capabilities)], | ||
"configuration": { | ||
"cleanUpCycle": 2000, | ||
"timeout": 30000, | ||
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy", | ||
"url": "http://$APPIUM_HOST:$APPIUM_PORT/wd/hub", | ||
"host": "$APPIUM_HOST", | ||
"port": $APPIUM_PORT, | ||
"maxSession": 6, | ||
"register": true, | ||
"registerCycle": 5000, | ||
"hubHost": "$SELENIUM_HOST", | ||
"hubPort": $SELENIUM_PORT | ||
} | ||
} | ||
_EOF | ||
) | ||
echo "$nodeconfig" > $node_config_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helpers/mocks/stub | ||
|
||
default_node_config=\ | ||
'{ | ||
"capabilities": [{ | ||
"platform": "Android", | ||
"platformName": "Android", | ||
"version": "7.1.1", | ||
"browserName": "android", | ||
"deviceName": "73QDU16916010699", | ||
"maxInstances": 1 | ||
}, { | ||
"platform": "Android", | ||
"platformName": "Android", | ||
"version": "5.1.1", | ||
"browserName": "android", | ||
"deviceName": "4b13354b80b36200", | ||
"maxInstances": 1 | ||
}], | ||
"configuration": { | ||
"cleanUpCycle": 2000, | ||
"timeout": 30000, | ||
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy", | ||
"url": "http://127.0.0.1:4723/wd/hub", | ||
"host": "127.0.0.1", | ||
"port": 4723, | ||
"maxSession": 6, | ||
"register": true, | ||
"registerCycle": 5000, | ||
"hubHost": "172.17.0.1", | ||
"hubPort": 4444 | ||
} | ||
}' | ||
node_config_json="/root/nodeconfig.json" | ||
adb_devices_output='73QDU16916010699 device 4b13354b80b36200 device' | ||
|
||
@test 'Verify selenium grid config is created' { | ||
stub adb \ | ||
"devices : echo $adb_devices_output" \ | ||
"-s 73QDU16916010699 shell getprop ro.build.version.release : echo 7.1.1" \ | ||
"-s 4b13354b80b36200 shell getprop ro.build.version.release : echo 5.1.1" | ||
|
||
run /root/generate_config.sh $node_config_json | ||
[ "$(cat $node_config_json)" == "$default_node_config" ] | ||
|
||
unstub adb | ||
} |