示例#1
0
    def waitForDialog(self,expect_title):
        for i in range(10):
            try:
                title = HtmlModule(selector1=['xpath',"/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[1]/span"]).element.text
                logger.debug('dialog title is %s'%(title))
            except:
                sleep(0.5)
                continue

            if title == expect_title:
                logger.info('open dailog of %s success' % (expect_title))
                return True
            else:
                sleep(0.5)
        logger.error('open dailog of %s fail'%(expect_title))
        return False
示例#2
0
 def setDialog(self,testData):
     name_selector = ['xpath', '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[1]/div/div/input']
     superior_selector = ['xpath', '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[2]/div/span/span']
     number_selector = ['xpath', '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[3]/div/div/input']
     desc_selector = ['xpath', '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[4]/div/div/input']
     telephone_selector = ['xpath', '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[5]/div/div/input']
     address_selector = ['xpath', '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[6]/div/div/input']
     addressCode_selector = ['xpath','/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[7]/div/div/div[1]/input']
     
     for key in testData:
         if key == 'name':
             ret = HtmlText(selector1=name_selector).setText(testData.get(key))
         elif key == 'superior':
             HtmlSelect(selector1=superior_selector).element.click()
             try:
                 ret = HtmlSelect(selector1=['xpath',"/html/body/div[4]/ul"]).selectLiByText(testData.get(key).get('superior1'))
             except:
                 ret = HtmlSelect(selector1=['xpath', "/html/body/div[3]/ul"]).selectLiByText(testData.get(key).get('superior1'))
             
             if testData.get(key).get('superior2'):
                 try:
                     ret = HtmlSelect(selector1=['xpath',"/html/body/div[3]/ul[2]"]).selectLiByText(testData.get(key).get('superior2'))
                 except:
                     ret = HtmlSelect(selector1=['xpath', "/html/body/div[4]/ul[2]"]).selectLiByText(testData.get(key).get('superior2'))
                 
             HtmlSelect(selector1=superior_selector).element.click()
             
         elif key == 'number':
             ret = HtmlText(selector1=number_selector).setText(testData.get(key))
         elif key == 'desc':
             ret = HtmlText(selector1=desc_selector).setText(testData.get(key))
         elif key == 'telephone':
             ret = HtmlText(selector1=telephone_selector).setText(testData.get(key))
         elif key == 'address':
             ret = HtmlText(selector1=address_selector).setText(testData.get(key))
         elif key == 'addressCode':
             HtmlSelect(selector1=addressCode_selector).element.click()
             ret = HtmlSelect(selector1=['xpath',"/html/body/div[4]/div[1]/div[1]/ul"]).selectLiByText(testData.get(key))
         else:
             ret = False
             logger.error('invalid parameter %s' % (key))
 
         if ret:
             logger.info('set %s:%s success' % (key, testData.get(key)))
         else:
             logger.error('set %s:%s fail' % (key, testData.get(key)))
示例#3
0
    def waitForDialog_addRole(self, expect_title):
        for i in range(10):
            try:
                title = HtmlModule(selector1=[
                    'xpath',
                    "//div[@id='system_editDept_modal_showAddPersonModel']/div/div[1]/span"
                ]).element.text
                logger.debug('dialog title is %s' % (title))
            except:
                sleep(0.5)
                continue

            if title == expect_title:
                logger.info('open dailog of %s success' % (expect_title))
                return True
            else:
                sleep(0.5)
        logger.error('open dailog of %s fail' % (expect_title))
        return False
示例#4
0
 def __init__(self, element=None, selector1=None, selector2=None):
     if element:
         self.element = element
     else:
         # self.element = self.getElement(selector1, selector2)
         for i in range(10):
             try:
                 self.element = self.getElement(selector1, selector2)
                 break
             except Exception as e:
                 if i == 9:
                     logger.error(
                         'finding element by selector1=%s ,selector2=%s failed'
                         % (selector1, selector2))
                     raise e
                 else:
                     logger.info(
                         'finding element by selector1=%s ,selector2=%s' %
                         (selector1, selector2))
                     sleep(0.5)
示例#5
0
    def __find_elements(self, selector):
        '''
        private method:
        :param selector:key-value list
        :return:element
        '''

        key = selector[0]
        value = selector[1]
        elements = None

        if key in [
                'xpath', 'link_text', 'class_name', 'id', 'css_selector',
                'name', 'partial_link_text', 'tag_name'
        ]:
            if key == 'xpath':
                elements = DR.find_elements_by_xpath(value)
            elif key == 'link_text':
                elements = DR.find_elements_by_link_text(value)
            elif key == 'class_name':
                elements = DR.find_elements_by_class_name(value)
            elif key == 'id':
                elements = DR.find_elements_by_id(value)
            elif key == 'css_selector':
                elements = DR.find_elements_by_css_selector(value)
            elif key == 'name':
                elements = DR.find_elements_by_name(value)
            elif key == 'partial_link_text':
                elements = DR.find_elements_by_partial_link_text(value)
            elif key == 'tag_name':
                elements = DR.find_elements_by_tag_name(value)

            if elements:
                return elements
            else:
                logger.error('fialed to find elements on the current page')
                return None
        else:
            logger.error('invalid key')
            return None
示例#6
0
    def executeSuite(self):
        '''
        execution test suite
        :return:0
        '''

        try:
            self.setDiscover()
            self.setReportPath()
            if os.path.exists(self.report_file):
                os.remove(self.report_file)

            with open(self.report_file, 'wb') as fb:
                runner = HTMLTestRunner.HTMLTestRunner(
                    stream=fb,
                    title=self.report_title,
                    description=self.report_description)
                runner.run(self.discover)
        except Exception as e:
            traceback.print_exc()
            logger.error(e)
        finally:
            DR.quit()
示例#7
0
    def setDialog(self, testData):
        roleName_selector = ['id', self.getIdSuffix('input', 'roleName')]
        roleDesc_selector = ['id', self.getIdSuffix('input', 'roleDesc')]
        roleLevel_selector = ['id', self.getIdSuffix('input', 'roleLevel')]

        for key in testData:
            if key == 'roleName':
                ret = HtmlText(selector1=roleName_selector).setText(
                    testData.get(key))
            elif key == 'roleDesc':
                ret = HtmlText(selector1=roleDesc_selector).setText(
                    testData.get(key))
            elif key == 'roleLevel':
                ret = HtmlText(selector1=roleLevel_selector).setText(
                    testData.get(key))
            else:
                ret = False
                logger.error('invalid parameter %s' % (key))

            if ret:
                logger.info('set %s:%s success' % (key, testData.get(key)))
            else:
                logger.error('set %s:%s fail' % (key, testData.get(key)))
示例#8
0
    def login(self,user,pwd,targetAddress = None):
        DR.get(LOGIN_ADDRESS)
        login_url = DR.current_url
        
        userText = HtmlText(selector1=['css_selector', 'div.input-wrapper:nth-child(3) > input:nth-child(2)'])
        userText.setText(user)

        pwdText = HtmlText(selector1=['css_selector', 'div.input-wrapper:nth-child(4) > input:nth-child(2)'])
        pwdText.setText(pwd)

        try:
            verificationCodeText = HtmlText(selector1=['css_selector','div.input-wrapper:nth-child(6) > input:nth-child(1)'])
            verificationCodeText.setText('11111')
        except:
            pass

        loginBtn = HtmlButton(selector1=['css_selector','.el-button'])
        loginBtn.clickBtn()

        for i in range(30):
            if DR.current_url == login_url:
                logger.info('logging in ,wait pls')
                sleep(0.5)
            else:
                logger.info('successful login ')
                break

        if targetAddress:
            for i in range(3):

                if DR.current_url == targetAddress:
                    logger.info('login to the homepage %s success '%(targetAddress))
                    return True
                else:
                    sleep(2)
            logger.error('login to the homepage failed')
            return False
示例#9
0
    def setDialog_addDept(self, testData):
        deptName_selector = ['id', self.getIdSuffix('input', 'deptName')]
        deptLeader_selector = [
            'xpath',
            '/html/body/div[1]/div/div[2]/section/section/section/main/div/div/div[2]/div/div[2]/div/form/div[2]/div/div/div[2]/input'
        ]
        deptTel_selector = ['id', self.getIdSuffix('input', 'tel')]
        deptAddress_selector = ['id', self.getIdSuffix('input', 'address')]
        deptDesc_selector = ['id', self.getIdSuffix('input', 'desc')]

        for key in testData:
            if key == 'deptName':
                ret = HtmlText(selector1=deptName_selector).setText(
                    testData.get(key))
            elif key == 'deptLeader':
                HtmlButton(selector1=deptLeader_selector).clickBtn()
                ret = HtmlSelect(
                    selector1=['xpath', '/html/body/div[3]/div[1]/div[1]/ul'
                               ]).selectLiByText(testData.get(key))
            elif key == 'tel':
                ret = HtmlText(selector1=deptTel_selector).setText(
                    testData.get(key))
            elif key == 'address':
                ret = HtmlText(selector1=deptAddress_selector).setText(
                    testData.get(key))
            elif key == 'desc':
                ret = HtmlText(selector1=deptDesc_selector).setText(
                    testData.get(key))
            else:
                ret = False
                logger.error('invalid parameter %s' % (key))

            if ret:
                logger.info('set %s:%s success' % (key, testData.get(key)))
            else:
                logger.error('set %s:%s fail' % (key, testData.get(key)))
示例#10
0
    def setDialog(self, testData):
        accountType_selector = [
            'id', self.getIdSuffix('select', 'accountType')
        ]
        accountOrgId_selector = [
            'id', self.getIdSuffix('select', 'accountOrgId')
        ]
        accountUsername_selector = [
            'id', self.getIdSuffix('input', 'accountUsername')
        ]
        accountName_selector = ['id', self.getIdSuffix('input', 'accountName')]
        accountPassword_selector = [
            'id', self.getIdSuffix('input', 'accountPassword')
        ]
        accountConfiremPassword_selector = [
            'id', self.getIdSuffix('input', 'accountConfiremPassword')
        ]
        accountIdcard_selector = [
            'id', self.getIdSuffix('input', 'accountIdcard')
        ]
        accountMobile_selector = [
            'id', self.getIdSuffix('input', 'accountMobile')
        ]
        accountEmail_selector = [
            'id', self.getIdSuffix('input', 'accountEmail')
        ]
        accountAddress_selector = [
            'id', self.getIdSuffix('input', 'accountAddress')
        ]
        accountMemo_selector = ['id', self.getIdSuffix('input', 'accountMemo')]

        for key in testData:
            if key == 'accountType':
                HtmlSelect(selector1=accountType_selector).element.click()
                ret = HtmlSelect(selector1=[
                    'xpath',
                    "//li[@name='system_user_options_0_accountType']/.."
                ]).selectLiByText(testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountOrgId':
                HtmlSelect(selector1=accountOrgId_selector).element.click()
                ret = HtmlSelect(selector1=[
                    'xpath',
                    "//li[@name='autotest_system_user_options_0_accountOrgId']/.."
                ]).selectLiByText(testData.get(key))
                # ret = HtmlSelect(selector1=['xpath',"/html/body/div[3]/div[1]/div[1]/ul"]).selectLiByText(testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountUsername':
                ret = HtmlText(selector1=accountUsername_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountName':
                ret = HtmlText(selector1=accountName_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:

                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountPassword':
                ret = HtmlText(selector1=accountPassword_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountConfiremPassword':
                ret = HtmlText(
                    selector1=accountConfiremPassword_selector).setText(
                        testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountIdcard':
                ret = HtmlText(selector1=accountIdcard_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountMobile':
                ret = HtmlText(selector1=accountMobile_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountEmail':
                ret = HtmlText(selector1=accountEmail_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountAddress':
                ret = HtmlText(selector1=accountAddress_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            elif key == 'accountMemo':
                ret = HtmlText(selector1=accountMemo_selector).setText(
                    testData.get(key))
                if ret:
                    logger.info('set %s:%s success' % (key, testData.get(key)))
                else:
                    logger.error('set %s:%s fail' % (key, testData.get(key)))
            else:
                logger.error('invalid parameter %s' % (key))