def test_login_by_enter(self, get_driver): '''回车登录''' print("测试使用回车登录...") with allure.step('初始化浏览器driver'): login_page = LoginPage(get_driver) with allure.step('打开登录界面,正确的用户名密码'): login_page.open_login() login_page.input_user_pwd(self.user, self.correct_pwd) with allure.step('输入回车,检查是否登录'): login_page.driver.find_element_by_id("p").send_keys(Keys.ENTER) time.sleep(3) assert login_page.login_success()
def test_login_succ_speed(self, get_driver): '''登陆速度测试''' print("测试登录速度...") with allure.step('初始化浏览器driver'): login_page = LoginPage(get_driver) with allure.step('打开登录界面'): login_page.open_login() with allure.step('输入正确的用户名,密码,开始计时'): login_page.input_user_pwd(self.user, self.correct_pwd) start = time.clock() login_page.login_submit(False) with allure.step('检测是否在5s内完成'): # 等待主界面加载 login_page.driver.find_element_by_id("mainFrameContainer") if time.clock() - start > 5: pytest.fail("登陆超时")
def test_user_too_long(self, get_driver): '''测试用户名/密码过长''' print("测试输入用户名/密码过长..."), with allure.step('初始化浏览器driver'): login_page = LoginPage(get_driver) with allure.step('打开登陆界面,输入20位用户名和密码'): login_page.open_login() user = "******" * 20 login_page.input_user_pwd(user, user) with allure.step('输入的用户名小于20位'): if len(login_page.get_element_attr("u", "value")) < 20: pass else: pytest.fail("输入用户名长度没有限制") with allure.step('输入的密码小于20位'): if len(login_page.get_element_attr("p", "value")) < 20: pass else: pytest.fail("输入密码长度没有限制")
def test_brute_force(self, get_driver): '''错误登录次数限制''' print("测试防止暴力破解...") with allure.step('初始化浏览器driver'): login_page = LoginPage(get_driver) with allure.step('打开登录界面,输入脚本语句'): login_page.open_login() err = True for i in range(5): login_page.input_user_pwd(self.any_user, "xxx" * i) try: login_page.login_submit() except: # 出现拖动滑块限制 err = False break with allure.step('检查10此连续尝试是否被拦截'): if err: pytest.fail("未对暴力破解做限制")
def test_login_emptycheck(self, get_driver): '''非空检查''' print("测试对于用户名/密码非空检查...") with allure.step('初始化浏览器driver'): login_page = LoginPage(get_driver) with allure.step('打开登陆界面'): login_page.open_login() with allure.step('什么都不输入,点击登录'): # 登录且不等待 login_page.login_submit(False) with allure.step('界面提示输入用户名'): assert "输入账号" in login_page.get_source() with allure.step('只输入用户名,点击登录'): login_page.input_user_pwd(self.user, "") login_page.login_submit(False) with allure.step('界面提示输入密码'): assert "输入密码" in login_page.get_source() with allure.step('只输入密码,点击登录'): login_page.input_user_pwd("", "123456") login_page.login_submit(False) with allure.step('界面提示输入用户名'): assert "输入账号" in login_page.get_source()