class TestAddressBook: data = BasePage.yaml_load('../data/member_manage.data.yaml') step = BasePage.yaml_load('../data/member_manage.step.yaml') def setup_class(self): self.dx = Index() # self.dx.driver.implicitly_wait(3) def teardown_class(self): self.dx.driver.close() @pytest.mark.parametrize('name, acct_id, phone, mail, expect', data['test_add_member']) def test_add_member(self, name, acct_id, phone, mail, expect): res = self.dx.address_book().member_manage().add_member( name, acct_id, phone, mail) assert res == expect @pytest.mark.parametrize('name, expect', data['test_delete_member']) def test_delete_member(self, name, expect): res = self.dx.address_book().member_manage().delete_member('杜宁') assert res == expect @pytest.mark.parametrize('name, acct_id, phone, mail, expect', data['test_add_member']) def test_add_member_step(self, name, acct_id, phone, mail, expect): BasePage.params = { 'name': name, 'acct_id': acct_id, 'phone': phone, 'mail': mail } self.dx.address_book().member_manage().steps(self.step['add_member'])
def __init__(self, driver): BasePage.__init__(self, driver) self.user = (By.NAME, "user") self.password = (By.NAME, "pwd") self.captcha = (By.NAME, "captcha") self.captchaImg = (By.ID, "captchaImg") self.btn = (By.CLASS_NAME, "btn")
def __init__(self, driver): BasePage.__init__(self, driver) self.user_name = (By.NAME, "username") self.email = (By.NAME, "email") self.pwd = (By.NAME, "pwd") self.confirm_pwd = (By.NAME, "confirmPwd") self.captcha = (By.ID, "captcha") self.captcha_img = (By.ID, "captchaimg") self.bt = (By.CLASS_NAME, "btn")
def __init__(self, driver): # 先继承在重构, 可以获得父类的属性 # 定义了__init__方法, 就是在定义了构造函数进行了重构, 如果不先进行继承的话, 子类则不能继承父类的属性 """ 继承构造类的两种方法 1. 经典类的写法: 父类名称.__init__(self, 参数1,参数2,...) 2.新式类的写法:super(子类,self).__init__(参数1,参数2,....) """ BasePage.__init__(self, driver) # 继承父类的构造方法 self.user = (By.NAME, "user") self.password = (By.NAME, "pwd") self.btn = (By.CLASS_NAME, "btn")
class XueQiuPage(BasePage): _mine_button = BasePage.by_xpath("//*[@index='3']") def goto_mine_page(self): self.find(self._mine_button).click() return MinePage()
class MinePage(BasePage): _account_button = BasePage.by_id("login_account") _password_button = BasePage.by_id("button_next") _login_button = BasePage.by_id("button_next") _message_login_fail = BasePage.by_id("md_content") def __login_by_phone(self, phone, captch): self.driver.tap([(16, 166), (464, 194)]) self.find(self._account_button).send_keys(phone) self.find(self._password_button).send_keys(captch) self.find(self._login_button).click() def login_fail(self, phone, captch): self.__login(phone, captch) return self._message_login_fail.text def login_successful(self, phone, captch): self.__login(phone, captch) return self
class AddCart_Page(BasePage): #加入购物车页面测试 def __init__(self, driver): self.addcart = BasePage(driver, node='AddCartElement') def addcart_case(self): #先调用登录case后再运行 self.addcart.find_element('book').click() self.addcart.find_element('literature').click() self.addcart.find_element('addcart').click()
class Login_Page(BasePage): def __init__(self, driver): self.login = BasePage(driver, node='LoginElement') def login_case(self, email, password): self.login.find_element('email').send_keys(email) self.login.find_element('password').send_keys(password) self.login.find_element('loginbutton').click() def login_err(self, email, password): self.login_case(email, password) text = self.login.find_element('loginerr').text if text is not None: return True else: return False
def run_main(self): self.handle_excel = ReadExcel() self.action_method = BasePage() time.sleep(2) case_lines = self.handle_excel.get_lines() for i in range(1, case_lines): is_run = self.handle_excel.get_cell(i, 2) if is_run == 'yes': method = self.handle_excel.get_cell(i, 3) handle_value = self.handle_excel.get_cell(i, 4) send_value = self.handle_excel.get_cell(i, 5) if send_value == '': if handle_value == '': self.run_method(method) else: self.run_method(method, handle_value) else: self.run_method(method, handle_value, send_value) time.sleep(1)
class TestDepartmentManage: data = BasePage.yaml_load('../data/department_manage.data.yaml') def setup_class(self): self.dx = Index() def teardown_class(self): self.dx.driver.close() @pytest.mark.parametrize('name, p_name, expect', data['test_add_dept']) def test_add_dept(self, name, p_name, expect): res = self.dx.address_book().department_manager().add_dept( name, p_name) assert res == expect @pytest.mark.skip(reason="不执行该用例") @pytest.mark.parametrize('name, expect', data['test_delete_dept']) def test_delete_dept(self, name, expect): res = self.dx.address_book().department_manager().delete_dept(name) assert res == expect
def __init__(self, driver): self.rg = BasePage(driver, node='RegisterElement')
class Register_Page(BasePage): def __init__(self, driver): self.rg = BasePage(driver, node='RegisterElement') #self.ri = ReadINI(node='ErrInfo') def register_case(self, firstname, lastname, email, telephone, password): self.rg.find_element('lastname').send_keys(lastname) self.rg.find_element('firstname').send_keys(firstname) self.rg.find_element('email').send_keys(email) self.rg.find_element('telephone').send_keys(telephone) self.rg.find_element('password').send_keys(password) self.rg.find_element('confirmPassword').send_keys(password) self.rg.find_element('checkbox').click() self.rg.find_element('sliderButton').click() err_text = [] #如果对应输入框存在错误提示信息,则拼接到err_text中返回 if self.rg.find_element('firstname_err') is not None: err_text.append( ['firstname_err', self.rg.find_element('firstname_err').text]) if self.rg.find_element('lastname_err') is not None: err_text.append( ['lastname_err', self.rg.find_element('lastname_err').text]) if self.rg.find_element('email_err') is not None: err_text.append( ['email_err', self.rg.find_element('email_err').text]) if self.rg.find_element('phone_err') is not None: err_text.append( ['phone_err', self.rg.find_element('phone_err').text]) if self.rg.find_element('password_err') is not None: err_text.append( ['password_err', self.rg.find_element('password_err').text]) return err_text def register_phone_err(self, firstname, lastname, email, telephone, password): self.register_case(firstname, lastname, email, telephone, password)
def __init__(self): BasePage.__init__(self)
def __init__(self): BasePage.__init__(self) self.goto_movie_page()
def __init__(self, driver): self.buy = BasePage(driver, node='BuyElement')
def __init__(self, driver): self.addcart = BasePage(driver, node='AddCartElement')
def __init__(self): BasePage.__init__(self) self.goto_login_page()
def __init__(self,driver): self.address = BasePage(driver,node='AddressElement')
class Address_Page(BasePage): #地址管理页面测试 def __init__(self,driver): self.address = BasePage(driver,node='AddressElement') def address_add_case(self,firstname,lastname,address,city,country,zone): #调用登录后,选择右侧地址管理按钮进入地址管理页面 self.address.find_element('addressmanage').click() time.sleep(2) self.address.find_element('newaddress').click() time.sleep(2) self.address.find_element('firstname').send_keys(firstname) self.address.find_element('lastname').send_keys(lastname) self.address.find_element('address').send_keys(address) self.address.find_element('city').send_keys(city) countryElement = self.address.find_element('country') selCountry = Select(countryElement) selCountry.select_by_visible_text(country) zoneElement = self.address.find_element('zone') selZone = Select(zoneElement) selZone.select_by_visible_text(zone) self.address.find_element('addbutton').click()
def find_element(self, element, node): el = BasePage(self.driver, node) return el.find_element(element)
def __init__(self, driver): self.login = BasePage(driver, node='LoginElement')
class Buy_Page(BasePage): def __init__(self, driver): self.buy = BasePage(driver, node='BuyElement') def buy_case(self): #先调用登录case后再运行 self.buy.find_element('cart').click() self.buy.find_element('gobuy').click() time.sleep(1) self.buy.find_element('payaddresscontinue').click() time.sleep(1) self.buy.find_element('shopaddresscontinue').click() time.sleep(1) self.buy.find_element('methodcontinue').click() time.sleep(1) self.buy.find_element('agree').click() time.sleep(1) self.buy.find_element('paymethod').click() time.sleep(1) self.buy.find_element('confirm').click()