简体   繁体   English

如何使用 AppiumService() 从我的 python 代码启动 appium 服务器?

[英]How to start appium server from my python code with AppiumService()?

I am running some test on real Android device.我正在真正的 Android 设备上运行一些测试。 I installed APpium server via pm.我通过 pm 安装了 APPium 服务器。 I can run Appium server with Windows command line 'appium'.我可以使用 Windows 命令行“appium”运行 Appium 服务器。

I try to start the appium server from my python code with these lines of code:我尝试使用以下代码行从我的 python 代码启动 appium 服务器:

appium_service = AppiumService()
appium_service.start()

but nothing happened, I don't get any output, no error message, no exception.但什么也没发生,我没有收到任何 output,没有错误消息,也没有异常。 nothing.没有什么。

So I tried again by passing some parameters:所以我通过传递一些参数再次尝试:

appium_service = AppiumService()
appium_service.start(address='0.0.0.0', p='4723')

Again nothing happened!又什么都没发生!

It seems the code is waiting... or sleeping.... these lines of code are at the beginning of the script... I can see some logger messages for the initialization of my webdriver... but then nothing.似乎代码正在等待......或睡眠......这些代码行在脚本的开头......我可以看到一些用于初始化我的 webdriver 的记录器消息......但什么也没有。

Is there anyone please who can help me to debug and to make run APpium server from my code without the command line os option.有没有人可以帮助我在没有命令行 os 选项的情况下从我的代码中调试和运行 APPium 服务器。

First of all its good to check manually if "appium" command on shell launches the appium server or not(Seems in your case its working fine).首先,手动检查 shell 上的“appium”命令是否启动了 appium 服务器(在您的情况下似乎工作正常)。 In my case it was not with the installation of Appium desktop version.就我而言,它不是安装 Appium 桌面版。 Posting the details of what i did to resolve this in case it helps someone:发布我为解决此问题所做的详细信息,以防它帮助某人:

Installed npm (as part of node installation, MSI available at nodejs.org) npm install -g appium Now to answer your main question, below is what i used in my Python script to start the appium server on a new window so that it runs separately from the rest of the script execution: Installed npm (as part of node installation, MSI available at nodejs.org) npm install -g appium Now to answer your main question, below is what i used in my Python script to start the appium server on a new window so that it runs与脚本执行的rest分开:

import os
os.system("start /B start cmd.exe @cmd /k appium")

In case you want to change the port(eg to 4728) of the appium server (may be when you have multiple servers for multiple devices) you can use following:如果您想更改 appium 服务器的端口(例如更改为 4728)(可能是当您有多个服务器用于多个设备时),您可以使用以下内容:

os.system("start /B start cmd.exe @cmd /k appium -a 127.0.0.1 -p 4728")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM