class Test_Login_Page: def setup(self): # 初始化对象 self.driver = init_driver() self.login_obj = Page_Obj(self.driver).return_login() def teardown(self): self.driver.quit() # @allure.step(title="登录模块") # @pytest.mark.parametrize("test_num, phone, password, expect", read_test_data()) # def test_login(self, test_num, phone, password, expect): # # 输入手机号 # allure.attach('输入%s' % phone, '输入手机号') # self.login_obj.phone_input(phone) # # 输入密码 # allure.attach('输入%s' % password, '输入密码') # self.login_obj.pwd_input(password) # # 点击登录按钮 # allure.attach('', '点击登录按钮') # self.login_obj.click_login_btn() # if test_num == "输入正确的手机号正确的密码": # self.login_obj.if_disp(Page.index_text) # ele = self.login_obj.find_element_o(Page.index_text) # self.driver.get_screenshot_as_file("./screen/%s.png" % test_num) # assert expect in ele.text # elif test_num == "密码为空": # self.login_obj.is_toast("请输入") # toast_text = self.login_obj.find_toast("请输入") # self.driver.get_screenshot_as_file("./screen/%s.png" % test_num) # assert expect in toast_text @allure.step("登录步骤") @pytest.mark.parametrize("args", data_with_key("Login_data")) @allure.story("登录功能测试用例") def test_login(self, args): test_num = data_with_key("Login_data") screen_name = args["screen_name"] phone = args["phone"] password = args["password"] # 输入手机号 allure.attach('输入%s' % phone, '输入手机号') self.login_obj.phone_input(phone) # 输入密码 allure.attach('输入%s' % password, '输入密码') self.login_obj.pwd_input(password) # 点击登录按钮 allure.attach('点击', '点击登录按钮') self.login_obj.click_login_btn() time.sleep(1) self.driver.get_screenshot_as_file("./screen/%s.png" % screen_name) # 上传截图到报告 allure.attach(open('./screen/' + screen_name + '.png', 'rb').read(), '截图', allure.attachment_type.PNG) if test_num == "test_login_001": self.login_obj.if_disp(Page.index_text) ele = self.login_obj.find_element_o(Page.index_text) assert args["expect"] in ele.text elif test_num == "test_login_002": assert self.login_obj.is_toast("请输入密码")
class Test_Add_Page: def setup_class(self): self.driver = init_driver() self.add_obj = Page_Obj(self.driver).return_add_page() def teardown_class(self): self.driver.quit() @pytest.fixture() def click(self): # 点击新建联系人 self.add_obj.click_add() @pytest.mark.usefixtures("click") @pytest.mark.parametrize("test_num,name,phone", yaml_add_data()) def test_add(self, test_num, name, phone): print("用例编号:", test_num) self.add_obj.input_add_click_return(name, phone) self.driver.keyevent(4)
class Test_Add_User: def setup_class(self): self.driver = init_driver() self.add_user_obj = Page_Obj(self.driver).address_add_user() def teardown_class(self): self.driver.quit() @pytest.fixture() def add_user_btn(self): # 点击添加用户按钮 self.add_user_obj.click_add() # @pytest.fixture(scope="class") # def save_local_btn(self): # # 点击本地保存 # self.add_user_obj.click_save_local() @pytest.mark.usefixtures("add_user_btn") # @pytest.mark.usefixtures("add_user_btn", "save_local_btn") @pytest.mark.parametrize("test_num,test_name,test_phone,expect_data",yaml_data()) def test_input_user_info(self,test_num,test_name,test_phone,expect_data): self.add_user_obj.input_user_info(test_name,test_phone) print("test_001", test_num) if test_num == "test_001": assert expect_data not in self.add_user_obj.get_user_list() else: assert expect_data in self.add_user_obj.get_user_list()
class Test_Add_User: def setup_class(self): self.driver = init_driver() self.add_user_obj = Page_Obj(self.driver).return_add_user() def teardown_class(self): self.driver.quit() @allure.step(title="点击新建联系人") @pytest.fixture() def add_user_btn(self): # 添加用户 self.add_user_obj.click_add() @allure.step(title="输入用户信息") @pytest.mark.usefixtures("add_user_btn") @pytest.mark.parametrize("test_num, name, phone, expect", read_test_data()) def test_input_user_info(self, test_num, name, phone, expect): self.add_user_obj.input_user_info(name, phone) if test_num == "test_user_001": assert expect not in self.add_user_obj.get_user_list() else: assert expect in self.add_user_obj.get_user_list()
class Test_search: def setup_class(self): self.driver = InitDriver().initDriver(scripts.appPackage, scripts.appActivity) self.search_obj = Page_Obj(self.driver).search_text() self.search_obj.search_click() def teardown_class(self): self.search_obj.search_return() self.driver.quit() # @pytest.fixture() # @pytest.mark.run(order=1) # def test_search_001(self): # self.search_obj.search_click() #@pytest.mark.usefixtures("search_001") # @pytest.fixture() # @pytest.mark.run(order=2) # @pytest.mark.parametrize("search_001",indirect=True) @allure.issue('http://www.163.com') @allure.testcase('https://www.baidu.com') @allure.severity(allure.severity_level.BLOCKER) @allure.step(title='这是搜索框测试') @pytest.mark.parametrize("num,text", yaml_data()) def test_search_002(self, num, text): # print("用例编号:"+num) self.search_obj.search_input(text) self.driver.get_screenshot_as_file("./Screen/set_%s.png" % text) allure.attach( '我是测试步骤001的描述~~~', '描述', )
class Test_login: @allure.step("初始化对象,打开浏览器") def setup(self): self.driver = webdriver.Chrome() self.lp = Page_Obj(self.driver).Login_Page() self.lp.open_browser('http://119.29.235.245:9003/index.php/user/login') @allure.step("关闭浏览器") def teardown(self): self.lp.close_browser() # @pytest.mark.parametrize("user,passwd", [('zerong.zhang', 'RK0A9ICT'), ('zzzzrr', '123456')]) # def test_login(self, user, passwd): # self.lp.test_login(user, passwd) # expect_url = 'http://119.29.235.245:9003/index.php/home/welcome' # current_url = self.driver.current_url # assert expect_url == current_url @pytest.mark.parametrize("user,passwd", read_database()) @allure.story("用户登录验证") def test_login(self, user, passwd): with allure.step("输入用户名,密码"): self.lp.test_login(user, passwd) allure.attach(self.driver.get_screenshot_as_png(), "登录截图", allure.attachment_type.PNG) expect_url = 'http://119.29.235.245:9003/index.php/home/welcome' current_url = self.driver.current_url assert expect_url == current_url
class Test_Search_Page: def setup_class(self): self.driver = init_driver() self.search_obj = Page_Obj(self.driver).return_search() self.search_obj.click_search_btn() def teardown_class(self): self.search_obj.search_return() self.driver.quit() @pytest.mark.parametrize("test_num,text,expect_data", yaml_data()) def test_input_text(self, test_num, text, expect_data): print("用例编号:", test_num) self.search_obj.search_input(text) self.driver.get_screenshot_as_file("./screen/%s.png" % test_num) assert expect_data == 456
class Test_Search_Page: def setup_class(self): self.driver = init_driver() self.search_obj = Page_Obj(self.driver).return_search() self.search_obj.click_search_btn() def teardown_class(self): self.search_obj.search_return() self.driver.quit() @pytest.mark.parametrize("test_num,text,expect_data", yaml_data()) # @pytest.allure.severity(pytest.allure.severity_level.CRITICAL) @allure.step('测试搜索') @allure.issue('http://www.baidu.com', 'Test') def test_input_text(self, test_num, text, expect_data): print("用例编号:", test_num) allure.attach('描述', "执行测试步骤" + test_num) self.search_obj.search_input(text) self.driver.get_screenshot_as_file("./screen/%s.png" % test_num) assert expect_data == 456
class Test_Add_User: def setup_class(self): self.driver = init_driver() self.add_user_obj = Page_Obj(self.driver).return_add_user() def teardown_class(self): self.driver.quit() @pytest.fixture() def add_user_btn(self): # 添加用户 self.add_user_obj.click_add() @pytest.fixture(scope="class") def save_local_btn(self): # 点击本地保存 self.add_user_obj.click_save_local() @pytest.mark.usefixtures("add_user_btn", "save_local_btn") @pytest.mark.parametrize("name, phone", [("李001", "13333333333"), ("李002", "13555555555")]) def test_input_user_info(self, name, phone): self.add_user_obj.input_user_info(name, phone)
def setup(self): # 初始化对象 self.driver = init_driver() self.login_obj = Page_Obj(self.driver).return_login()
def setup_class(self): self.driver = init_driver() self.add_user_obj = Page_Obj(self.driver).return_add_user()
def setup_class(self): self.driver = init_driver() self.search_obj = Page_Obj(self.driver).return_search() self.search_obj.click_search_btn()
def setup_class(self): self.driver = init_driver() self.search_obj = Page_Obj(self.driver).return_page() # 点击搜索输入框 self.search_obj.search_click()
def setup_class(self): self.driver = InitDriver().initDriver(scripts.appPackage, scripts.appActivity) self.search_obj = Page_Obj(self.driver).search_text() self.search_obj.search_click()
def setup(self): self.driver = webdriver.Chrome() self.lp = Page_Obj(self.driver).Login_Page() self.lp.open_browser('http://119.29.235.245:9003/index.php/user/login')