我正试图在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)然后,如果我在本地主机上启动Appium Desktop,端口为4723,并具有所需的功能:
{
"platformName": "Android",
"platformVersion": "10",
"deviceName": "Android Emulator",
"appPackage": "com.google.android.calculator",
"appActivity": "com.android.calculator2.Calculator"
}google计算器启动。
但是,如果我启动以下脚本,该脚本就会卡在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你能帮我让这个脚本运行吗?我已经尝试了很多东西,在一周左右的时间里,我不知道哪里出了问题。
谢谢你的帮助
发布于 2020-07-15 07:06:59
好了,我有答案了。我似乎是一个bug,在这里引用:https://github.com/appium/python-client/issues/534
解决方法是编写
appium_service.start(args=..., stdout=sp.DEVNULL)而不是:
appium_service.start(args=...)希望其他人会像我一样高兴地找到这个答案:)
https://stackoverflow.com/questions/61870221
复制相似问题