from appium import webdriver
import unittest
def script(deviceName,udid,platformVersion,bp,port):
import os,time
app_path = '/Users/liming06/Desktop/APK/test.apk'
desired_caps = {}
desired_caps['deviceName'] = deviceName #测试设备类型(测试Android时被忽略)
desired_caps['platformName'] = 'Android' #被测设备的系统平台
desired_caps['platformVersion'] = platformVersion#'8.1.0'
desired_caps['udid'] = udid #仅真机使用)测试设备的ID
desired_caps['app'] = os.path.abspath(app_path)
desired_caps['fullReset']="False" #完全重置(Android通过卸载程序的方式),Session完成后会卸载程序
desired_caps['appPackage'] = 'com.cookie.testapp' #被测APP的包名
desired_caps['appActivity'] = ".MainActivity" #被测APP启动的Activity名称
desired_caps["clearSystemFiles"]='True'
desired_caps['newCommandTimeout']='10000s'#Appium服务器等待Appium客户端发送新消息的时间,单位为s 60s(默认)
desired_caps['noSign'] = "False"
# desired_caps["noReset"]="false" #在一个Session开始前不重置被测程序的状态
print("http://127.0.0.1:"+port+"/wd/hub", desired_caps)
driver=webdriver.Remote('http://127.0.0.1:'+port+"/wd/hub", desired_caps)
driver.implicitly_wait(5)
driver.find_element_by_android_uiautomator('text(\"进入来电秀\")').click()
driver.find_element_by_android_uiautomator('text(\"始终允许\")').click()
driver.find_element_by_android_uiautomator('text(\"始终允许\")').click()
driver.find_element_by_android_uiautomator('text(\"始终允许\")').click()
def appium_script_start():
import multiprocessing
r1=multiprocessing.Process(target=script,args=("OPPO Find X","210c80c2",'8.1.0','4724','4723',))
r2=multiprocessing.Process(target=script,args=('Honor 9i','b99ede26','8.1.0','4726','4725',))
r2.start()
r1.start()
def appium_server_cmd(port,bp_port):
import subprocess
cmd="appium -a 127.0.0.1 -p %s -bp %s >>/Users/liming/Desktop/python学习/数据分析/%slog.log"%(port,bp_port,port)
print(cmd)
subprocess.getoutput(cmd)
def appium_server_start():
import multiprocessing
appium_script_start_01=multiprocessing.Process(target=appium_server_cmd,args=(4723,4724))
appium_script_start_02 = multiprocessing.Process(target=appium_server_cmd, args=(4726, 4725))
appium_script_start_02.start()
appium_script_start_01.start()
if __name__ == '__main__':
import multiprocessing,time
appium_script_start_01 = multiprocessing.Process(target=appium_server_cmd, args=(4723, 4724))
appium_script_start_02 = multiprocessing.Process(target=appium_server_cmd, args=(4725, 4726))
appium_script_start_02.start()
appium_script_start_01.start()
time.sleep(3)
appium_script_start()