简体   繁体   English

如何使用Python以编程方式启动和停止Appium Server

[英]How to Start and Stop Appium Server programmatically using Python

I am a newbie to Python and have created simple Appium Automation Test case for Android mobile app. 我是Python的新手,并且为Android移动应用程序创建了简单的Appium Automation测试用例。

I have setup Jenkins server and want to run Appium on it so there are 2 ways: 我已经设置了Jenkins服务器,并希望在其上运行Appium,所以有2种方法:

  1. Run appium server via Jenkins (We can run it using appium command but when I run appium command it just "hangs up" and showing server console continiously) 通过Jenkins运行appium服务器(我们可以使用appium命令运行它,但是当我运行appium命令时,它只是“挂断”并连续显示服务器控制台)
  2. Start Appium Server programmatically using Python 使用Python以编程方式启动Appium Server

I know we can run Appium Server programmatically using Java but don't know about python. 我知道我们可以使用Java以编程方式运行Appium Server,但不了解python。

So, if you have any idea about either of above 2 ways, please post the answer. 因此,如果您对以上两种方式中的任何一种有任何想法,请发布答案。

Thank you 谢谢

I have found the answer for 1: 我找到了答案1:

Use appium & command. 使用appium &命令。

Use & at the end of the command that will run it in background and didn't freeze the terminal. 在命令的末尾使用将在后台运行它并且不会冻结终端。

Please Refer this 请参考这个

Below is what you can do for 2. Start Appium Server programmatically using Python 下面是您可以做的2.使用Python以编程方式启动Appium Server

import os

#starts appium on same terminal window

os.system("appium")

#starts appium on new terminal window 
os.system("start /B start cmd.exe @cmd /k appium")

The way I do it is: 我这样做的方式是:

write appium in terminal 在终端中写appium

or if I want a specific chromedriver version then I do: 或者,如果我想要特定的chromedriver版本,则可以执行以下操作:

appium --chromedriver-executable /path/to/my/chromedriver/chromedriver_2.42

1) Create a shell script called startAppium.sh with this command: appium --debug & 1)使用以下命令创建一个名为startAppium.sh的shell脚本:appium --debug&

2) Create a shell script called killAppium.sh with this command: kill $(ps -e | grep 'appium' | awk '{print $1}') 2)使用以下命令创建一个名为killAppium.sh的shell脚本:kill $(ps -e | grep'appium'| awk'{print $ 1}')

3) Use python to run either process to execute the shell scripts: import killProcess killProcess.call(['./killAppium.sh']) 3)使用python运行任一进程来执行shell脚本:import killProcess killProcess.call(['./ killAppium.sh'])

Note: I use the above for Jenkins CI/CD in the groovy file's setup and post blocks with just the commands, ie: sh "appium --debug &" and sh "kill $(ps -e | grep 'appium' | awk '{print $1}')". 注意:我在groovy文件的设置中将上述内容用于Jenkins CI / CD,并仅使用以下命令发布代码块:sh“ appium --debug&”和sh“ kill $(ps -e | grep'appium'| awk '{print $ 1}')”。

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

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