import socket
import subprocess
class AppiumServer():
# host = "127.0.0.1"
# port = 4723
def checkPort(self,host,port):
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
s.connect((host,int(port)))
s.shutdown(2)
print('port %s is used !'%port)
return False
except:
print('port %s is availabel !' %port)
return True
def startAppium(self,host,port,devicename):
appiumServerUrl = ""
errorMessage=""
bootstrapPort = str(port+1)
try:
if self.checkPort(host,port):
cmd = 'start /b appium -a ' + host + ' -p ' + str(port) + '-U' + devicename + '--bootstrap-port ' + str(bootstrapPort)
print(cmd)
p = subprocess.Popen(cmd,shell=True,stdout=open("D:\project\Test\log\log.log",'w'),stderr=subprocess.STDOUT)
p.wait()
print('P:')
print(p)
appiumServerUrl = 'http://'+host+':'+str(port)+'/wd/hub'
print(appiumServerUrl)
except Exception as msg:
errorMessage = str(msg)
return appiumServerUrl,errorMessage
def endAppium(self):
subprocess.call('start /b taskkill /f /t /im node.exe', shell=True,stdout=open('D:\project\Test\log\log.log', 'w'), stderr=subprocess.STDOUT)
if __name__ == "__main__":
s = AppiumServer()
s.startAppium('127.0.0.1', 4723,"192.168.207.101:5555")
s.endAppium()
appiumServer
最新推荐文章于 2025-10-29 00:07:27 发布
496

被折叠的 条评论
为什么被折叠?



