def showHubs(self,runType): if runType == 'Android' or runType == 'iOS': sql = "select ip, port from test_hubs where status = '1' and androidConnect = '1';" else: sql = "select ip, port from test_hubs where status = '1';" result = useDB.useDB().search(sql) hubs = [] if len(result): for hub in result: if self.IsOpen(hub[0],hub[1]): hubs.append(hub) else: self.updateHub(hub[0],hub[1],'0','0') if len(hubs) == 0: log.log().logger.debug('no hubs is availabe!') return hubs
def search_test_batch_detail1(self,id,fieldlist): search_value = fieldlist[0] for i in range(1,len(fieldlist)): search_value = search_value + ','+fieldlist[i] sql = 'select ' + search_value + ' from test_batch where id = "' + str(id) + '";' result = useDB.useDB().search(sql) log.log().logger.info(result) if len(result): result = result[0] results = {} results['id'] = id for i in range(len(fieldlist)): results[fieldlist[i]] = result[i] else: results = [] return results
def show_test_cases(self,conditionList, valueList, fieldlist,rows): if len(fieldlist)==0: fieldlist = ['id', 'module', 'name', 'steps', 'description','isPublicFunction'] search_value = fieldlist[0] for i in range(1,len(fieldlist)): search_value = search_value + ','+fieldlist[i] condition = '' for i in range(len(conditionList)): if i == 0: if conditionList[i] == 'module': log.log().logger.info(valueList[i]) moduleList = '' for j in range(len(valueList[i])): if j: moduleList += ',' moduleList += '"' + valueList[i][j] + '"' condition += str(conditionList[i]) + ' in (' + str(moduleList) + ')' else: condition += str(conditionList[i]) + ' like "%' + str(valueList[i]) + '%"' else: if conditionList[i] == 'module': log.log().logger.info(valueList[i]) moduleList = '' for j in range(len(valueList[i])): if j: moduleList += ',' moduleList += '"' + valueList[i][j] + '"' condition += ' and ' + str(conditionList[i]) + ' in (' + str(moduleList) + ')' else: condition += ' and ' + str(conditionList[i]) + ' like "%' + str(valueList[i]) + '%"' # if condition != '': # condition += ' and ' results = [] sql = 'select ' + search_value + ' from test_case where ' + str(condition) + ' and status = 1 order by id desc limit '+ str(rows)+';' cases = useDB.useDB().search(sql) log.log().logger.info('cases : %s'%cases) for i in range(len(cases)): result = {} result['id'] = cases[i][0] result['module'] = cases[i][1] result['name'] = cases[i][2] result['steps'] = cases[i][3] result['description'] = cases[i][4] result['isPublic'] = cases[i][5] results.append(result) return results
def show_test_cases_unattach(self,test_suite_id,conditionList, valueList, fieldlist,rows): fieldlist = ['id', 'module', 'name', 'steps', 'description','isPublicFunction'] search_value = fieldlist[0] for i in range(1,len(fieldlist)): search_value = search_value + ','+fieldlist[i] results = [] log.log().logger.info('%s, %s, %s, %s, %s' %(test_suite_id,conditionList, valueList, fieldlist,rows)) condition = '' for i in range(len(conditionList)): if i == 0: if conditionList[i]=='module': log.log().logger.info(valueList[i]) moduleList = '' for j in range(len(valueList[i])): if j : moduleList += ',' moduleList += '"'+valueList[i][j]+'"' condition += str(conditionList[i]) + ' in (' + str(moduleList) + ')' else: condition += str(conditionList[i]) +' like "%'+str(valueList[i])+'%"' else: if conditionList[i] == 'module': log.log().logger.info(valueList[i]) moduleList = '' for j in range(len(valueList[i])): if j : moduleList += ',' moduleList += '"'+valueList[i][j]+'"' condition += ' and ' + str(conditionList[i]) + ' in (' + str(moduleList) + ')' else: condition += ' and '+str(conditionList[i]) +' like "%'+str(valueList[i])+'%"' if condition !='': condition += ' and ' sql = 'select ' + search_value + ' from test_case where status = 1 and isPublicFunction=0 and '+ str(condition) +' id not in (select distinct test_case_id from test_batch where test_suite_id = '+test_suite_id+' ) order by module desc;' cases = useDB.useDB().search(sql) log.log().logger.info('cases : %s'%cases) for i in range(len(cases)): result = {} result['id'] = cases[i][0] result['module'] = cases[i][1] result['name'] = cases[i][2] result['steps'] = cases[i][3] result['description'] = cases[i][4] result['isPublic'] = cases[i][5] results.append(result) return results
def searchHubs(self,id=''): if id!='': sql = "select id, ip, port, androidConnect,status from test_hubs where id = %s limit 1;" %str(id) else: sql = "select id, ip, port, androidConnect,status from test_hubs;" list = useDB.useDB().search(sql) log.log().logger.info('cases : %s' %list) results = [] for i in range(len(list)): result = {} result['id'] = list[i][0] result['ip'] = list[i][1] result['port'] = list[i][2] result['androidConnect'] = list[i][3] result['status'] = list[i][4] results.append(result) return results
def search_test_batch_detail(self): sql = 'select * from test_batch limit 10;' results = useDB.useDB().search(sql) users = [] data = {} for r in results: user = {} user['id'] = r[0] user['batch_id'] = r[1] user['case_id'] = r[2] user['status'] = r[3] user['steps'] = r[4] users.append(user) data['code'] = 0 data['cases'] = users log.log().logger.info(users) return users
def search_test_suite(self, id, field): sql = string.Template('select $field from test_suite where id = $id;') sql = sql.substitute(field=field, id=id) result = useDB.useDB().search(sql) log.log().logger.info(result) if len(result): if field == 'run_type': if result[0][0] == '0': result = 'Android' elif result[0][0] == '1': result = 'iOS' elif result[0][0] == '2': result = 'Chrome' else: result = result[0][0] else: result = [] return result
def checkHubs(self): sql = "select ip, port from test_hubs;" result = useDB.useDB().search(sql) hubs = [] if len(result): for hub in result: if self.IsOpen(hub[0], hub[1]): hubs.append(hub) self.updateHub(hub[0], hub[1], '', '1') else: self.updateHub(hub[0], hub[1], '0', '0') if len(hubs) == 0: log.log().logger.error('no hubs is availabe!') else: # log.log().logger.info('availables hubs are :') for i in range(len(hubs)): log.log().logger.info(hubs[i][0] + ':' + hubs[i][1]) return hubs
def show_test_api(self, conditionList, valueList, fieldlist, rows, type='all'): from app.api_new import api_manage import json print(conditionList, valueList, fieldlist, rows) condition = '' if len(conditionList) != 0: for i in range(len(conditionList)): if str(conditionList[i]) == 'id': if str(valueList[i]) != '': condition += ' and ' + str( conditionList[i]) + ' =' + str(valueList[i]) elif str(valueList[i]) != '': condition += ' and ' + str( conditionList[i]) + ' like "%' + str( valueList[i]) + '%"' results = [] sql = 'select id,product,module,name,url,paras,osign_list,description from api_new where 1=1 and status=1' + str( condition) + ' order by id desc limit ' + str(rows) + ';' list = useDB.useDB().search(sql) log.log().logger.info('cases : %s ' % list) for i in range(len(list)): result = {} result['id'] = list[i][0] result['product'] = list[i][1] result['module'] = list[i][2] result['name'] = list[i][3] result['url'] = list[i][4] paras = list[i][5].replace("'", '"') if type == 'default': paras = api_manage.api_manage().get_api_paras( para_info=json.loads(paras), type='default') elif type == 'ramdon': paras = api_manage.api_manage().get_api_paras( para_info=json.loads(paras), type='ramdon') result['paras'] = json.dumps(paras).replace('"', "'") result['osign_list'] = list[i][6] result['description'] = list[i][7] results.append(result) return results
def show_test_keywords(self,conditionList, valueList, fieldlist,rows): results = [] if len(conditionList) and conditionList[0]=='id': sql = 'select id, keyword, paraCount, template, example,description from test_keyword where status = 1 and id =' + str( valueList[0]) + ' order by id desc limit 1;' else: sql = 'select id, keyword, paraCount, template, example,description from test_keyword where status = 1 and keyword like "%' + str(valueList[0]) + '%" order by id desc limit '+ str(rows)+';' print(sql) cases = useDB.useDB().search(sql) print(cases) log.log().logger.info('cases : %s'%cases) for i in range(len(cases)): result = {} result['id'] = cases[i][0] result['keyword'] = cases[i][1] result['paraCount'] = cases[i][2] result['template'] = cases[i][3] result['example'] = cases[i][4] result['description'] = cases[i][5] results.append(result) print(results) return results
def show_test_batch_status(self, test_suite_id): results = [] sql = 'select status, count(*) from test_batch where test_suite_id = ' + str( test_suite_id) + ' group by status;' cases = useDB.useDB().search(sql) log.log().logger.info('cases : %s' % cases) results = {} notrun = 0 pending = 0 success = 0 running = 0 fail = 0 for case in cases: log.log().logger.info(case) if case[0] == 0: pending = case[1] elif case[0] == 1: success = case[1] elif case[0] == 2: fail = case[1] elif case[0] == 3: notrun = case[1] elif case[0] == 4: running = case[1] total = pending + notrun + success + fail + running if total > 0: successRate = (success / total) * 100 log.log().logger.info('%s, %s' % (total, successRate)) else: successRate = 0 results['pending'] = str(pending + notrun) results['success'] = str(success) results['fail'] = str(fail) results['running'] = str(running) results['total'] = str(total) results['successRate'] = str(round(successRate, 2)) + '%' log.log().logger.info(results) return results
def test_case_list(self): sql = 'select id, steps,browser_type from test_batch where status in (0) and test_suite_id = 0;' # sql = sql.substitute(type = type) # log.log().logger.info(sql) idList = useDB.useDB().search(sql) return idList
def updateHub(self, ip, port, androidConnect, status): if port == 'all': useDB.useDB().insert( "update test_hubs set status = 0 where ip = '%s';" % (ip)) log.log().logger.info('update hub to unavailable: %s' % (ip)) elif status == '1': sql = "select status from test_hubs where ip = '%s' and port = '%s' limit 1;" % ( ip, port) result = useDB.useDB().search(sql) if androidConnect == '': if len(result) == 0: useDB.useDB().insert( "insert into test_hubs (ip, port) values ('%s','%s');" % (ip, port)) log.log().logger.info('add new hub to available: %s:%s' % (ip, port)) elif result[0][0] != 1: useDB.useDB().insert( "update test_hubs set status = 1 where ip = '%s' and port = '%s' limit 1;" % (ip, port)) log.log().logger.info('update hub to available: %s:%s' % (ip, port)) else: log.log().logger.info('hub already available: %s:%s' % (ip, port)) else: if len(result) == 0: useDB.useDB().insert( "insert into test_hubs (ip, port,androidConnect) values ('%s','%s',%s);" % (ip, port, androidConnect)) log.log().logger.info( 'add new hub to available: %s:%s, %s' % (ip, port, androidConnect)) elif result[0][0] != 1: useDB.useDB().insert( "update test_hubs set status = 1,androidConnect = %s where ip = '%s' and port = '%s' limit 1;" % (androidConnect, ip, port)) log.log().logger.info('update hub to available: %s:%s,%s' % (ip, port, androidConnect)) else: log.log().logger.info('hub already available: %s:%s,%s' % (ip, port, androidConnect)) elif status == '0': sql = "select status from test_hubs where ip = '%s' and port = '%s' limit 1;" % ( ip, port) result = useDB.useDB().search(sql) if len(result) == 0: log.log().logger.info('hub does not exist: %s:%s, %s' % (ip, port, androidConnect)) else: useDB.useDB().insert( "update test_hubs set status = 0, androidConnect = 0 where ip = '%s' and port = '%s' limit 1;" % (ip, port)) log.log().logger.info('update hub to unavailable: %s:%s' % (ip, port))
def show_test_suites(self, conditionList, valueList, fieldlist, rows): fieldlist = [] if len(fieldlist) == 0: fieldlist = [ 'id', 'name', 'status', 'run_type', 'description', 'batchId' ] search_value = fieldlist[0] log.log().logger.info(fieldlist) for i in range(1, len(fieldlist)): search_value = search_value + ',' + fieldlist[i] condition = 'isDeleted = 0 ' for i in range(len(conditionList)): if len(valueList[i]): if conditionList[i] == 'run_type': if valueList[i] == 'Chrome': valueList[i] = 2 elif valueList[i] == 'Android': valueList[i] = 0 elif valueList[i] == 'iOS': valueList[i] = 1 if conditionList[i] in ('id', 'status', 'run_type'): condition += ' and ' + str( conditionList[i]) + ' = "' + str(valueList[i]) + '"' else: condition += ' and ' + str( conditionList[i]) + ' like "%' + str( valueList[i]) + '%"' results = [] sql = 'select ' + str(search_value) + ' from test_suite where ' + str( condition) + ' order by id desc limit ' + str(rows) + ';' cases = useDB.useDB().search(sql) log.log().logger.info('cases : %s ' % cases) for i in range(len(cases)): result = {} result['id'] = cases[i][0] result['name'] = cases[i][1] if cases[i][2] == 0: status = '0-准备执行' elif cases[i][2] == 1: status = '1-执行完成' elif cases[i][2] == 2: status = '2-执行中' elif cases[i][2] == -1: status = '未执行' else: status = 'unknown' result['status'] = status if cases[i][3] == '0': run_type = 'Android' elif cases[i][3] == '1': run_type = 'iOS' elif cases[i][3] == '2': run_type = 'Chrome' else: run_type = cases[i][3] result['run_type'] = run_type result['description'] = cases[i][4] result['batchId'] = cases[i][5] results.append(result) # log.log().logger.info(results) return results
def search_test_suite_list(self): sql = 'select * from test_suite limit 10;' result = useDB.useDB().search(sql)[0] log.log().logger.info(result) return result
def test_suite_list(self): sql = 'select id,run_type from test_suite where status in (0,2) and isDeleted = 0 and run_type in ("2","Chrome");' idList = useDB.useDB().search(sql) return idList
def test_suite_list(self, type): sql = 'select id from test_suite where status = 0;' idList = useDB.useDB().search(sql) return idList
def test_case_list(self): sql = 'select id, steps,browser_type from test_batch where status in (0) and test_suite_id = 0;' idList = useDB.useDB().search(sql) return idList
def getTeseCasesATX(self,ip='', all=False, isRunning=False): if all: case = useDB.useDB().search('select id, steps,browser_type from test_batch where test_suite_id in (SELECT id FROM test_suite WHERE STATUS in (0,2) AND run_type IN ("0" ,"Android")) and status ="0" limit 1000 ;' )
def getPara(self, para): url = useDB.useDB().search( "SELECT VALUE FROM test_config WHERE NAME = '%s' AND isUseAble = '1';" % para) return url[0][0]
def test_suite_list(self): sql = 'select id,run_type from test_suite where status in (0,2);' idList = useDB.useDB().search(sql) return idList
def new_test_case(self,module,name,steps,description, isPublic): sql = string.Template('insert into test_case (module,name,steps,description,isPublicFunction) values ("$module","$name","$steps","$description",$isPublic);') sql = sql.substitute(name = name, module = module, steps = steps,description=description, isPublic=isPublic) useDB.useDB().insert(sql)
def search_test_batch(self, id): sql = string.Template('select steps from test_batch where id = "$id";') sql = sql.substitute(id=id) return useDB.useDB().search(sql)[0]
def update_test_suite(self, relateId,status): import string sql = string.Template('update test_suite set status = $status, runCount = runCount+1 where id = "$relateId";') sql = sql.substitute(relateId = relateId,status=status) # log.log().logger.info(sql) useDB.useDB().insert(sql)
def test_suite_list(self, runtype='2'): sql = 'select id,run_type from test_suite where status in (0,2) and run_type = "%s";' % runtype idList = useDB.useDB().search(sql) return idList
def update_test_suite_check(self): check_list = test_batch_manage.test_batch_manage().search_done_test_suite() if len(check_list): sql = 'update test_suite set status = 1 where id in (%s);' %check_list # print(sql) useDB.useDB().insert(sql)
from app import useDB,autotestconfig from app.core import log import time,platform,os import httplib2,json class util(): def getTeseCases(self,test_suite_id): case = useDB.useDB().search('select id, steps,browser_type from test_batch where test_suite_id = "%s" and status in ("0") limit 1000 ;' % test_suite_id) #and status = "2" limit 1 # log.log().logger.info(case) return case def getTeseCasesATX(self,ip='', all=False, isRunning=False): if all: case = useDB.useDB().search('select id, steps,browser_type from test_batch where test_suite_id in (SELECT id FROM test_suite WHERE STATUS in (0,2) AND run_type IN ("0" ,"Android")) and status ="0" limit 1000 ;' ) elif isRunning: case = useDB.useDB().search( 'select id, steps,browser_type from test_batch where test_suite_id in (SELECT id FROM test_suite WHERE STATUS in (0,2) AND run_type IN ("0" ,"Android")) and status in ("4") and ip = "%s" limit 1000 ;' % ip) else: case = useDB.useDB().search('select id, steps,browser_type from test_batch where test_suite_id in (SELECT id FROM test_suite WHERE STATUS in (0,2) AND run_type IN ("0" ,"Android")) and status in ("0") and ip = "%s" limit 1000 ;' %ip) #and status = "2" limit 1 log.log().logger.info(case) return case def screenshot(self,screenShotType, caseNo): nowTime = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime()) if platform.system() == 'Windows': screen_shot_path = autotestconfig.screen_shot_path screen_shot_path1 = 'static\\screenshot\\' log.log().logger.info(screen_shot_path) normalfilename = screen_shot_path + 'normalScreenShot\\' + str(caseNo)+'_success' + nowTime + '.jpg' errorfilename = screen_shot_path + 'errorScreenShot\\' + str(caseNo)+'_error' + nowTime + '.jpg' normalfilename1 = '\\' +screen_shot_path1 + '\\' + 'normalScreenShot' + '\\' + str(caseNo)+'_success' + nowTime + '.jpg'
def test_suite_list(self): sql = 'select id,run_type from test_suite where status in (0,2);' # sql = sql.substitute(type = type) # log.log().logger.info(sql) idList = useDB.useDB().search(sql) return idList
class util(): def getTeseCases(self,test_suite_id): case = useDB.useDB().search('select id, steps,browser_type from test_batch where test_suite_id = "%s" and status in ("0") limit 1000 ;' % test_suite_id) #and status = "2" limit 1 # log.log().logger.info(case) return case
def new_test_run_list(self, Id): sql = 'update test_suite set status = 0,runCount=1 where id = %s;' % str( Id) useDB.useDB().insert(sql)