class TestCase04UserCenterModifyPassword(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.user_center_read_csv = UserCenterReadCsv() self.driver.set_window_max() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) # 打开途强在线首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.test_user_login() def tearDown(self): self.driver.quit_browser() def test_user_center_modify_password(self): # 通过csv测试修改密码功能 # 点击打开修改密码框 self.user_center.click_edit_password() csv_file = self.user_center_read_csv.read_csv( "modify_password_exception.csv") csv_data = csv.reader(csv_file) for row in csv_data: data = { "old_password": row[0], "new_password": row[1], "new_password2": row[2], "pwd_prompt": row[3], } text = self.user_center.get_modify_pwd_exception_prompt( data['old_password'], data['new_password'], data['new_password2']) self.assertIn(data["pwd_prompt"], text, "修改密码,错误提示语显示不一致") csv_file.close() # 关闭修改密码框 self.user_center.click_edit_password_close() # 退出登录 self.user_center.logout()
class TestCase03UserCenterModifyPassword(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.user_center_read_csv = UserCenterReadCsv() 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_center_modify_password(self): # 通过csv测试修改密码功能 csv_file = self.user_center_read_csv.read_csv( 'user_to_modify_password.csv') csv_data = csv.reader(csv_file) for row in csv_data: user_to_modify_password = { "account": row[0], "old_passwd": row[1], "new_passwd": row[2], } # 打开途强在线首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.user_login(user_to_modify_password['account'], user_to_modify_password['old_passwd']) # 修改密码 self.user_center.click_edit_password() self.user_center.input_old_password( user_to_modify_password['old_passwd']) self.user_center.input_new_password( user_to_modify_password['new_passwd']) self.user_center.input_password_again( user_to_modify_password['new_passwd']) # 确认 self.user_center.click_edit_password_confirm() self.driver.wait() # 用旧密码登录,验证提示 self.login_page.user_login(user_to_modify_password['account'], user_to_modify_password['old_passwd']) exception_text = self.login_page.get_exception_text() self.assertEqual('登录密码验证错误', exception_text) self.driver.wait() # 用新密码登录,验证是否修改成功 self.login_page.user_login(user_to_modify_password['account'], user_to_modify_password['new_passwd']) # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql( user_to_modify_password['account']) print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 退出登录 self.user_center.logout() csv_file.close()
class TestCase07OrgManageSearchOrg(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() 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_search_org(self): # 通过csv测试搜索公司部门功能 csv_file = self.user_center_read_csv.read_csv('search_org.csv') csv_data = csv.reader(csv_file) for row in csv_data: search_org = { "account": row[0], "password": row[1], "key": row[2], } # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.user_login(search_org['account'], search_org['password']) # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql( search_org['account']) print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 点击进入部门管理 self.organize_management.click_org_manage() # 输入搜索关键词进行搜索 self.organize_management.search_org(search_org['key']) # 获取搜索结果 num = int(self.organize_management.get_search_result_num()) org_name = self.organize_management.get_search_result_all() # 数据库查询搜索结果 org_name_by_sql = self.organize_management.get_search_result_orgname_by_sql( search_org['account'], search_org['key']) num_by_sql = self.organize_management.get_search_result_num_by_sql( search_org['account'], search_org['key']) # 验证搜索结果是否一致 self.assertEqual(num, num_by_sql) self.assertEqual(set(org_name), set(org_name_by_sql)) # 跳出外层frame self.organize_management.switch_to_default_content() # 退出登录 self.user_center.logout() csv_file.close()
class TestCase03OrgManageAddOrgException2(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() self.driver.set_window_max() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.test_user_login() def tearDown(self): self.driver.quit_browser() def test_add_org_exception2(self): # 通过csv测试新增公司部门功能异常情况-部门名称已存在 # 获取当前登录账户 log_in_account = self.user_center.get_login_account() print(log_in_account) csv_file = self.user_center_read_csv.read_csv( 'add_org_info_exception2.csv') csv_data = csv.reader(csv_file) for row in csv_data: add_org_info_exception = { "add_org_name": row[0], "add_org_tel": row[1], "exception_text": row[2], } # 点击进入部门管理 self.organize_management.click_org_manage() # 点击新增公司部门 self.organize_management.click_add_org() # 验证上级部门是否显示正确 sup_org_name = self.organize_management.get_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql( log_in_account) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 选择上级部门 self.organize_management.choose_sup_org() # 填写新增部门名称 self.organize_management.input_add_org_name( add_org_info_exception['add_org_name']) # 填写联系方式 self.organize_management.input_add_org_tel( add_org_info_exception['add_org_tel']) # 点击保存按钮 self.organize_management.click_add_org_save() # 跳出最外层frame self.organize_management.switch_to_default_content() # 获取名称重复异常提示 text = self.organize_management.get_add_org_exception2() self.assertEqual(add_org_info_exception['exception_text'], text) # 切入外层frame self.organize_management.switch_to_1_frame() # 切入内层frame self.organize_management.switch_to_2_frame() # 关闭新增公司部门框 self.organize_management.click_add_org_close() # 跳出最外层frame self.organize_management.switch_to_default_content() # 从数据库查询验证新增失败 new_org_name = self.organize_management.get_add_org_by_sql( log_in_account) self.assertNotEqual(new_org_name, add_org_info_exception['add_org_name']) self.driver.wait(1) csv_file.close() # 退出登录 self.user_center.logout()
class TestCase05OrgManageEditOrgException(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() 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_edit_org_exception(self): # 通过csv测试修改公司部门功能异常情况 # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.test_user_login() # 获取当前登录账户 log_in_account = self.user_center.get_login_account() print(log_in_account) # 点击进入部门管理 self.organize_management.click_org_manage() # 查找test00000部门 search_key = '00000' self.organize_management.search_org(search_key) # 获取页面查找结果 search_org_name_01 = self.organize_management.get_search_result_one() # 查询数据库获取搜索结果 org_info_00 = self.organize_management.get_search_result_by_sql(log_in_account, search_key) org_name_00 = org_info_00[0] sup_org_name_00 = org_info_00[1] org_tel_00 = org_info_00[2] self.assertEqual(search_org_name_01, org_name_00) csv_file = self.user_center_read_csv.read_csv('edit_org_info_exception.csv') csv_data = csv.reader(csv_file) for row in csv_data: edit_org_info_exception = { "edit_org_name": row[0], "edit_org_tel": row[1], "exception_text": row[2], } # 点击修改 self.organize_management.click_edit_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 获取当前显示的部门名称是否与未修改前一致 current_org_name_01 = self.organize_management.get_current_org_name() self.assertEqual(search_org_name_01, current_org_name_01) # 获取显示的所属上级是否与未修改前一致 current_sup_org = self.organize_management.get_current_sup_org_name() self.assertEqual(sup_org_name_00, current_sup_org) # 获取显示的联系方式是否与未修改前一致 current_org_tel = self.organize_management.get_current_org_tel() self.assertEqual(org_tel_00, current_org_tel) # 修改部门名称 self.organize_management.edit_org_name(edit_org_info_exception['edit_org_name']) # 修改联系方式 self.organize_management.edit_org_tel(edit_org_info_exception['edit_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 修改(保存) self.organize_management.click_org_modify_button() # 获取异常提示语 exception_text = self.organize_management.get_edit_org_exception_text() self.assertEqual(edit_org_info_exception['exception_text'],exception_text) # 数据库查询是否修改失败 org_info = self.organize_management.get_search_result_by_sql(log_in_account, search_key) org_name = org_info[0] org_tel = org_info[2] self.assertNotEqual(edit_org_info_exception['edit_org_name'], org_name) self.assertNotEqual(edit_org_info_exception['edit_org_tel'], org_tel) # 跳出内层frame self.organize_management.switch_to_parent_content() # 关闭 self.organize_management.click_org_modify_close() csv_file.close() # 跳出外层frame self.organize_management.switch_to_default_content() # 退出登录 self.user_center.logout()
class TestCase01OrgManageAddOrg(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() 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_add_org(self): # 通过csv测试新增公司部门功能 csv_file = self.user_center_read_csv.read_csv('add_org_info.csv') csv_data = csv.reader(csv_file) for row in csv_data: add_org_info = { "account": row[0], "password": row[1], "add_org_name": row[2], "add_org_tel": row[3], } # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.user_login(add_org_info['account'], add_org_info['password']) # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql( add_org_info['account']) print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 点击进入部门管理 self.organize_management.click_org_manage() # 点击新增公司部门 self.organize_management.click_add_org() # 验证上级部门是否显示正确 sup_org_name = self.organize_management.get_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql( add_org_info['account']) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 选择上级部门 self.organize_management.choose_sup_org() # 填写新增部门名称 self.organize_management.input_add_org_name( add_org_info['add_org_name']) # 填写联系方式 self.organize_management.input_add_org_tel( add_org_info['add_org_tel']) # 点击取消 self.organize_management.click_add_org_dismiss() # 从数据库查询验证未新增成功 new_org_name_01 = self.organize_management.get_add_org_by_sql( add_org_info['account']) self.assertNotEqual(new_org_name_01, add_org_info['add_org_name']) self.driver.wait(1) # 点击新增公司部门 self.organize_management.click_add_org() # 验证上级部门是否显示正确 sup_org_name = self.organize_management.get_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql( add_org_info['account']) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 选择上级部门 self.organize_management.choose_sup_org() # 填写新增部门名称 self.organize_management.input_add_org_name( add_org_info['add_org_name']) # 填写联系方式 self.organize_management.input_add_org_tel( add_org_info['add_org_tel']) # 点击关闭按钮 self.organize_management.click_add_org_close() # 从数据库查询验证未新增成功 new_org_name_02 = self.organize_management.get_add_org_by_sql( add_org_info['account']) self.assertNotEqual(new_org_name_02, add_org_info['add_org_name']) self.driver.wait(1) # 点击新增公司部门 self.organize_management.click_add_org() # 验证上级部门是否显示正确 sup_org_name = self.organize_management.get_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql( add_org_info['account']) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 选择上级部门 self.organize_management.choose_sup_org() # 填写新增部门名称 self.organize_management.input_add_org_name( add_org_info['add_org_name']) # 填写联系方式 self.organize_management.input_add_org_tel( add_org_info['add_org_tel']) # 点击保存按钮 self.organize_management.click_add_org_save() # 跳出最外层frame self.organize_management.switch_to_default_content() # 从数据库查询验证新增成功 new_org_name_03 = self.organize_management.get_add_org_by_sql( add_org_info['account']) self.assertEqual(new_org_name_03, add_org_info['add_org_name']) self.driver.wait(1) # 退出登录 self.user_center.logout() csv_file.close()
class TestCase06UserCenterFeedback(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.user_center_read_csv = UserCenterReadCsv() 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_center_feedback(self): '''通过csv测试用户中心意见反馈功能''' data = ["部门管理", "设备", "贷款客户", "车辆监控中心", "统计报表", "设置"] csv_file = self.user_center_read_csv.read_csv('user_feedback_info.csv') csv_data = csv.reader(csv_file) for row in csv_data: user_feedback_info = { "account": row[0], "passwd": row[1], "type": row[2], "content": row[3], "linkman": row[4], "phone": row[5], } # 打开风控首页-登录页 self.base_page.open_page() # 输入用户信息进行登录 self.login_page.user_login(user_feedback_info["account"], user_feedback_info["passwd"]) self.driver.wait(1) # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql( user_feedback_info['account']) print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 验证模块 module = self.user_center.get_module_name() print(module) self.assertEqual(data, module, "用户账号登录,模块显示错误") self.driver.wait(10) # 进入意见反馈 self.user_center.click_feedback() # 提交反馈信息 self.user_center.choose_problem_type(user_feedback_info['type']) self.user_center.input_problem_content( user_feedback_info['content']) self.user_center.input_linkman(user_feedback_info['linkman']) self.user_center.input_phone(user_feedback_info['phone']) self.user_center.click_submit() # 获取提交反馈信息成功提示语 text = self.user_center.get_feedback_success_text() self.assertEqual('意见反馈成功', text) # 从数据库获取反馈信息验证是否提交成功 feedback_info = self.user_center.get_feedback_info_by_sql( user_feedback_info['account']) print(feedback_info) self.assertEqual(user_feedback_info['account'], feedback_info[0]) self.assertEqual(user_feedback_info['type'], feedback_info[1]) self.assertEqual(user_feedback_info['content'], feedback_info[2]) self.assertEqual(user_feedback_info['linkman'], feedback_info[3]) self.assertEqual(user_feedback_info['phone'], feedback_info[4]) # # 成功退出系统 sleep(2) self.user_center.logout() csv_file.close()
class TestCase06OrgManageViewOrg(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() 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_view_org(self): # 通过csv测试查看公司部门功能 # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.test_user_login() # 获取当前登录账户 log_in_account = self.user_center.get_login_account() print(log_in_account) # 点击进入部门管理 self.organize_management.click_org_manage() csv_file = self.user_center_read_csv.read_csv('view_org_info.csv') csv_data = csv.reader(csv_file) for row in csv_data: view_org_info = { "view_org_name": row[0], "view_org_tel": row[1], } # 点击查看公司部门 self.organize_management.click_view_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 验证所属上级是否显示正确 sup_org_name = self.organize_management.get_current_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_belong_to_superior_org_by_sql( log_in_account) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 编辑公司/部门名称 self.organize_management.edit_org_name( view_org_info['view_org_name']) # 编辑联系方式 self.organize_management.edit_org_tel( view_org_info['view_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 取消 self.organize_management.click_org_modify_dismiss() # 从数据库查询验证未修改成功 current_org_info_01 = self.organize_management.get_current_org_info_by_sql( log_in_account) edit_org_name_01 = current_org_info_01[0] edit_org_tel_01 = current_org_info_01[1] self.assertNotEqual(edit_org_name_01, view_org_info['view_org_name']) self.assertNotEqual(edit_org_tel_01, view_org_info['view_org_tel']) self.driver.wait(1) # 点击查看公司部门 self.organize_management.click_view_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 验证所属上级是否显示正确 sup_org_name = self.organize_management.get_current_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_belong_to_superior_org_by_sql( log_in_account) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 编辑公司/部门名称 self.organize_management.edit_org_name( view_org_info['view_org_name']) # 编辑联系方式 self.organize_management.edit_org_tel( view_org_info['view_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 关闭 self.organize_management.click_org_modify_close() # 从数据库查询验证未修改成功 current_org_info_02 = self.organize_management.get_current_org_info_by_sql( log_in_account) edit_org_name_02 = current_org_info_02[0] edit_org_tel_02 = current_org_info_02[1] self.assertNotEqual(edit_org_name_02, view_org_info['view_org_name']) self.assertNotEqual(edit_org_tel_02, view_org_info['view_org_tel']) self.driver.wait(1) # 点击查看公司部门 self.organize_management.click_view_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 验证所属上级是否显示正确 sup_org_name = self.organize_management.get_current_sup_org_name() # 数据库查询当前登录账户的上级部门 sup_org_name_by_aql = self.organize_management.get_belong_to_superior_org_by_sql( log_in_account) self.assertEqual(sup_org_name, sup_org_name_by_aql) # 编辑公司/部门名称 self.organize_management.edit_org_name( view_org_info['view_org_name']) # 编辑联系方式 self.organize_management.edit_org_tel( view_org_info['view_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 修改(保存) self.organize_management.click_org_modify_button() # 从数据库查询验证修改成功 current_org_info_03 = self.organize_management.get_current_org_info_by_sql( log_in_account) edit_org_name_03 = current_org_info_03[0] edit_org_tel_03 = current_org_info_03[1] self.assertEqual(edit_org_name_03, view_org_info['view_org_name']) self.assertEqual(edit_org_tel_03, view_org_info['view_org_tel']) self.driver.wait(1) # 跳出外层frame self.organize_management.switch_to_default_content() csv_file.close() # 退出登录 self.user_center.logout()
class TestCase08OrgManageDeleteOrg(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() 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_delete_org(self): # 通过csv测试删除公司部门功能 # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.test_user_login() # 获取当前登录账户 log_in_account = self.user_center.get_login_account() print(log_in_account) # 点击进入部门管理 self.organize_management.click_org_manage() csv_file = self.user_center_read_csv.read_csv('delete_org.csv') csv_data = csv.reader(csv_file) for row in csv_data: delete_org = { "org_name": row[0], } # 按名称查找部门 self.organize_management.search_org(delete_org['org_name']) # 点击删除 self.organize_management.click_delete_org() # 跳出frame self.organize_management.switch_to_default_content() # 取消 self.organize_management.delete_org_dismiss() # 切入frame self.organize_management.switch_to_1_frame() # 点击删除 self.organize_management.click_delete_org() # 跳出frame self.organize_management.switch_to_default_content() # 关闭 self.organize_management.delete_org_close() # 切入frame self.organize_management.switch_to_1_frame() # 点击删除 self.organize_management.click_delete_org() # 跳出frame self.organize_management.switch_to_default_content() # 确认 self.organize_management.delete_org_accept() # 数据库查找验证部门是否删除成功 # 数据库查找部门 org_name_after_delete = self.organize_management.get_search_result_orgname_by_sql( log_in_account, '') self.assertNotIn(delete_org['org_name'], org_name_after_delete) # 切入frame self.organize_management.switch_to_1_frame() csv_file.close() # 跳出frame self.organize_management.switch_to_default_content() # 退出登录 self.user_center.logout()
class TestCase01UserCenterModifyInfo(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.user_center_read_csv = UserCenterReadCsv() 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_center_modify_info(self): # 通过csv测试修改资料功能 csv_file = self.user_center_read_csv.read_csv( 'user_to_modify_info.csv') csv_data = csv.reader(csv_file) for row in csv_data: user_to_modify_info = { "username": row[0], "phone": row[1], } # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.test_user_login() # 获取当前登录账号 log_in_account = self.user_center.get_login_account() print(log_in_account) # 从数据库获取登录账号的客户名称、电话 account_info = self.user_center.get_account_info_by_sql( log_in_account) print(account_info) # 获取修改资料里面的信息 user_info = self.user_center.get_user_info() # 断言 self.assertEqual(log_in_account, user_info['login_account']) self.assertEqual(account_info[1], user_info['name']) self.assertEqual(account_info[2], user_info['tel']) # 编辑客户名称、电话后点击取消 self.user_center.edit_user_info_not_save( user_to_modify_info['username'], user_to_modify_info['phone']) # 从数据库获取登录账号的客户名称、电话 account_info1 = self.user_center.get_account_info_by_sql( log_in_account) print(account_info1) self.assertEqual(account_info, account_info1) # 获取修改资料里面的信息 user_info1 = self.user_center.get_user_info() # 断言 self.assertEqual(log_in_account, user_info1['login_account']) self.assertEqual(account_info1[1], user_info1['name']) self.assertEqual(account_info1[2], user_info1['tel']) # 编辑客户名称、电话后点击关闭按钮 self.user_center.edit_user_info_close( user_to_modify_info['username'], user_to_modify_info['phone']) # 从数据库获取登录账号的客户名称、电话 account_info2 = self.user_center.get_account_info_by_sql( log_in_account) print(account_info2) self.assertEqual(account_info, account_info2) # 获取修改资料里面的信息 user_info2 = self.user_center.get_user_info() # 断言 self.assertEqual(log_in_account, user_info2['login_account']) self.assertEqual(account_info2[1], user_info2['name']) self.assertEqual(account_info2[2], user_info2['tel']) # 编辑客户名称、电话后保存 print(user_to_modify_info['username'], user_to_modify_info['phone']) self.user_center.edit_user_info_exception( user_to_modify_info['username'], user_to_modify_info['phone']) # 从数据库获取登录账号的客户名称、电话 account_info3 = self.user_center.get_account_info_by_sql( log_in_account) print(account_info3) web_data = [ log_in_account, user_to_modify_info['username'], user_to_modify_info['phone'] ] self.assertEqual(account_info3, web_data) # 获取修改资料里面的信息 user_info3 = self.user_center.get_user_info() # 断言 self.assertEqual(log_in_account, user_info3['login_account']) self.assertEqual(account_info3[1], user_info3['name']) self.assertEqual(account_info3[2], user_info3['tel']) # 退出登录 self.user_center.logout() csv_file.close()
class TestCase04OrgManageEditOrg(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.organize_management = OrganizeManagement(self.driver, self.base_url) self.log_in_page_read_csv = LogInPageReadCsv() self.user_center_read_csv = UserCenterReadCsv() self.organize_management_read_csv = OrganizeManagementReadCsv() 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_edit_org(self): # 通过csv测试修改公司部门功能 csv_file = self.user_center_read_csv.read_csv('edit_org_info.csv') csv_data = csv.reader(csv_file) for row in csv_data: edit_org_info = { "account": row[0], "password": row[1], "search_key": row[2], "edit_org_name": row[3], "choose_sup_org": row[4], "edit_org_tel": row[5], } # 打开风控首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.login_page.user_login(edit_org_info['account'], edit_org_info['password']) # 判断登录成功后招呼栏的用户名是否正确 username = self.user_center.get_username() # 从数据库获取登录账号的用户名 account_info = self.user_center.get_account_info_by_sql( edit_org_info['account']) print(account_info) account_name = account_info[1] self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误') # 点击进入部门管理 self.organize_management.click_org_manage() # 查找test00000部门 self.organize_management.search_org(edit_org_info['search_key']) # 获取页面查找结果 search_org_name_01 = self.organize_management.get_search_result_one( ) # 查询数据库获取搜索结果 org_info_00 = self.organize_management.get_search_result_by_sql( edit_org_info['account'], edit_org_info['search_key']) org_name_00 = org_info_00[0] sup_org_name_00 = org_info_00[1] org_tel_00 = org_info_00[2] self.assertEqual(search_org_name_01, org_name_00) # 点击修改 self.organize_management.click_edit_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 获取当前显示的部门名称是否与未修改前一致 current_org_name_01 = self.organize_management.get_current_org_name( ) self.assertEqual(search_org_name_01, current_org_name_01) # 获取显示的所属上级是否与未修改前一致 current_sup_org = self.organize_management.get_current_sup_org_name( ) self.assertEqual(sup_org_name_00, current_sup_org) # 获取显示的联系方式是否与未修改前一致 current_org_tel = self.organize_management.get_current_org_tel() self.assertEqual(org_tel_00, current_org_tel) # 修改部门名称 self.organize_management.edit_org_name( edit_org_info['edit_org_name']) # 修改所属上级 self.organize_management.edit_sup_org( edit_org_info['choose_sup_org']) # 修改联系方式 self.organize_management.edit_org_tel( edit_org_info['edit_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 取消 self.organize_management.click_org_modify_dismiss() # 数据库查询是否修改失败 org_info_01 = self.organize_management.get_search_result_by_sql( edit_org_info['account'], edit_org_info['search_key']) org_name_01 = org_info_01[0] sup_org_name_01 = org_info_01[1] org_tel_01 = org_info_01[2] self.assertEqual(org_name_00, org_name_01) self.assertEqual(sup_org_name_00, sup_org_name_01) self.assertEqual(org_tel_00, org_tel_01) # 点击修改 self.organize_management.click_edit_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 修改部门名称 self.organize_management.edit_org_name( edit_org_info['edit_org_name']) # 修改所属上级 self.organize_management.edit_sup_org( edit_org_info['choose_sup_org']) # 修改联系方式 self.organize_management.edit_org_tel( edit_org_info['edit_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 关闭 self.organize_management.click_org_modify_close() # 数据库查询是否修改失败 org_info_02 = self.organize_management.get_search_result_by_sql( edit_org_info['account'], edit_org_info['search_key']) org_name_02 = org_info_02[0] sup_org_name_02 = org_info_02[1] org_tel_02 = org_info_02[2] self.assertEqual(org_name_00, org_name_02) self.assertEqual(sup_org_name_00, sup_org_name_02) self.assertEqual(org_tel_00, org_tel_02) # 点击修改 self.organize_management.click_edit_org() # 切入内层frame self.organize_management.switch_to_2_frame() # 修改部门名称 self.organize_management.edit_org_name( edit_org_info['edit_org_name']) # 修改所属上级 self.organize_management.edit_sup_org( edit_org_info['choose_sup_org']) # 修改联系方式 self.organize_management.edit_org_tel( edit_org_info['edit_org_tel']) # 跳出内层frame self.organize_management.switch_to_parent_content() # 修改(保存) self.organize_management.click_org_modify_button() # 数据库查询是否修改成功 org_info_03 = self.organize_management.get_search_result_by_sql( edit_org_info['account'], edit_org_info['search_key']) org_name_03 = org_info_03[0] sup_org_name_03 = org_info_03[1] org_tel_03 = org_info_03[2] self.assertEqual(edit_org_info['edit_org_name'], org_name_03) self.assertEqual(edit_org_info['choose_sup_org'], sup_org_name_03) self.assertEqual(edit_org_info['edit_org_tel'], org_tel_03) # 跳出外层frame self.organize_management.switch_to_default_content() # 退出登录 self.user_center.logout() csv_file.close()