用命令方式启动、停止appium服务和app
启动appium服务并监听一个端口命令:
命令command==> appium -a {ip} -p {port} -U {deviceName} -g {log}
以shell命令方式执行命令,并输入日志到log文件:用subprocess需导入
subprocess.Popen(command, stdout=open(LOG_PATH, 'a+'), stderr=subprocess.PIPE, shell=True) #相当于再cmd窗口输入上面的命令command
根据端口号查询是否已经启动服务:
subprocess.getoutput('netstat -ano | findstr %s'%self.port) #如果找到以启动端口包含port,则会返回对应信息,
netstat -ano | findstr 1111 查询端口号1111的进程信息,从中可以获得pid
启动模拟器或手机,访问服务监听的那个端口:
webdriver.Remote('http://127.0.0.1:4723/wd/hub',dic) #dic是模拟器或手机的设备信息和app信息
根据pid查询进程信息,第一列就是进程名称
tasklist | findstr 2472
根据进程名称杀死改名成对应的所有进程:
taskkill /F /IM node.exe /t #node.exe是进程名
根据pid杀死进程
taskkill /pid 2472 -t -f #2472是pid
例子:
yaml文件格式如下:内容为手机信息和app信息
device_type: android
tester:
resetKeyboard: true
appActivity: com.tencent.mobileqq.activity.SplashActivity
appPackage: com.tencent.mobileqq
# appPackage: com.android.browser
# appActivity: .BrowserActivity
noReset: False
unicodeKeyboard: true
devices:
android:
- port: 9009
platformName: Android
udid: emulator-5554
platformVersion: 5.1.1
name: 雷电a
ip: 127.0.0.2
deviceName: emulator-5554
启动服务、测试服务是否启动、启动app
from lib.tool import Tool
from conf.setting import LOG_PATH
from lib.log import logger
from appium import webdriver
import subprocess
class Controller(object):
def __init__(self):#初始化函数主要是对设备和app信息的获取
self.tool=Tool()#tool类中写的有获取设备文件yaml数据的方法
self.yml=self.tool.app_data#获取到yaml文件中的设备信息
self.device_type=self.yml.get('device_type')
self.device_name=self.yml.get('devices').get(self.device_type)[0].get('deviceName')
self.devices=self.yml.get('devices')
self.port=self.devices.get(self.device_type)[0].get('port')
self.tester=self.yml.get('tester')
# print(self.device_name) #taskkill -PID 4152 -F
# 每次启动前都要kill掉所有的进程taskkill /F /IM node.exe /t def kill_server(self): #taskkill /F /IM node.exe /t 我们开启的appium进程名是node.exe
logger.debug('执行[KILL SERVER]操作:%s' % subprocess.getoutput("taskkill /F /IM node.exe /t"))
logger.debug('重启ADB服务!%s' % subprocess.getoutput("adb kill-server")) def start_server(self):#启动server
device=self.devices.get(self.device_type)[0] #命令字符串
command="appium -a {ip} -p {port} -U {deviceName} -g {log}".format(
ip=device.get('ip'),
port=device.get('port'),
deviceName=device.get('deviceName'),
log=LOG_PATH.replace('app_log.log',device.get('name')+'.log') )
print(command)
logger.debug('服务启动命令:%s'%command) #执行命令
subprocess.Popen(command, stdout=open(LOG_PATH, 'a+'), stderr=subprocess.PIPE, shell=True) def test_server(self):
while True:
#查询是否端口已启动,即服务启动
c=subprocess.getoutput('netstat -ano | findstr %s'%self.port)
if c: logger.debug('启动成功。。。。')
break
else:
logger.debug('启动失败,5s后重试')
import time
time.sleep(5)
return True def start_driver(self):
device=self.devices.get(self.device_type)[0]
self.tester.update(device)
# print(self.tester)
driver=webdriver.Remote('http://{ip}:{port}/wd/hub'.format(
ip=device.get('ip'),
port=device.get('port') ),self.tester) if __name__=='__main__':
controller=Controller()
print(controller.device_name)
controller.kill_server()
controller.start_server()
if controller.test_server():
controller.start_driver()
用命令方式启动、停止appium服务和app的更多相关文章
- Appium+Python app自动化测试之脚本启动和停止Appium服务
研究了一段时间的Appium android app的自动化测试,工作中需要连接多台手机终端同时执行测试用例,我实现的方式是获取用例中需要执行用例的设备id个数以及实际连接到的设备数(通过adb de ...
- delphi 启动停止windows服务 转
http://blog.csdn.net/haiou327/article/details/6106233 不用cmd用delphi如何实现启动停止windows服务建议参考一下Delphi的Sckt ...
- Linux Systemd——在RHEL/CentOS 7中启动/停止/重启服务
RHEL/CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服务进行管理.systemd兼容SysV和Li ...
- bat启动/停止oracle服务
原文:bat启动/停止oracle服务 自己的电脑比较慢,尤其装了oracle10g后,服务开启和关闭用bat文件操作省事点 开启服务 @echo offnet start OracleService ...
- 在CentOS 7中启动/停止/重启服务
RHEL/CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服务进行管理.systemd兼容SysV和Li ...
- Delphi启动/停止Windows服务,启动类型修改为"自动"
unit U_StartServices; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contr ...
- Windows下使用service.bat安装tomcat服务, 启动停止tomcat服务
在项目开发过程中,以前只是在Eclipse中配置.启动.停止tomcat服务器 如果只想在机器中使用tomcat服务器,而不想安装MyEclipse,可以使用service.bat 将tomcat安装 ...
- 【OF框架】使用OF.WinService项目,添加定时服务,进行创建启动停止删除服务操作
准备 使用框架搭建完成项目,包含OF.WinService项目. 了解Window Service 和定时服务相关知识. 一.添加一个定时服务 第一步:了解项目结构 第二步:创建一个新的Job 第三步 ...
- Windows下启动停止Oracle11g服务-为解决系统变慢而生
我们拿Oracle 11g作为例子. 首先在“开始=〉运行”中输入“services.msc”,按回车,进入“服务”控制台, 将 Oracle ORCL VSS Writer Service.Orac ...
随机推荐
- 关于setTimeout的用法注意事项
setTimeout setTimeout的定义:setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式. setTimeout的用法:setTimeout(代码片段,执行代码等待的毫 ...
- C#LeetCode刷题之#39-组合总和(Combination Sum)
目录 问题 示例 分析 问题 该文章已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3663 访问. 给定一个无重复元素的数组 candi ...
- JS的赋值与深浅拷贝实例
赋值 基本类型: 传值,在栈内存中的数据发生数据变化的时候,系统会自动为新的变量分配一个新的之值在栈内存中,两个变量相互独立,互不影响的 引用类型: 传址,只改变指针的指向,指向同一个对象,两个变量相 ...
- 12 种使用 Vue 的最佳做法
随着 VueJS 的使用越来越广泛,出现了几种最佳实践并逐渐成为标准. 1.始终在 v-for 中使用 :key 在需要操纵数据时,将key属性与v-for指令一起使用可以让程序保持恒定且可预测. 这 ...
- Maven项目在进行单元测试报错:ClassNoFoundExceptipon
解决方法: 只要把Java--------compiler-------building-------Buil path problems ------- incomplete build path ...
- 阿里天池 NLP 入门赛 TextCNN 方案代码详细注释和流程讲解
thumbnail: https://image.zhangxiann.com/jung-ho-park-HbnqEhMBpPM-unsplash.jpg toc: true date: 2020/8 ...
- Magento 2 instantiate object by Factory Objects
magento2的Factory Objects是用来实例化non-injectable classes,目前还不知道什么叫non-injectable classes. 可以用它来实例化Helper ...
- unsigned char printf 如何输出
参考链接:https://blog.csdn.net/m0_37362454/article/details/88639668 #include <stdio.h> int main() ...
- Tmux安装和使用
1.What's tmux tmux 是一个终端复用器: 可以激活多个终端或窗口, 在每个终端都可以单独访问,每一个终端都可以访问,运行和控制各自的程序.tmux类似于screen,可以关闭窗口将程序 ...
- ARM开发板挂载Ubuntu18.04主机的NFS共享文件夹
环境 ubuntu主机环境:Window10 下装VMWare下装的 ubuntu18.04LTS x64 IP 192.168.10.119 Window10下配置192.168.10该网段 开发板 ...