def add_hub(): info = request.values log.log().logger.info('info : %s' % info) host = viewutil.getInfoAttribute(info, 'host') port = viewutil.getInfoAttribute(info, 'port') status = viewutil.getInfoAttribute(info, 'status') hubs.hubs().updateHub(host, port, '0', status) result = jsonify({'code': 200, 'msg': '新增成功'}) return result, {'Content-Type': 'application/json'}
def serveice(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('0.0.0.0', 9998)) s.listen(5) log1.log().logger.info("waiting for connections...") while True: # 接受一个新连接: hubs.hubs().showHubs('') sock, addr = s.accept() # 创建新线程来处理TCP连接: t = threading.Thread(target=tcplink, args=(sock, addr)) t.start()
def runmain(self,test_suite_id,threadNum, runType ): if runType == 'Android' and isUseATX: Hubs = hubs.hubs().getDevices() log.log().logger.debug('Run type is ATX and usable devices are %s' %Hubs) else: Hubs = hubs.hubs().showHubs(runType) if len(Hubs) ==0: log.log().logger.debug('cannot run for no available hubs!') elif runType == 'Android' and isUseATX: self.atxMain() else: self.multipleRun(util.util().getTeseCases(test_suite_id),threadNum) test_task_manage.test_task_manage().update_test_suite_check()
def check_hubs(): log.log().logger.info(request) log.log().logger.info('check_hubs') if request.method == 'POST': log.log().logger.info('post') result = jsonify({'code': 500, 'msg': 'should be get!'}) return result else: log.log().logger.info('start checking hubs') hubs.hubs().checkHubs() result = jsonify({'code': 200, 'msg': 'success!'}) return result
def tcplink(sock, addr): log1.log().logger.info('Accept new connection from %s:%s...' % addr) sock.send(b'Welcome!') while True: try: data = sock.recv(1024) # print(data.decode('utf-8')) except ConnectionResetError: hubs.hubs().updateHub(ip, 'all', '0', '0') break time.sleep(1) ip = addr[0] port = data.decode('utf-8') # print(data.decode('utf-8')) if not data: break elif data.decode('utf-8') == 'exit': hubs.hubs().updateHub(ip, 'all', '0', '0') break sock.send(('Hello, %s!' % data.decode('utf-8')).encode('utf-8')) log1.log().logger.info(data) androidConnect = '0' hubs.hubs().updateHub(ip, port, androidConnect, '1') log1.log().logger.info('Connection from %s:%s closed.' % addr) hubs.hubs().showHubs('')
def getDevicesList(): #获取列表 from app.core import hubs list = hubs.hubs().getDevicesList() log.log().logger.info('list %s' % list) result = jsonify({'msg': list}) return result, {'Content-Type': 'application/json'}
def iniDriver(self, runType,devicename = ''): log.log().logger.info('RUNTYPE is : %s' %runType) servers = hubs.hubs().showHubs(runType) log.log().logger.info(servers) if len(servers): server_url = self.serverUrl(servers) if runType == 'Chrome': desired_caps_web = webdriver.DesiredCapabilities.CHROME deviceList = ['Galaxy S5', 'Nexus 5X', 'Nexus 6P', 'iPhone 6', 'iPhone 6 Plus', 'iPad', 'iPad Pro'] if devicename!='' : if devicename not in deviceList: devicename = deviceList[2] chrome_option = { 'args': ['lang=en_US','start-maximized'], 'extensions': [], 'mobileEmulation': {'deviceName': ''} } chrome_option['mobileEmulation']['deviceName'] = devicename else: chrome_option = { 'args': ['lang=en_US','--start-maximized'], 'extensions': [] } desired_caps_web['goog:chromeOptions']=chrome_option elif runType == 'Firefox': desired_caps_web = webdriver.DesiredCapabilities.FIREFOX else: log.log().logger.info("browser not support! %s " %runType) return 0 log.log().logger.info(desired_caps_web) retry = 2 while retry: try: log.log().logger.info("start session %s time!" %(3-retry)) driver = webdriver.remote.webdriver.WebDriver(command_executor=server_url,desired_capabilities=desired_caps_web) break except WebDriverException as e: log.log().logger.info(e) # retry +=-1 except ConnectionResetError as e: log.log().logger.info(e) except http.client.RemoteDisconnected as e: log.log().logger.info(e) # retry +=-1 finally: retry +=-1 if retry == 0: return 0 else: try: driver.maximize_window() log.log().logger.info(driver.get_window_size()['height']) if driver.get_window_size()['height']<1920: driver.set_window_size(1920, 1080) #最大化失败,则手动 except WebDriverException as e: log.log().logger.info(e) driver.set_window_size(1920, 1080) #最大化失败,则手动 return driver else: return 0
def runmain(self, test_suite_id, threadNum, runType): Hubs = hubs.hubs().showHubs(runType) if len(Hubs) == 0: log.log().logger.error('cannot run for no available hubs!') else: self.multipleRun(util.util().getTeseCases(test_suite_id), threadNum) test_task_manage.test_task_manage().update_test_suite_check()
def edit_hub(): info = request.values id = viewutil.getInfoAttribute(info, 'id') data = hubs.hubs().searchHubs(id) if len(data): host = data[0]['ip'] port = data[0]['port'] else: host = '' port = 4444 return render_template("util/new_hub.html", host=host, port=port)
def connectDevice(self, package, deviceList=[]): if len(deviceList) == 0: deviceList = hubs.hubs().getDevices() isConnected = 0 device0 = '' for device in deviceList: isConnected, u = self.init(device) if isConnected: if self.start_app(u, package) != 0: device0 = device return isConnected, device0, u else: isConnected = 0 device0 = '' log.log().logger.error('package not found!') return 0, '', ''
def search_hubs(): if request.method == 'POST': log.log().logger.info('post') result = jsonify({'code': 500, 'msg': 'should be get!'}) return result else: info = request.values log.log().logger.info('info : %s' %info) # name = viewutil.getInfoAttribute(info, 'name') limit = info.get('limit', 10) # 每页显示的条数 offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点 from app.core import hubs # data= test_unittest_manage.test_unittest_manage().show_unittest_records(['name'], [name],[],100) data = hubs.hubs().searchHubs() data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]}) log.log().logger.info('data1: %s' %data1) return data1, {'Content-Type': 'application/json'}
def atxMain(self): q = queue.Queue() Hubs = hubs.hubs().getDevices() alllist = util.util().getTeseCasesATX(all=True) if len(Hubs) and len(alllist): count = 0 threads = [] for i in range(len(Hubs)): j = Hubs[i] threads.append(MyThread(q, i, j)) for mt in threads: mt.start() log.log().logger.info("start time: %s" %time.ctime()) elif len(alllist): log.log().logger.debug('no device is avaible!') else: log.log().logger.debug('no test case is needed!')
def runmain(self, test_suite_id, threadNum, runType): Hubs = hubs.hubs().showHubs(runType) self.multipleRun(util.util().getTeseCases(test_suite_id), threadNum) test_task_manage.test_task_manage().update_test_suite_check()
def test_show_hubs(self): hubCount = len(hubs.hubs().showHubs('')) self.assertEqual((hubCount > 0), True)