如何在 Python 中以编程方式启动 appium 服务器 [英] How to start appium server programmatically in Python

查看:37
本文介绍了如何在 Python 中以编程方式启动 appium 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Appium 和 python 编写一个 android 测试框架.Appium 链接:http://appium.io/

I want to write a android test framework using Appium and python. Appium link: http://appium.io/

所以在用 npm 安装 appium 之后,要启动它的服务器,我需要在终端中执行命令appium".它会启动服务器.启动后是这样的:

So after installing appium with npm, to start its server I need to execute the command "appium" in terminal.It will start the server. It looks something like this after starting:

    ranits-MacBook-Pro:$ appium
[Appium] Welcome to Appium v1.8.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

但是我需要使用 python 从我的代码中启动 appium 服务器吗?

But I need to start the appium server from my code using python?

有什么帮助吗?

推荐答案

首先,手动检查 shell 上的appium"命令是否启动 appium 服务器很好(在您的情况下它工作正常).就我而言,这与安装 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). In my case it was not with the installation of Appium desktop version. Posting the details of what i did to resolve this in case it helps someone:

  1. 已安装 npm(作为 node 安装的一部分,MSI 在 nodejs.org 上可用)
  2. npm install -g appium
  1. Installed npm (as part of node installation, MSI available at nodejs.org)
  2. npm install -g appium

现在回答您的主要问题,下面是我在 Python 脚本中使用的内容,用于在新窗口上启动 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:

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

如果您想更改 appium 服务器的端口(例如更改为 4728)(可能是当您有多个服务器用于多个设备时),您可以使用以下内容:

In case you want to change the port(e.g. to 4728) of the appium server (may be when you have multiple servers for multiple devices) you can use following:

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

这篇关于如何在 Python 中以编程方式启动 appium 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆