# -*- coding: utf-8 -*-
import os
import socket
import urllib.request
from urllib.error import URLError
from multiprocessing import Process
import time
import platform
import subprocess
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
import threading
class AppiumServer:
def __init__(self, kwargs=None):
self.kwargs = kwargs
def start_server(self):
"""start the appium server
"""
for i in range(0, len(self.kwargs)):
cmd = "appium --session-override -p %s -bp %s -U %s" % (
self.kwargs[i]["port"], self.kwargs[i]["bport"], self.kwargs[i]["devices"])
print(cmd)
if platform.system() == "Windows": # windows下启动server
t1 = RunServer(cmd)
p = Process(target=t1.start())
p.start()
while True:
print("--------start_win_server-------------")
if self.win_is_runnnig("http://127.0.0.1:" + self.kwargs[i]["port"] + "/wd/hub" + "/status"):
print("-------win_server_ 成功--------------")
break
else:
appium = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1,
close_fds=True)
while True:
appium_line = appium.stdout.readline().strip().decode()
time.sleep(1)
print("---------start_server----------")
if 'listener started' in appium_line or 'Error: listen' in appium_line:
print("----server_ 成功---")
break
def win_is_runnnig(self, url):
"""Determine whether server is running
:return:True or False
"""
response = None
time.sleep(1)
try:
response = urllib.request.urlopen(url, timeout=5)
if str(response.getcode()).startswith("2"):
return True
else:
return False
except URLError:
return False
except socket.timeout:
return False
finally:
if response:
response.close()
def stop_server(self, devices):
sysstr = platform.system()
if sysstr == 'Windows':
os.popen("taskkill /f /im node.exe")
else:
for device in devices:
# mac
cmd = "lsof -i :{0}".format(device["port"])
plist = os.popen(cmd).readlines()
plisttmp = plist[1].split(" ")
plists = plisttmp[1].split(" ")
# print plists[0]
os.popen("kill -9 {0}".format(plists[0]))
def re_start_server(self):
"""reStart the appium server
"""
# self.stop_server()
# self.start_server()
pass
【笔记】appium启动多个服务
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 首先可以看看上篇帖子基于 selenium grid 连接多个 appium 介绍 python 基于unitte...
- 现开发的项目每次都需要启动三个服务才能进行开发测试,每天手动操作一遍超级无敌繁琐…… 果断写个批处理文件一键启动,...