本帖子基于上篇帖子python+appium 开源框架分享
appium:
- devices: JTJ4C16331013562
port: 4723
config: node D:\app\Appium\node_modules\appium\bin\appium.js -p 4723 -bp 4733
platformName: android
- devices: MSM8926
port: 4724
config: node D:\app\Appium\node_modules\appium\bin\appium.js -p 4724 -bp 4734
platformName: android
class AppiumServer:
def __init__(self, l_devices):
self.l_devices = l_devices
def start_server(self):
"""start the appium server
:return:
"""
for i in range(0, len(self.l_devices["appium"])):
t1 = RunServer(self.l_devices["appium"][i]["config"])
p = Process(target=t1.start())
p.start()
def stop_server(self):
"""stop the appium server
selenium_appium: appium selenium
:return:
"""
os.system('taskkill /f /im node.exe')
def re_start_server(self):
"""reStart the appium server
"""
self.stop_server()
self.start_server()
def is_runnnig(self):
"""Determine whether server is running
:return:True or False
"""
response = None
for i in range(0, len(self.l_devices["appium"])):
url = " http://127.0.0.1:"+str(self.l_devices["appium"][i]["port"])+"/wd/hub"+"/status"
try:
response = urllib.request.urlopen(url, timeout=5)
if str(response.getcode()).startswith("2"):
return True
else:
return False
except URLError:
return False
finally:
if response:
response.close()
class RunServer(threading.Thread):
def __init__(self, cmd):
threading.Thread.__init__(self)
self.cmd = cmd
def run(self):
os.system(self.cmd)
def runnerPool():
devices_Pool = []
for i in range(0, len(ga["appium"])):
l_pool = []
t = {}
t["deviceName"] = ga["appium"][i]["devices"]
t["platformVersion"] = phoneBase.get_phone_info(devices=ga["appium"][i]["devices"])["release"]
t["platformName"] = ga["appium"][i]["platformName"]
t["port"] = ga["appium"][i]["port"]
l_pool.append(t)
devices_Pool.append(l_pool)
pool = Pool(len(devices_Pool)) #根据多个设备名新建多个不同的进程
# for i in range(2):
# pool.apply_async(sample_request, args=(t[i],)) # 异步
pool.map(runnerCaseApp, devices_Pool) # runnerCaseApp是case
pool.close()
pool.join()
<application android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name="com.XX.crashhandler.CrashApplication">