I am trying to automate some tasks on an android emulator, and faces a very strange problem : my Appium + Python script cannot even launch the application, whereas everything works fine with Appium Desktop.
Here are the details :
First, I launch my avd (with a first script):
date = datetime.now().strftime("%Y%m%d%H%M")
try:
emu_process = subprocess.run("adb kill-server")
print(emu_process)
except Exception as e:
print("exception : {}".format(e))
pass
emu_process = subprocess.Popen(["{}\emulator\emulator.exe".format(os.getenv('ANDROID_SDK_ROOT')),
"-avd", "{}".format(emu_model)])
emu_process = subprocess.run("adb start-server")
# Wait until the device is connected
time.sleep(2)
ready = False
while not ready:
emu_process = subprocess.run("adb devices",
capture_output=True, text=True)
print(emu_process.stdout)
print(emu_process.stdout[:4] == "List")
if emu_process.stdout[:4] == "List" and \
emu_process.stdout[-8:-2] == "device":
ready=True
time.sleep(2)
# store logcat on a .txt file
emu_process = subprocess.Popen(["adb", "logcat", "*:I", ">",
"{}_adb.log".format(date)], shell=True)
Then, if I launch Appium Desktop on localhost, port 4723 with the desired capabilities :
{
"platformName": "Android",
"platformVersion": "10",
"deviceName": "Android Emulator",
"appPackage": "com.google.android.calculator",
"appActivity": "com.android.calculator2.Calculator"
}
The google calculator is launched.
BUT, if I launch the Following script, the script is stuck in the webdriver.remote line :
from appium import webdriver
import subprocess
from datetime import datetime
from appium.webdriver.appium_service import AppiumService
# kill current node instance, to avoid multiple appium session
subprocess.Popen(['taskkill', '/F', '/IM', 'node.exe'])
ip_address = '127.0.0.1'
port = '4723'
date = datetime.now().strftime("%Y%m%d%H%M")
# Run Appium server, store logfile
appium_service = AppiumService()
appium_service.start(args=['--address', ip_address, '-p', port,
'--log-timestamp', '--log', 'D:\Temp\{}_appium.log'.format(date)])
print("appium is running : ", appium_service.is_running) # return True, ok
print("appium is listening : ", appium_service.is_listening) # return True, ok
desired_caps = {"platformName": "Android",
"platformVersion": "10",
"deviceName": "Android Emulator",
"appPackage": "com.google.android.calculator",
"appActivity": "com.android.calculator2.Calculator"
}
driver = webdriver.Remote(
command_executor='http://{}:{}/wd/hub'.format(ip_address, port),
desired_capabilities=desired_caps
)
print("appium is connected to the device") # Nothing is printed, the script is stuck in the webdriver.remote line
Could you please help me to make this script running ? I have already tried a lot of things, during a week or so, and I have no idea what is going wrong.
Thank you for any help,