def find_elements(self, ele_infos): """ 根据提供的元素参数信息进行元素识别 :param ele_infos: 元素信息,字典类型{} :return: element对象 """ try: ele_locate_type = ele_infos['locate_type'] ele_locate_value = ele_infos['locate_value'] ele_time_out = ele_infos['time_out'] if ele_locate_type == 'id': locate_type = By.ID elif ele_locate_type == 'xpath': locate_type = By.XPATH elif ele_locate_type == 'name': locate_type = By.NAME elif ele_locate_type == 'class': locate_type = By.CSS_SELECTOR element = WebDriverWait(self.driver, 5).until( lambda x: x.find_element(locate_type, ele_locate_value)) if element: logger.log_info('元素%s定位成功' % ele_infos['elemen_name']) return element except Exception as e: logger.err_info('[元素%s]识别失败,%s' % (ele_infos['elemen_name'], e.__str__())) self.scream_hot()
def setUp(self) -> None: logger.log_info('===============开始执行测试用例=============') self.base_page = BasePage(GetBrower().get_brower_driver()) self.driver = self.base_page.driver self.base_page.implicity_wait() try: self.base_page.open_url(self.url) except Exception as e: logger.err_info('打开浏览器失败,浏览器地址为:%s,%s' % (self.url, e.__str__())) return self.driver
def goto_product(self): # 进产品 ele = self.find_elements(self.product) ele.click() logger.log_info('成功进入产品界面')
def goto_mydipan(self): # 进入我的地盘 ele = self.find_elements(self.my_dipan) ele.click() logger.log_info('成功进入我的地盘')
def get_company_name(self): # 方法就是控件的操作 ele = self.find_elements(self.company_name) get_company_name = ele.get_attribute('title') logger.log_info('成功获取公司名称%s' % get_company_name) return get_company_name
def setUpClass(cls) -> None: logger.log_info('===============开始执行setupclass=============') cls.url = read_conf.get_conf_URL_path()
def tearDownClass(cls) -> None: logger.log_info('===============用例执行完成=============')
def login(self): self.login_page.input_username(read_conf.get_conf_username()) self.login_page.input_password(read_conf.get_conf_password()) self.login_page.click_login() logger.log_info('使用默认账号登录成功') return MainPage(self.driver)
def login_success(self, username='******', password='******'): self.login_page.input_username(username) self.login_page.input_password(password) self.login_page.click_login() logger.log_info('成功登录') return MainPage(self.driver)
def click_login(self): self.click(self.login_button) logger.log_info('正确登录')
def input_password(self, password): self.input(self.password_inputbox, password) logger.log_info('正确输入用户名%s' % str(password))
def input_username(self, username): # 方法就是控件的操作 self.input(self.username_inputbox, username) logger.log_info('正确输入用户名%s' % str(username))
def input(self, ele_info, conent): input_ele = self.find_elements(ele_info) input_ele.send_keys(conent) logger.log_info('%s输入成功' % ele_info['elemen_name'])
def click(self, ele_infos): ele = self.find_elements(ele_infos) ele.click() logger.log_info('成功点击%s这个元素' % ele_infos['elemen_name'])