class TestCase104LoginException(unittest.TestCase): # 测试异常登录情况 def setUp(self): self.driver = AutomateDriverServer() self.base_url = self.driver.base_url self.base_page = BasePageServer(self.driver, self.base_url) self.login_page = LoginPage(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.log_in_read_csv = LogInPageReadCsv() self.connect_sql = ConnectSql() self.assert_text = AssertText() self.driver.set_window_max() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_case_login_exception(self): # 异常登录 self.base_page.open_page() sleep(2) # 第一种 密码和账号都为空 self.login_page.account_input('') self.login_page.password_input('') self.login_page.login_button_click() sleep(2) self.assertEqual(self.assert_text.log_in_page_account_or_password_not_null(), self.login_page.get_exception_text()) # 第二种 密码 和 账号一个不为空 self.login_page.account_input('jimitest') self.login_page.password_input('') self.login_page.login_button_click() sleep(2) self.assertEqual(self.assert_text.log_in_page_account_or_password_not_null(), self.login_page.get_exception_text()) self.login_page.account_input('') self.login_page.password_input('jimi123') self.login_page.login_button_click() sleep(2) self.assertEqual(self.assert_text.log_in_page_account_or_password_not_null(), self.login_page.get_exception_text()) # 第三种 账号不存在 self.login_page.account_input('fdsafasfd') self.login_page.password_input('jimi123') self.login_page.login_button_click() sleep(5) self.assertEqual(self.assert_text.log_in_page_account_not_exist(), self.login_page.get_exception_text()) # 第四种 密码错误 self.login_page.account_input('jimitest') self.login_page.password_input('jimi123222') self.login_page.login_button_click() sleep(5) self.assertEqual(self.assert_text.log_in_page_password_error(), self.login_page.get_exception_text())
class TestCase02LoginException(unittest.TestCase): # 测试登录异常情况 def setUp(self): self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.login_page = LoginPage(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.driver.set_window_max() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_user_login_exception(self): '''测试用户账户登录异常''' # 打开风控首页-登录页 self.base_page.open_page() # 第一种,密码和账号都为空 self.login_page.account_input('') self.login_page.password_input('') self.login_page.login_button_click() self.driver.wait() self.assertEqual('登录账号不能为空', self.login_page.get_exception_text()) # 第二种,密码和账号其中一个不为空 self.login_page.account_input('syntest') self.login_page.password_input('') self.login_page.login_button_click() self.driver.wait() self.assertEqual('登陆密码不能为空', self.login_page.get_exception_text()) self.login_page.account_input('') self.login_page.password_input('jimi123') self.login_page.login_button_click() self.driver.wait() self.assertEqual('登录账号不能为空', self.login_page.get_exception_text()) # 第三种,账号不存在 self.login_page.account_input('abdwerewf') self.login_page.password_input('123') self.login_page.login_button_click() self.driver.wait() self.assertEqual('账号不存在或者已经停用', self.login_page.get_exception_text()) # 第四种,密码错误 self.login_page.account_input('syntest') self.login_page.password_input('jimi') self.login_page.login_button_click() self.driver.wait() self.assertEqual('登录密码验证错误', self.login_page.get_exception_text())
class TestCase03LoginWithRememberMe(unittest.TestCase): # 测试登录时记住密码 def setUp(self): self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.login_page = LoginPage(self.driver, self.base_url) self.user_center = UserCenter(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.driver.set_window_max() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_user_login_exception(self): '''测试登录时记住密码''' # 打开风控首页-登录页 self.base_page.open_page() # 登录时勾选“记住我”复选框 self.login_page.account_input('syntest') self.login_page.password_input('jimi123') self.login_page.remember_me() self.login_page.login_button_click() self.driver.wait() # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql('syntest') print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 成功退出系统 sleep(2) self.user_center.logout() # 输入用户名 self.login_page.account_input('syntest') # 点击密码输入框 self.login_page.click_password() self.driver.wait() # 验证退出系统后“记住我”复选框是否是已勾选状态 box_status = self.login_page.check_remember_me() self.assertEqual(True, box_status, '记住密码失败') self.driver.wait() # 输入用户名,不输入密码直接点击登录 self.login_page.login_button_click() self.driver.wait() # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql('syntest') print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 成功退出系统 sleep(2) self.user_center.logout() # 输入用户名 self.login_page.account_input('syntest') # 点击密码输入框 self.login_page.click_password() # 验证退出系统后“记住我”复选框是否是已勾选状态 box_status = self.login_page.check_remember_me() self.assertEqual(True, box_status, '记住密码失败') self.driver.wait() # 输入用户名,取消勾选“记住我”复选框,输入密码再次登录 self.login_page.account_input('syntest') # 点击密码输入框 self.login_page.click_password() self.driver.wait(2) # 取消勾选“记住我”复选框 self.login_page.remember_me() # 验证“记住我”复选框是否是未勾选状态 box_status = self.login_page.check_remember_me() self.assertEqual(False, box_status, '取消记住密码失败') # 点击登录 self.login_page.login_button_click() self.driver.wait() # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql('syntest') print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 成功退出系统 sleep(2) self.user_center.logout() # 输入用户名 self.login_page.account_input('syntest') # 点击密码输入框 self.login_page.click_password() # 验证退出系统后“记住我”复选框是否是未勾选状态 box_status = self.login_page.check_remember_me() self.assertEqual(False, box_status, '取消记住密码失败')