Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be more appropriate to user grep for this purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically it is the same thing

echo "Connecting to: ${array_device}"
adb connect ${array_device}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check the exit code here to make sure the connection was really successful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't care. Anyway script will be run again after specified delay.
It is the main idea of this PR. Script will try to reconnect to remote device in any case

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