def isEnterMenuSuccess(self,menuName): tags = HtmlModule(selector1=self.pageTag_selector).element.find_elements_by_tag_name('span') for tag in tags: if tag.text == menuName: logger.info('the current page is %s ' % (menuName)) return True logger.info('the enter top Menu fail %s ' % (menuName)) return False
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
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)))
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
def checkupTableData(self, expect_data): conversionRules = { '角色名称': 'roleName', '角色描述': 'roleDesc', '角色级别': 'roleLevel' } actual_datas = self.getTableData() for actual_data in actual_datas: ret, sameDict = compareDict( expect_data, convertDict(actual_data, conversionRules)) if ret != -1 and ret != -2: logger.info('sameDict is : %s' % (sameDict)) return True elif ret == -1: logger.info('diffDict is : %s' % (sameDict)) return False else: pass # placeholder return False
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)
def checkupTableData(self, expect_data): conversionRules = { '部门名称': 'deptName', '部门电话': 'tel', '分管领导': 'deptLeader', '地址': 'address', '备注': 'desc', '所属单位': 'deptOrgId', '状态': 'deptState' } actual_datas = self.getTableData() for actual_data in actual_datas: ret, sameDict = compareDict( expect_data, convertDict(actual_data, conversionRules)) if ret != -1 and ret != -2: logger.info('sameDict is : %s' % (sameDict)) return True elif ret == -1: logger.info('diffDict is : %s' % (sameDict)) return False else: pass # placeholder return False
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)))
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)))
def checkupTableData(self, expect_data): conversionRules = { '账号': 'accountUsername', '姓名': 'accountName', '身份证': 'accountIdcard', '手机号': 'accountMobile', 'E-mail': 'accountEmail', '所属组织': 'accountOrgId', '备注': 'accountMemo', '状态': 'accountState' } actual_datas = self.getTableData() for actual_data in actual_datas: ret, sameDict = compareDict( expect_data, convertDict(actual_data, conversionRules)) if ret != -1 and ret != -2: logger.info('sameDict is : %s' % (sameDict)) return True elif ret == -1: logger.info('diffDict is : %s' % (sameDict)) return False else: pass # placeholder return False
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
def search(self, keyword): logger.info('search %s' % (keyword)) selector_text = ['id', self.getIdSuffix('input', 'text')] selector_btn = ['id', self.getIdSuffix('button', 'search')] HtmlText(selector1=selector_text).setText(keyword) HtmlButton(selector1=selector_btn).clickBtn()
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))