【发布时间】:2020-09-04 06:55:35
【问题描述】:
我正在尝试在 android 模拟器上自动执行一些任务,但遇到了一个非常奇怪的问题:我的 Appium + Python 脚本甚至无法启动应用程序,而 Appium Desktop 一切正常。
以下是详细信息:
首先,我启动我的 avd(使用第一个脚本):
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)
然后,如果我在 localhost 上启动 Appium Desktop,端口 4723 具有所需的功能:
{
"platformName": "Android",
"platformVersion": "10",
"deviceName": "Android Emulator",
"appPackage": "com.google.android.calculator",
"appActivity": "com.android.calculator2.Calculator"
}
谷歌计算器启动。
但是,如果我启动以下脚本,脚本会卡在 webdriver.remote 行中:
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
你能帮我让这个脚本运行吗?在一周左右的时间里,我已经尝试了很多东西,但我不知道出了什么问题。
感谢您的帮助,
【问题讨论】:
标签: python appium python-appium