class TestMyself: def setup(self): self.action = Page().init_page_myself def teardown(self): self.action.driver.quit() # @pytest.mark.skip() @pytest.mark.parametrize("obj", get_data("myself", "login_no_num")) def test_login_no_num(self, obj): Page().init_page_home.into_page() # 在这里为了避免被操作的元素还未出现,可以设置强制等待,让主界面内容进行加载渲染 time.sleep(2) # 点击 我 self.action.click_myself() # 点击使用已有账号登录 self.action.click_exist_num() # 输入账号 self.action.input_num(obj[0]) # 输入密码 self.action.input_pwd(obj[1]) # 点击登录 self.action.click_login() # 断言账号不存在用例执行是否通过 self.action.assert_toast("此用户不存在")
class Test_Login(): def setup_class(self): self.driver = init_driver() self.login_obj = Page(self.driver).get_login() # 输入手机号码 # 输入密码 # 判断页面登入是否成功:使用断言方法 # 每次传入参数直接为一个 列表,可以直接对应3个参数 # 这种方式 用的比较少,在数据量比较少可以用,但是yml书写比较模糊 # @pytest.mark.parametrize(("name","pwd","toast"),get_data("TestData")) # def test_login(self,name,pwd,toast): # self.login_obj.login_name(name) # self.login_obj.login_pwd(pwd) # self.login_obj.click_login() # # assert self.login_obj.is_toast_exit(toast) # # print('xxxx') # 每次传入的参数是一个字典,使用时需要根据字典的键获取对应值 # 这种方法用的比较多,因为yml的书写格式 很清晰 @allure.step(title="这是登录测试") @pytest.mark.parametrize("dir", get_yml_with_filename_key("login_data", "TestData2")) def test_login2(self, dir): name = dir["name"] password = dir["password"] toast = dir["toast"] #当有需要新增参数数据时,可以自己再加入yml,读取格式无需修改,很方便 screen = dir["screen"] allure.attach("输入用户名", name) self.login_obj.login_name(name) allure.attach("输入密码", password) self.login_obj.login_pwd(password) allure.attach("点击登入") self.login_obj.click_login() allure.attach("登入结果判断", toast) #断言判断,并且进行截图 # toast_exist= self.login_obj.is_toast_exit(toast,True,screen) # #将截图上传到报告中 # allure.attach("图片",open("./screen/"+screen+".png","rb").read(),allure.attachment_type.PNG) # assert toast_exist def test_001(self): print(111) def teardown_class(self): self.driver.quit()
class TestAddress: def setup(self): self.action = Page().init_page_address # @pytest.mark.skip() @pytest.mark.parametrize("obj", get_data("address", "address_new")) def test_address_new(self, obj): # 进入主界面,通掉用page_home里的页面动作 Page().init_page_home.into_page() # 点击我,通过掉用page_myself里的页面动作 self.use_myself = Page().init_page_myself self.use_myself.click_myself() # 判断用户是否登录 通过掉用page_myself里的页面动作 if not self.use_myself.is_login(): self.use_myself.click_exist_num() self.use_myself.input_num(18610453007) self.use_myself.input_pwd(123456) self.use_myself.click_login() # 点击设置 通过掉用page_myself里的页面动作 self.use_myself.click_setting() # 点击地址管理 self.action.click_address_manage() # 点击 新增地址 self.action.click_new_address() # 输入收件人 self.action.input_receipt(obj[0]) # 输入手机号 self.action.input_phone_num(obj[1]) # 展开省市区下拉 self.action.click_area_select() # 选择省市区 self.action.select_area(obj[2], obj[3], obj[4]) # 输入详细地址 self.action.input_detail_address(obj[5]) # 点击保存 self.action.click_save() time.sleep(2) # 断言 self.action.assert_address_add(obj[0], obj[1]) @pytest.mark.skip() def test_address_del(self): # 进入主界面 Page().init_page_home.into_page() # 点击我 Page().init_page_myself.click_myself() # 判断用户是否登录 if not Page().init_page_myself.is_login(): Page().init_page_myself.click_exist_num() Page().init_page_myself.input_num(18610453007) Page().init_page_myself.input_pwd(123456) Page().init_page_myself.click_login() # 点击设置 self.action.click_setting() # 点击地址管理 self.action.click_address_manage() time.sleep(1) # 获取删除前的地址条数 before_del = self.action.get_address_count() if not before_del: return else: # 点击编辑 self.action.click_address_edit() # 点击删除 self.action.click_address_del() # 点击确定 self.action.click_address_confirm() time.sleep(1) # 获取删除后的地址条数 after_del = self.action.get_address_count() # 断言 assert before_del - after_del == 1 @pytest.mark.skip() def test_address_del_all(self): # 进入主界面 Page().init_page_home.into_page() # 点击我 Page().init_page_myself.click_myself() # 判断用户是否登录 if not Page().init_page_myself.is_login(): Page().init_page_myself.click_exist_num() Page().init_page_myself.input_num(18610453007) Page().init_page_myself.input_pwd(123456) Page().init_page_myself.click_login() # 点击设置 self.action.click_setting() # 点击地址管理 self.action.click_address_manage() time.sleep(1) # 获取删除前的地址条数 before_del = self.action.get_address_count() print(before_del) # 执行删除 for i in range(before_del): # 点击编辑 self.action.click_address_edit() # 点击删除 self.action.click_address_del() # 点击确认 self.action.click_address_confirm() time.sleep(1) # 获取删除后的地址条数 after_del = self.action.get_address_count() print(after_del) # 断言 assert after_del == 0