Skip to content

Commit b2873c3

Browse files
red-avtovoSrinivasanTarget
authored andcommitted
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
1 parent fc226dc commit b2873c3

File tree

6 files changed

+49
-17
lines changed

6 files changed

+49
-17
lines changed

Appium/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ EXPOSE 4723
115115
COPY \
116116
Appium/entry_point.sh \
117117
Appium/generate_config.sh \
118+
Appium/wireless_connect.sh \
119+
Appium/wireless_autoconnect.sh \
118120
/root/
119121
RUN chmod +x /root/entry_point.sh && \
120-
chmod +x /root/generate_config.sh
122+
chmod +x /root/generate_config.sh && \
123+
chmod +x /root/wireless_connect.sh && \
124+
chmod +x /root/wireless_autoconnect.sh
121125

122126
#========================================
123127
# Run xvfb and appium server
124128
#========================================
125-
CMD ["/root/entry_point.sh"]
129+
CMD /root/wireless_autoconnect.sh && /root/entry_point.sh

Appium/entry_point.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
NODE_CONFIG_JSON="/root/nodeconfig.json"
44
CMD="xvfb-run appium"
55

6+
if [ ! -z "$REMOTE_ADB" ]; then
7+
/root/wireless_connect.sh
8+
fi
9+
610
if [ ! -z "$CONNECT_TO_GRID" ]; then
711
/root/generate_config.sh $NODE_CONFIG_JSON
812
CMD+=" --nodeconfig $NODE_CONFIG_JSON"

Appium/generate_config.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ if [ -z "$NODE_TIMEOUT" ]; then
3030
NODE_TIMEOUT=300
3131
fi
3232

33-
if [ ! -z "$REMOTE_ADB" ]; then
34-
if [ ! -z "$ANDROID_DEVICES" ]; then
35-
IFS=',' read -r -a array <<< "$ANDROID_DEVICES"
36-
for i in "${!array[@]}"
37-
do
38-
echo "Connecting to: ${array[$i]}"
39-
adb connect ${array[$i]}
40-
echo "Success!"
41-
done
42-
#Give time to finish connection
43-
sleep 1
44-
fi
45-
fi
46-
4733
#Get device names
4834
devices=($(adb devices | grep -oP "\K([^ ]+)(?=\sdevice(\W|$))"))
4935
echo "Devices found: ${#devices[@]}"

Appium/wireless_autoconnect.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
if [ ! -z "$REMOTE_ADB" ]; then
4+
5+
if [ -z "$REMOTE_ADB_POLLING_SEC" ]; then
6+
REMOTE_ADB_POLLING_SEC=5
7+
fi
8+
9+
function connect() {
10+
while true
11+
do
12+
#to avoid immediate run
13+
sleep ${REMOTE_ADB_POLLING_SEC}
14+
/root/wireless_connect.sh
15+
done
16+
}
17+
18+
( trap "true" HUP ; connect ) >/dev/null 2>/dev/null </dev/null & disown
19+
fi

Appium/wireless_connect.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
if [ ! -z "$ANDROID_DEVICES" ]; then
4+
connected_devices=$(adb devices)
5+
IFS=',' read -r -a array <<< "$ANDROID_DEVICES"
6+
for i in "${!array[@]}"
7+
do
8+
array_device=$(echo ${array[$i]} | tr -d " ")
9+
#string contains check
10+
if [[ ${connected_devices} != *${array_device}* ]]; then
11+
echo "Connecting to: ${array_device}"
12+
adb connect ${array_device}
13+
echo "Success!"
14+
fi
15+
done
16+
#Give time to finish connection
17+
sleep 1
18+
fi

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ Then run docker container with following parameters:
110110
111111
- REMOTE\_ADB=True
112112
- ANDROID\_DEVICES=\<android\_device\_host\>:\<android\_device\_port\> \[,\<android\_device\_host\>:\<android\_device\_port\>\]
113+
- REMOTE_ADB_POLLING_SEC=60 (default: 5, interval between polling the list of connected devices in order to connect to lost remote devices)
113114
114115
```
115-
$ docker run -d -p 4723:4723 -e REMOTE_ADB=True -e ANDROID_DEVICES=192.168.0.5:5555,192.168.0.6:5555
116+
$ 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
116117

117118
```
118119

0 commit comments

Comments
 (0)