From b2873c31ccd55a34daf423e92189dda825b13cb2 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 23 Oct 2017 12:56:05 +0200 Subject: [PATCH] wireless devices autoconnection (#67) * refactored wireless device connection script added daemon for wireless device autoconnection * updated README * updated Dockerfile * refactored autoconnect function Updated entry point and Dockerfile --- Appium/Dockerfile | 8 ++++++-- Appium/entry_point.sh | 4 ++++ Appium/generate_config.sh | 14 -------------- Appium/wireless_autoconnect.sh | 19 +++++++++++++++++++ Appium/wireless_connect.sh | 18 ++++++++++++++++++ README.md | 3 ++- 6 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 Appium/wireless_autoconnect.sh create mode 100644 Appium/wireless_connect.sh diff --git a/Appium/Dockerfile b/Appium/Dockerfile index ddfe094..ca9f43e 100644 --- a/Appium/Dockerfile +++ b/Appium/Dockerfile @@ -115,11 +115,15 @@ EXPOSE 4723 COPY \ Appium/entry_point.sh \ Appium/generate_config.sh \ + Appium/wireless_connect.sh \ + Appium/wireless_autoconnect.sh \ /root/ RUN chmod +x /root/entry_point.sh && \ - chmod +x /root/generate_config.sh + chmod +x /root/generate_config.sh && \ + chmod +x /root/wireless_connect.sh && \ + chmod +x /root/wireless_autoconnect.sh #======================================== # Run xvfb and appium server #======================================== -CMD ["/root/entry_point.sh"] +CMD /root/wireless_autoconnect.sh && /root/entry_point.sh diff --git a/Appium/entry_point.sh b/Appium/entry_point.sh index e8e7cd3..8a4ebce 100755 --- a/Appium/entry_point.sh +++ b/Appium/entry_point.sh @@ -3,6 +3,10 @@ NODE_CONFIG_JSON="/root/nodeconfig.json" CMD="xvfb-run appium" +if [ ! -z "$REMOTE_ADB" ]; then + /root/wireless_connect.sh +fi + if [ ! -z "$CONNECT_TO_GRID" ]; then /root/generate_config.sh $NODE_CONFIG_JSON CMD+=" --nodeconfig $NODE_CONFIG_JSON" diff --git a/Appium/generate_config.sh b/Appium/generate_config.sh index c5af664..71b5a43 100755 --- a/Appium/generate_config.sh +++ b/Appium/generate_config.sh @@ -30,20 +30,6 @@ if [ -z "$NODE_TIMEOUT" ]; then NODE_TIMEOUT=300 fi -if [ ! -z "$REMOTE_ADB" ]; then - if [ ! -z "$ANDROID_DEVICES" ]; then - IFS=',' read -r -a array <<< "$ANDROID_DEVICES" - for i in "${!array[@]}" - do - echo "Connecting to: ${array[$i]}" - adb connect ${array[$i]} - echo "Success!" - done - #Give time to finish connection - sleep 1 - fi -fi - #Get device names devices=($(adb devices | grep -oP "\K([^ ]+)(?=\sdevice(\W|$))")) echo "Devices found: ${#devices[@]}" diff --git a/Appium/wireless_autoconnect.sh b/Appium/wireless_autoconnect.sh new file mode 100644 index 0000000..9b8717d --- /dev/null +++ b/Appium/wireless_autoconnect.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ ! -z "$REMOTE_ADB" ]; then + + if [ -z "$REMOTE_ADB_POLLING_SEC" ]; then + REMOTE_ADB_POLLING_SEC=5 + fi + + function connect() { + while true + do + #to avoid immediate run + sleep ${REMOTE_ADB_POLLING_SEC} + /root/wireless_connect.sh + done + } + + ( trap "true" HUP ; connect ) >/dev/null 2>/dev/null :\ \[,\:\\] +- REMOTE_ADB_POLLING_SEC=60 (default: 5, interval between polling the list of connected devices in order to connect to lost remote devices) ``` -$ docker run -d -p 4723:4723 -e REMOTE_ADB=True -e ANDROID_DEVICES=192.168.0.5:5555,192.168.0.6:5555 +$ docker run -d -p 4723:4723 -e REMOTE_ADB=True -e ANDROID_DEVICES=192.168.0.5:5555,192.168.0.6:5555 -e REMOTE_ADB_POLLING_SEC=60 ```