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

查看:91
本文介绍了如何在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天全站免登陆