zoukankan      html  css  js  c++  java
  • Appium多线程自动化测试批量关闭cmd窗口(appium)

    1.自动化测时候,连接多台设备,需要单独启动一个appium server,也就意味着要多开cmd窗口;但是测试结束后,cmd窗口不会自动关闭;

    2.当然可以通过“start /b”在后台运行;这种方法一个设备还可以;但是多个设备就会出问题;

    3.清理appium的cmd窗口解决办法:运行前为appium设置title,测试结束后没找到title对应的进程,杀死进程;

    注:由于是用udid创建的窗口,所以 title = udid

    def start_appium(udid,port):
        try:
            bp = int(port) + 1
            cmd = r'start "' + str(udid) + '" /min  appium -p ' + str(port) + ' -bp ' + str(bp) + ' -U ' + str(
                udid) + ' --session-override -a 127.0.0.1 --command-timeout 600'
            log.info(cmd)
            res = os.popen(cmd)
        
        except Exception as err:
            return "fail: %s" % str(err)
    
    
    def close_cmd_window(title):
        try:
       
            cmd = 'tasklist /v |find "' + str(title) + '" '
            res = (os.popen(cmd)).read()
            pid = [(i.split())[1] for i in res.strip().split("
    ") if i != ""]
            if len(pid) > 0:
                for i in pid:
                    cmd = 'taskkill /f /pid ' + str(i)
                    res = (os.popen(cmd)).read()
            print("关闭cmd窗口成功:%s" % str(title))
        except Exception as err:
            raise Exception(str(err))    
    

      

      

  • 相关阅读:
    最后一次不用看脸的日子
    经典算法_指针
    #include <process.h>
    经典算法_文件
    stdin、stdout、stderr
    经典算法_位运算
    经典算法_结构体
    经典算法_字符串
    #include <string.h>
    #include <stdio.h>
  • 原文地址:https://www.cnblogs.com/breakcircle/p/12794900.html
Copyright © 2011-2022 走看看