def test_Login(self): logger.info("开始执行登录脚本...") #获取是否执行列 isExecuteUser = TestLogin.excelObj.get_col_values(login_isExecute) for idx, i in enumerate(isExecuteUser[1:]): start_time = time.time() if i == 'Y': username = TestLogin.excelObj.get_cell_value( idx + 2, acount_username) password = TestLogin.excelObj.get_cell_value( idx + 2, acount_password) logger.info("执行测试数据:%s,%s" % (username, password)) try: options = webdriver.ChromeOptions() browser = webdriver.Chrome(options=options) browser.maximize_window() browser.get(loginpageUrl) logger.info('启动浏览器,访问登录页面...') LoginAction.login(username, password, browser) logger.info('登录操作执行...') try: # browser.implicitly_wait(5) # 如果在首页页面找到MDT管理系统logo,则通过测试用例,如果没找到该logo则测试用例未通过 homepage = HomePage(browser) self.assertIs(homepage.logoDiv().is_displayed(), True) logger.info('在首页页面找【MDT管理系统】logo') except Exception as e: # self.assertTrue(1 == 2) logger.debug('在首页页面找不到【MDT管理系统】logo,失败,用例不通过') TestLogin.excelObj.write_cell_value( idx + 2, login_testResult, 'fail', 'red') TestLogin.excelObj.write_cell_value( idx + 2, login_time, str(time.time() - start_time) + 's', 'red') raise e else: logger.info('在首页页面找到【MDT管理系统】logo,成功,用例通过') TestLogin.excelObj.write_cell_value( idx + 2, login_testResult, 'success', 'green') TestLogin.excelObj.write_cell_value( idx + 2, login_time, str(round( (time.time() - start_time) / 1000, 2)) + 's') except ElementNotVisibleException as e: logger.error("数据问题,元素没有找到..") except NoSuchElementException as e: logger.error("数据问题..重试") except Exception as e: logger.error(e) raise e else: continue
def setUpClass(cls) -> None: TestAddDoctorAuto.browser = webdriver.Chrome() TestAddDoctorAuto.browser.maximize_window() logger.info("开始登陆...") TestAddDoctorAuto.browser.get(loginpageUrl) TestAddDoctorAuto.login_cookie = LoginAction.login( account, password, TestAddDoctorAuto.browser)
logger.info("找到元素" + locateExpression) return element def doctorQueryInfoTd(self): try: locateType, locateExpression = self.QueryDoctorOptions[ 'DoctorManagePage.doctorQueryInfoTd'.lower()].split('>') element = getElement(self.driver, locateType, locateExpression) except Exception as e: logger.error(e) else: logger.info("找到元素" + locateExpression) return element if __name__ == "__main__": from selenium import webdriver import time options = webdriver.ChromeOptions() browser = webdriver.Chrome(options=options) browser.get("http://47.96.186.244:8020/user/login") browser.maximize_window() LoginAction.login( 'yinchengjie', '123456', browser, "http://47.96.186.244:8020/doctorControl/doctorControlList") doctor_manager_page = DoctorManagePage(browser) browser.implicitly_wait(1) doctor_manager_page.doctorNameInput().send_keys('123') # browser.quit()
'AddDoctorPage.doctorTitleOptions'.lower()].split('>')[1] SelectorUtils().selector_choose(self.driver, doctorTitleSelector, doctorTitleOptions) doctorDepartmentSelector = self.AddDoctorOptions[ 'AddDoctorPage.doctorDepartmentSelector'.lower()].split('>')[1] doctorDepartmentOptions = self.AddDoctorOptions[ 'AddDoctorPage.doctorDepartmentOptions'.lower()].split('>')[1] SelectorUtils().selector_choose(self.driver, doctorDepartmentSelector, doctorDepartmentOptions) self.AddDoctor.doctorPhoneNumberInput().send_keys(RandomInfo.get_tel()) self.AddDoctor.doctorEmailInput().send_keys(RandomInfo.get_email()) self.AddDoctor.doctorRemarksTextArea().send_keys("备注") self.AddDoctor.doctorSubmitButton().click() def get_doctorNumberAuto(self): print('医生编号' + doctorNumberAuto) return doctorNumberAuto if __name__ == '__main__': options = webdriver.ChromeOptions() browser = webdriver.Chrome(options=options) browser.get("http://47.96.186.244:8020/user/login") browser.maximize_window() token = LoginAction.login('yinchengjie', '123456', browser) url2 = r'http://47.96.186.244:8020/doctorControl/doctorControlList/add' time.sleep(1) browser.get(eval('url2')) time.sleep(3) addDoctor = AddDoctorAction(browser) addDoctor.addDoctorAutoAction()