appium+python一个脚本同时运行在多台android设备

# -*- coding:utf-8 -*-
from appium import webdriver;
import subprocess
import time
import os
import login_Activity
import threading;
from selenium.webdriver.support.ui import WebDriverWait;


PATH=lambda p:os.path.abspath(os.path.join(os.path.dirname(__file__),p))


desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = ''
desired_caps['app'] = PATH('C:\\Users\\butel\\Desktop\\hvs_s175_v2.6.68.310-201709111846.apk')


# desired_caps['appPackage'] = 'com.tencent.mm'
# desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'


subprocess.call('start /b taskkill /f /t /im node.exe', shell=True, stdout=open('D:\log\\shasi.log', 'w'), stderr=subprocess.STDOUT)
ip = ['192.168.8.100', '192.168.8.103']
tt = []


def sever(ip):
    for i in range(len(ip)):


        host = '127.0.0.1'
        cmd = 'start /b appium -a ' + host + ' -p ' + str(4723 + 2 * i) + \
              ' --command-timeout 500  --automation-name Appium -U ' + ip[i] + ':' + str(5555 + i)
        print cmd
        time.sleep(2)
        # 注释掉的
        # subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        subprocess.call(cmd, shell=True, stdout=open('D:\log\\log.log', 'w'), stderr=subprocess.STDOUT)
        time.sleep(30)
        driver = webdriver.Remote('http://localhost:' + str(4723 + 2 * i) + '/wd/hub', desired_caps)
        hh = Ni(driver)
        t = threading.Thread(target=hh.login)
        tt.append(t)




class Ni():


    def __init__(self, driver):
        self.driver = driver


    def login(self):
        time.sleep(5)
        print 111111111
        for j in range(3):
            # self.cgw = self.driver.find_element_by_id("cn.redcdn.hvs:id/Login_numdemo_edit");
            # time.sleep(3)
            # self.cgw.click();
            # time.sleep(3)
            login_Activity.login_phone(self)
            # self.bum = self.driver.find_element_by_id("com.tencent.mm:id双击查看原图n")
            # self.bum.send_keys('12345678')
            # time.sleep(2)
            #
            # self.gz = self.driver.find_element_by_id("com.tencent.mm:id双击查看原图");
            # self.gz.send_keys('jho');
            # time.sleep(2)
            print 2222222222
            # self.driver.keyevent(4)


        self.driver.quit()




if __name__ == '__main__':
        sever(ip)
        time.sleep(2)
        for i in tt:
            i.start()

猜你喜欢

转载自blog.csdn.net/qq_36002111/article/details/84875195