Skip to content

Commit

Permalink
wireless devices autoconnection (#67)
Browse files Browse the repository at this point in the history
* refactored wireless device connection script
added daemon for wireless device autoconnection

* updated README

* updated Dockerfile

* refactored autoconnect function
Updated entry point and Dockerfile
  • Loading branch information
red-avtovo authored and SrinivasanTarget committed Oct 23, 2017
1 parent fc226dc commit b2873c3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
8 changes: 6 additions & 2 deletions Appium/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Appium/entry_point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 0 additions & 14 deletions Appium/generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
Expand Down
19 changes: 19 additions & 0 deletions Appium/wireless_autoconnect.sh
Original file line number Diff line number Diff line change
@@ -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 </dev/null & disown
fi
18 changes: 18 additions & 0 deletions Appium/wireless_connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ ! -z "$ANDROID_DEVICES" ]; then
connected_devices=$(adb devices)
IFS=',' read -r -a array <<< "$ANDROID_DEVICES"
for i in "${!array[@]}"
do
array_device=$(echo ${array[$i]} | tr -d " ")
#string contains check
if [[ ${connected_devices} != *${array_device}* ]]; then
echo "Connecting to: ${array_device}"
adb connect ${array_device}
echo "Success!"
fi
done
#Give time to finish connection
sleep 1
fi
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ Then run docker container with following parameters:

- REMOTE\_ADB=True
- ANDROID\_DEVICES=\<android\_device\_host\>:\<android\_device\_port\> \[,\<android\_device\_host\>:\<android\_device\_port\>\]
- 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
```

Expand Down

0 comments on commit b2873c3

Please sign in to comment.