Пример #1
0
    def select(self, driver, para_list):
        """
        Select a option for sepecified select type web element.

        :param driver:
        :param para_list: [method, value, option_method, option_value] eg : ['id','country_list','text','China']
                        index: select the option by it's index.
                        value: select the option by it's value.
                        text: select the option by it's text(full text).
                        text_part: select the option by it's text(part of the option).  e.g:  option text is 'autotest15865524', you can found the option by 'autotest'
        :return:
        """
        method, value, option_method, option_value = para_list[0], para_list[
            1], para_list[2], para_list[3]
        from selenium.webdriver.support.select import Select
        if option_method == 'index':
            comd = 'Select(driver.find_element_by_%s("%s")).select_by_%s(%s)' % (
                method, value, option_method, option_value)
        else:
            if option_method == 'text_part':
                self.select_by_visible_text(
                    driver.find_element(by=method, value=value), option_value)
            else:
                if option_method == 'text':
                    option_method = 'visible_text'
                comd = 'Select(driver.find_element_by_%s("%s")).select_by_%s("%s")' % (
                    method, value, option_method, option_value)
                log.log().logger.debug(comd)
                exec(comd)
        time.sleep(2)
Пример #2
0
 def run(self):
     list0 = util.util().getTeseCasesATX(self.j, isRunning=True)
     if len(list0):
         log.log().logger.info('case still running !')
     else:
         list = util.util().getTeseCasesATX(self.j)
         if len(list):
             log.log().logger.info('start test by single devices :%s ' %
                                   list[0][0])
             self.q.put(u"打点我是第%d个线程,ip: %s, 测试用例:%s" %
                        (self.t, self.j, list[0][0]))
             log.log().logger.info(u"打点我是第%d个线程,ip: %s, 测试用例:%s" %
                                   (self.t, self.j, list[0][0]))
             process().main(list[0])
             time.sleep(2)
         else:
             list2 = util.util().getTeseCasesATX(all=True)
             log.log().logger.info('current list lenth is: %s' % len(list2))
             if len(list2):
                 try:
                     case = list2[self.t]
                 except:
                     case = list2[0]
                     log.log().logger.info('current ip is : %s' %
                                           str(self.j))
Пример #3
0
 def readPublic(self, caseList0):
     # print(caseList0)
     resultList = []
     isRead = True
     while (isRead):
         case2 = caseList0[0].split('|')
         if case2[0] == "公共方法":
             caseList0.remove(caseList0[0])
             # log.log().logger.info(case2)
             case0 = self.read_public_case(case2[1])
             if len(case0):
                 resultList0 = []
                 case0 = case0[0]
                 for casei in caseList0:
                     case0.append(casei)
                 try:
                     case0.remove('')
                 except ValueError as e:
                     # log.log().logger.info('error: %s' %e)
                     pass
                 caseList0 = case0
             else:
                 log.log().logger.error('public function is not found!')
                 resultList = []
                 isRead = False
         else:
             resultList = caseList0
             isRead = False
     # print(resultList)
     return resultList
Пример #4
0
    def screenshot(self, screenShotType, caseNo):

        nowTime = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        if platform.system() == 'Windows':
            screen_shot_path = config.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'
            errorfilename1 = '\\' + screen_shot_path1 + '\\' + 'errorScreenShot' + '\\' + str(
                caseNo) + '_error' + nowTime + '.jpg'
        else:
            screen_shot_path = config.screen_shot_path
            screen_shot_path1 = 'static/screenshot'
            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'
            errorfilename1 = '/' + screen_shot_path1 + '/' + 'errorScreenShot' + '/' + str(
                caseNo) + '_error' + nowTime + '.jpg'
        if screenShotType == 'error':
            return errorfilename, errorfilename1
        else:
            return normalfilename, normalfilename1
Пример #5
0
    def assert_element_text(self,
                            driver,
                            para_list,
                            isNot=False,
                            isUpper=False):
        """
        Assert whether the specified web element contains the given text.

        :param driver:
        :param para_list:   [method, value] eg : ['id','add_btn']
        :param isNot:  If you want to assert that target element doesn't contain the given text, isNot should be set to True.
        :param isUpper: if isUpper is false, will convert the target text to upper mode.
        :return:
        """
        text0 = ''
        if len(para_list) == 3:
            method, value, text = para_list[0], para_list[1], para_list[2]
            element = self.find_element(driver, [method, value])
            text0 = element.text
            if isUpper:
                text = text.upper()
                text0 = text0.upper()
            if not len(text0):
                text0 = element.get_attribute('value')
        if isNot:
            log.log().logger.info('目标文本:%s, 期待不包含文本:%s' % (text0, text))
            assert (text in str(text0)) == False
        else:
            log.log().logger.info('目标文本:%s, 期待包含文本:%s' % (text0, text))
            assert (text in str(text0))
Пример #6
0
 def run_step(self, u, step_name, detail, caseNo, screenFileList):
     # print(u, step_name, detail,caseNo,screenFileList)
     result = '1'
     if step_name == 'Android':
         time.sleep(1)
     elif step_name == '点击':
         u, result = self.click(u, detail[0], detail[1])
     elif step_name == '尝试点击':
         self.click(u, detail[0], detail[1])
     elif step_name == '等待':
         time.sleep(int(detail[0]))
     elif step_name == '发送':
         u, result = self.sendData(u, detail[0])
     elif step_name == '填写':
         u, result = self.type_text(u, detail[0], detail[1], detail[2])
     elif step_name == '返回':
         u.adb_shell('input', 'keyevent', 'BACK')
         time.sleep(1)
     elif step_name == '截图':
         screenFileList = self.take_screenshot(u, 'normal', caseNo,
                                               screenFileList)
     else:
         result = '2'
         log.log().logger.error('method is not defined : %s' % step_name)
     if result == '0':
         log.log().logger.error('package is not fould!')
     elif result == '2':
         screenFileList = self.take_screenshot(u, 'fail', caseNo,
                                               screenFileList)
     return u, result, screenFileList
Пример #7
0
 def assert_title(self, driver, text):
     if text in driver.title:
         result = '1'
     else:
         result = '2'
     log.log().logger.info('verify result is : %s' % result)
     return result
Пример #8
0
class MyThread(threading.Thread):
    def __init__(self, q, t, j):
        super(MyThread, self).__init__()
        self.q = q
        self.t = t
        self.j = j

    def run(self):
        list0 = util.util().getTeseCasesATX(self.j,isRunning=True)
        if len(list0):
            log.log().logger.info('case still running !')
        else:
            list = util.util().getTeseCasesATX(self.j)
            if len(list):
                log.log().logger.info('start test by single devices :%s ' %list[0][0] )
                self.q.put(u"打点我是第%d个线程,ip: %s, 测试用例:%s" % (self.t, self.j,list[0][0]))
                log.log().logger.info(u"打点我是第%d个线程,ip: %s, 测试用例:%s" % (self.t, self.j,list[0][0]))
                process().main(list[0])
                time.sleep(2)
            else:
                list2 = util.util().getTeseCasesATX(all=True)
                log.log().logger.info('current list lenth is: %s'%len(list2))
                if len(list2):
                    try:
                        case = list2[self.t]
                    except:
                        case=list2[0]
                        log.log().logger.info('current ip is : %s'%str(self.j))
                    log.log().logger.info('start test by multiple devices :%s ' % case[0])
                    self.q.put(u"我是第%d个线程,ip: %s, 测试用例:%s" % (self.t, self.j, case[0]))
                    log.log().logger.info(u"打点我是第%d个线程,ip: %s, 测试用例:%s" % (self.t, self.j, case[0]))
                    process().main(case,deviceList=[str(self.j)])
                    time.sleep(3)
Пример #9
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()
Пример #10
0
 def serverUrl(self,servers):
     server_url = {}
     import random
     i = random.randint(0,100)%len(servers)
     log.log().logger.info('%s, %s' %(i,len(servers)))
     server_url['hostname']=servers[i][0]
     server_url['port'] = servers[i][1]
     return "http://%s:%s/wd/hub" %(server_url['hostname'],server_url['port'])
Пример #11
0
 def click_description(self, u, id):
     if u(description=id).exists:
         u(description=id).click()
         time.sleep(1)
         result = 1
     else:
         log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % ('description', id))
         result = 2
     return u, result
Пример #12
0
 def click_id(self, u, id):
     if u(resourceId=id).exists:
         u(resourceId=id).click()
         time.sleep(1)
         result = 1
     else:
         log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % ('id', id))
         result = 2
     return u, result
Пример #13
0
 def click_text(self, u, text):
     if u(text=text).exists:
         u(text=text).click()
         time.sleep(1)
         result = 1
     else:
         log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % ('text', text))
         result = 2
     return u, result
Пример #14
0
 def click_class(self, u, id):
     if u(className=id).exists:
         u(className=id).click()
         time.sleep(1)
         result = 1
     else:
         log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % ('className', id))
         result = 2
     return u, result
Пример #15
0
 def click_text(self, driver, text):
     elements = driver.find_elements(by='xpath',
                                     value="//*[contains(.,'" + text +
                                     "')]")
     for element in elements:
         try:
             element.click()
         except NoSuchElementException as e:
             log.log().logger.info(e)
     time.sleep(2)
Пример #16
0
 def click_id(self, u, id):
     if u(resourceId=id).exists:
         u(resourceId=id).click()
         time.sleep(1)
         result = '1'
     else:
         log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % ('id', id))
         u.swipe_points([(0.509, 0.601), (0.503, 0.149)], 0.2)
         result = '2'
     return u, result
Пример #17
0
    def assert_title(self, driver, text):
        """
        Assert whether current web page's title contains the given text.

        :param driver:
        :param text:
        :return:
        """
        log.log().logger.info('目标文本:%s, 期待包含文本:%s' % (driver.title, text))
        assert text in driver.title
Пример #18
0
 def init(self, device=''):
     log.log().logger.info('trying to connect device : %s' % device)
     try:
         u = ut2.connect(device)
         log.log().logger.info(u.device_info)
         isConnected = 1
     except:
         isConnected = 0
         u = ''
     return isConnected, u
Пример #19
0
 def click_text(self, u, text):
     if u(text=text).exists:
         u(text=text).click()
         time.sleep(1)
         result = '1'
     else:
         log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % ('text', text))
         u.swipe_points([(0.509, 0.601), (0.503, 0.149)], 0.2)
         result = '2'
     return u, result
Пример #20
0
    def is_app_exist0(self, package):
        import subprocess
        cmd = 'dumpsys package %s | grep version' % package
        cmds = [cmd, "exit", ]

        pipe = subprocess.Popen("adb shell", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        code = pipe.communicate(("\n".join(cmds) + "\n").encode())

        log.log().logger.info(code)
        return 'versionCode' in str(code)
Пример #21
0
 def click_index(self, driver, para_list):
     method, value, index = para_list[0], para_list[1], para_list[2]
     elements = self.find_elements(driver, [method, value])
     if len(elements):
         for i in range(3):
             try:
                 elements[int(index)].click()
             except NoSuchElementException as e:
                 log.log().logger.info(e)
     time.sleep(2)
Пример #22
0
 def getDevices(self):
     url = config.ATXHost + '/list'
     response, content = util.util().send(url)
     content = json.loads(content)
     deviceList = []
     for device in content:
         if device['present']:
             deviceList.append(device['ip'] + ':7912')
         else:
             log.log().logger.debug(device['ip'] + ' is not ready!')
     return deviceList
Пример #23
0
 def screenshot(self, driver, id, screenFileList, isError=False):
     result = '2'
     if isError:
         fileName, fileName1 = util.util().screenshot('error', id)
     else:
         fileName, fileName1 = util.util().screenshot('normal', id)
     log.log().logger.debug(fileName)
     driver.save_screenshot(fileName)
     screenFileList.append(fileName1)
     result = '1'
     return result, screenFileList
Пример #24
0
 def getPara(self, keyword):
     result = 0
     log.log().logger.info(keyword)
     sql = string.Template(
         "select paraCount, template, elementTemplate from `test_keyword` where `keyword`= '$index' limit 1;"
     )
     sql = sql.substitute(index=keyword)
     result = useDB.useDB().search(sql)
     if len(result):
         return result[0][0], result[0][1], result[0][2]
     else:
         return '', '', ''
Пример #25
0
 def getPara1(self, keyword):
     # print(self.keywords)
     keywords = self.keywords
     result = 0
     log.log().logger.info(keyword)
     for list in keywords:
         if list['index'] == keyword:
             result = 1
             return list['paraCount'], list['template']
             break
     if result == 0:
         return '', ''
Пример #26
0
 def IsOpen(self, ip, port):
     import socket
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     try:
         s.connect((ip, int(port)))
         s.shutdown(2)
         # 利用shutdown()函数使socket双向数据传输变为单向数据传输。shutdown()需要一个单独的参数,
         # 该参数表示了如何关闭socket。具体为:0表示禁止将来读;1表示禁止将来写;2表示禁止将来读和写。
         # log.log().logger.info('%s is open' % port)
         return True
     except:
         log.log().logger.info('%s is down' % port)
         return False
Пример #27
0
 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()
Пример #28
0
 def try_click(self, driver, para_list):
     # para_list=str(para_list).split(',')
     if len(para_list) == 2:
         method, value = para_list[0], para_list[1]
         # print(value)
         element = self.find_element(driver, [method, value])
         if element:
             for i in range(3):
                 try:
                     element.click()
                 except NoSuchElementException as e:
                     log.log().logger.info(e)
     time.sleep(2)
Пример #29
0
 def getDevicesList(self):
     url = config.ATXHost + '/list'
     response, content = util.util().send(url)
     content = json.loads(content)
     deviceLists = []
     for device in content:
         deviceList = {}
         if device['present']:
             deviceList["ip"] = device['ip'] + ':7912'
             deviceList["model"] = device['model']
             deviceLists.append(deviceList)
         else:
             log.log().logger.info(device['ip'] + ' is not ready!')
     return deviceLists
Пример #30
0
 def type_text(self, u, method, resource_id, text):
     if method == 'id':
         if u(resourceId=resource_id).exists:
             u(resourceId=resource_id).send_keys(text)
             time.sleep(1)
             result = 1
             u.adb_shell('input', 'keyevent', 'BACK')
             time.sleep(1)
         else:
             log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % (method, resource_id))
             result = 2
     elif method == 'name':
         if u(text=resource_id).exists:
             u(text=resource_id).send_keys(text)
             time.sleep(1)
             result = 1
             u.adb_shell('input', 'keyevent', 'BACK')
             time.sleep(1)
         else:
             log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % (method, resource_id))
             result = 2
     elif method == 'class':
         if u(className=resource_id).exists:
             u(className=resource_id).send_keys(text)
             time.sleep(1)
             result = 1
             u.adb_shell('input', 'keyevent', 'BACK')
             time.sleep(1)
         else:
             log.log().logger.error(u"出错了,没有找到元素! by %s , %s" % (method, resource_id))
             result = 2
     else:
         log.log().logger.error(u"元素方法未定义! %s" % method)
         result = 2
     return u, result