Skip to content

Commit

Permalink
Fixed device remote connection
Browse files Browse the repository at this point in the history
  • Loading branch information
budtmo committed Feb 2, 2023
1 parent 71f18ed commit 9c91dfb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Appium/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:focal-20230126
FROM ubuntu:bionic-20230126

ENV DEBIAN_FRONTEND=noninteractive

Expand Down
12 changes: 7 additions & 5 deletions Appium/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

# It is workaround to access adb from androidusr
echo "Prepare adb to have access to device"
sudo /opt/android/platform-tools/adb devices
sudo /opt/android/platform-tools/adb devices >/dev/null
sudo chown -R 1300:1301 .android
echo "adb can be used now"

# Connect device via wireless
if [ "${REMOTE_ADB}" = true ]; then
echo "Connect device via wireless"
./${APP_PATH}/wireless_autoconnect.sh
# Avoid lost connection
${APP_PATH}/wireless_autoconnect.sh && \
${APP_PATH}/wireless_connect.sh
fi

# Command to start Appium
Expand All @@ -18,15 +20,15 @@ command="xvfb-run appium --log $APPIUM_LOG"

# Adding Selenium configurations if needed
if [ "${CONNECT_TO_GRID}" = true ]; then
NODE_CONFIG_JSON="/${APP_PATH}/nodeconfig.json"
NODE_CONFIG_JSON="${APP_PATH}/nodeconfig.json"
if [ "${CUSTOM_NODE_CONFIG}" != true ]; then
./${APP_PATH}/generate_selenium_config.sh ${NODE_CONFIG_JSON}
${APP_PATH}/generate_selenium_config.sh ${NODE_CONFIG_JSON}
fi
command+=" --nodeconfig ${NODE_CONFIG_JSON}"
fi

if [ "${DEFAULT_CAPABILITIES}" = true ]; then
DEFAULT_CAPABILITIES_JSON="/${APP_PATH}/defaultcapabilities.json"
DEFAULT_CAPABILITIES_JSON="${APP_PATH}/defaultcapabilities.json"
command+=" --default-capabilities ${DEFAULT_CAPABILITIES_JSON}"
fi

Expand Down
2 changes: 1 addition & 1 deletion Appium/wireless_autoconnect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [ ! -z "${REMOTE_ADB}" ]; then
while true; do
#to avoid immediate run
sleep ${REMOTE_ADB_POLLING_SEC}
/root/wireless_connect.sh
${APP_PATH}/wireless_connect.sh
done
}

Expand Down
8 changes: 4 additions & 4 deletions Appium/wireless_connect.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/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}
adb connect ${array_device} >/dev/null 2>/dev/null
#Give time to finish connection
sleep 2
adb devices
echo "Success!"
fi
done
#Give time to finish connection
sleep 1
fi

0 comments on commit 9c91dfb

Please sign in to comment.