首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Appium错误: appium-python脚本无法连接到应用程序,而Appium Desktop可以

Appium错误: appium-python脚本无法连接到应用程序,而Appium Desktop可以
EN

Stack Overflow用户
提问于 2020-05-18 21:02:18
回答 1查看 268关注 0票数 0

我正试图在android模拟器上自动执行一些任务,但遇到了一个非常奇怪的问题:我的Appium + Python脚本甚至无法启动应用程序,而Appium Desktop则一切正常。

以下是详细信息:

首先,我启动我的avd (使用第一个脚本):

代码语言:javascript
复制
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,并具有所需的功能:

代码语言:javascript
复制
{
  "platformName": "Android",
  "platformVersion": "10",
  "deviceName": "Android Emulator",
  "appPackage": "com.google.android.calculator",
  "appActivity": "com.android.calculator2.Calculator"
}

google计算器启动。

但是,如果我启动以下脚本,该脚本就会卡在webdriver.remote行中:

代码语言:javascript
复制
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

你能帮我让这个脚本运行吗?我已经尝试了很多东西,在一周左右的时间里,我不知道哪里出了问题。

谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2020-07-15 07:06:59

好了,我有答案了。我似乎是一个bug,在这里引用:https://github.com/appium/python-client/issues/534

解决方法是编写

代码语言:javascript
复制
appium_service.start(args=..., stdout=sp.DEVNULL)

而不是:

代码语言:javascript
复制
appium_service.start(args=...)

希望其他人会像我一样高兴地找到这个答案:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61870221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档