def setUp(self): self.driver = AutomateDriverServer(choose='CHROME') 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.account_center_page_details = AccountCenterDetailsPage( self.driver, self.base_url) self.account_center_page_refill_card = AccountCenterRefillCardPage( self.driver, self.base_url) self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.connect_sql = ConnectSql() self.search_sql = SearchSql() self.assert_text = AssertText() self.driver.set_window_max() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1)
def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1)
class TestCase119LoginWithRememberMe(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_base = LogInBaseServer(self.driver, self.base_url) self.driver.set_window_max() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_login_with_remember_me(self): '''测试登录时勾选记住我''' # 打开途强在线首页-登录页 self.base_page.open_page() self.log_in_base.log_in() # 点账户中心 self.account_center_page_navi_bar.click_account_center_button() # 判断登录成功后跳转页面是否正确 actual_url = self.driver.get_current_url() expect_url = self.base_url + "/customer/toAccountCenter" self.assertEqual(expect_url, actual_url, "登录成功后页面跳转错误") sleep(1) # 成功退出系统 self.account_center_page_navi_bar.usr_logout() # 判断是否成功退出系统 self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "退出系统失败") # 验证退出系统后“记住我”是否是已勾选状态 box_status = self.login_page.check_remember_me() self.assertEqual(True, box_status, '记住密码失败')
class TestCase57CustManageCheckAccount(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.connect_sql = ConnectSql() self.cust_manage_page_read_csv = CustManagePageReadCsv() self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_cust_manage_check_account(self): '''测试客户管理-新增用户''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() csv_file = self.cust_manage_page_read_csv.read_csv( 'check_account_data.csv') csv_data = csv.reader(csv_file) for row in csv_data: data = {'account': row[0]} self.cust_manage_basic_info_and_add_cust_page.add_data_to_search_account( data) connect = self.connect_sql.connect_tuqiang_sql() cursor = connect.cursor() get_account_sql = "SELECT o.type,o.phone,o.nickName from user_info o WHERE o.account = '" + data[ 'account'] + "';" cursor.execute(get_account_sql) get_account_user_info = cursor.fetchall() current_user_info = [] for range1 in get_account_user_info: for range2 in range1: current_user_info.append(range2) print(current_user_info) type = self.assert_text.log_in_page_account_type( current_user_info[0]) # 断言客户类型 account_type = self.cust_manage_basic_info_and_add_cust_page.get_account_type( ) self.assertEqual(type, account_type) # 断言账号 account = self.cust_manage_basic_info_and_add_cust_page.get_account( ) self.assertEqual(data['account'], account) # 断言电话 account_phone = self.cust_manage_basic_info_and_add_cust_page.get_account_phone( ) if current_user_info[1] == None: self.assertEqual("", account_phone, "手机号不一致") else: self.assertEqual(current_user_info[1], account_phone) # 断言昵称 account_name = self.cust_manage_basic_info_and_add_cust_page.get_account_name( ) if current_user_info[2] == None: self.assertEqual("", account_name, "昵称不一致") else: self.assertEqual(current_user_info[2], account_name) # 点击监控用户 current_window = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.click_monitoring_account_button( ) all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_window: self.driver.switch_to_window(handle) expect_url = self.base_url + '/index' self.assertEqual(expect_url, self.driver.get_current_url()) self.driver.close_current_page() sleep(2) self.driver.switch_to_window(current_window) # 点击编辑用户 style_value = self.cust_manage_basic_info_and_add_cust_page.edit_button_style_value( ) if style_value == 'display: inline;': self.cust_manage_basic_info_and_add_cust_page.click_edit_account_button( ) # 点击关闭 self.cust_manage_basic_info_and_add_cust_page.click_close_edit_accunt_button( ) # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_button( ) # 查询用户上一级信息 connect_02 = self.connect_sql.connect_tuqiang_sql() cursor_02 = connect_02.cursor() get_id_sql = "SELECT o.parentId from user_info o WHERE o.account = '" + account + "';" cursor_02.execute(get_id_sql) get_id_info = cursor_02.fetchall() current_user = [] for range1 in get_id_info: for range2 in range1: current_user.append(range2) print(current_user) get_up_account_info_sql = "SELECT o.nickName FROM user_info o WHERE o.userId = '" + current_user[ 0] + "';" cursor_02.execute(get_up_account_info_sql) get_up_user_info = cursor_02.fetchall() up_user_info = [] for range1 in get_up_user_info: for range2 in range1: up_user_info.append(range2) account_name = up_user_info[0] get_web_account_name = self.cust_manage_basic_info_and_add_cust_page.get_account_name_after_click_edit( ) self.assertEqual(account_name, get_web_account_name, '用户上级显示错误!') self.cust_manage_basic_info_and_add_cust_page.click_close_edit_accunt_button( ) # 断言账号类型 cursor_02.close() connect_02.close() cursor.close() connect.close() csv_file.close()
class TestCase402CustomerManagementLowerUserSearch(unittest.TestCase): # 测试客户管理 搜索 客户 def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.account_center_page_details = AccountCenterDetailsPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.search_sql = SearchSql() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.close_window() self.driver.quit_browser() def test_customer_management_lower_user_search(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 点击账户中心 # self.account_center_page_navi_bar.click_account_center_button() # current_account = self.log_in_base.get_log_in_account() # 进入客户管理页面 current_handle = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle) csv_file = self.cust_manage_page_read_csv.read_csv('acc_search.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue search_data = { 'account': row[0], "account_type": row[1], "info": row[2] } print(search_data) sleep(1) self.cust_manage_lower_account_page.add_data_to_search_account( search_data) connect = self.connect_sql.connect_tuqiang_sql() # 创建数据库游标 cur = connect.cursor() # 执行sql脚本查询当前登录账号的userId,fullParent get_id_sql = "select o.account,o.userId,o.fullParentId from user_info o where o.account = '" + search_data[ 'account'] + "' ;" cur.execute(get_id_sql) # 读取数据 user_relation = cur.fetchall() # 遍历数据 for row in user_relation: user_relation_id = { "account": row[0], "userId": row[1], "fullParent": row[2] } # 执行sql脚本,根据当前登录账号的userId,fullParent查询出当前账户的所有下级账户 get_lower_account_sql = "select userId from user_info where fullParentId = " + \ "'" + user_relation_id["fullParent"] + user_relation_id[ "userId"] + ",'" + ";" cur.execute(get_lower_account_sql) # 读取数据 lower_account = cur.fetchall() print(lower_account) lower_account_list = [] for range1 in lower_account: for range2 in range1: lower_account_list.append(range2) lower_account_tuple = tuple(lower_account_list) print(lower_account_tuple) get_total_sql = self.search_sql.search_account_sql( lower_account_tuple, search_data) print(get_total_sql) cur.execute(get_total_sql) # 读取数据 total_data = cur.fetchall() # 从数据tuple中获取最终查询记录统计条数 total_list = [] for range1 in total_data: for range2 in range1: total_list.append(range2) total = len(total_list) print('本次查询数据库的条数为:%s' % total) web_total = self.cust_manage_lower_account_page.get_account_number( ) print('本次查询页面的条数是:%s' % web_total) self.assertEqual(total, web_total) cur.close() connect.close() csv_file.close()
class TestCase19AccountCenterOverviewAlarm(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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_details = AccountCenterDetailsPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_account_center_overview_set_up_landmark(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录账号 self.log_in_base.log_in() self.account_center_page_navi_bar.click_account_center_button() sleep(2) account_center_handle = self.driver.get_current_window_handle() # 点击告警 self.account_center_page_details.account_center_iframe() self.account_center_page_details.account_overview('告警') self.driver.default_frame() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != account_center_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.driver.get_current_url() actual_url = self.base_url + '/deviceReport/statisticalReport?modularId=alarmDdetails' self.assertEqual(expect_url, actual_url, '点击告警后,实际的url和期望的不一样!') sleep(2) actual_text = self.account_center_page_details.get_actual_text_after_click_alarms( ) self.assertEqual( self.assert_text.account_center_page_alarm_details_text(), actual_text, '点击告警后,页面没有跳转到告警总览页面上') # 查看控制台告警设置能否打开 self.account_center_page_navi_bar.click_alarm_button_in_console( ) # 断言 get_text = self.account_center_page_navi_bar.get_text_after_click_alarm_button( ) self.assertEqual( self.assert_text.account_center_page_alarm_manager_text(), get_text) self.account_center_page_navi_bar.close_alarm_in_console() self.driver.close_current_page() # 回到账户中心窗口 self.driver.switch_to_window(account_center_handle) self.driver.wait()
class TestCase131MarkOperation(unittest.TestCase): """ web_autotest账号,标注点页面操作 """ # author:邓肖斌 def setUp(self): self.driver = AutomateDriverServer(choose='chrome') self.base_url = self.driver.base_url self.base_page = BasePageServer(self.driver, self.base_url) self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.safe_area_page = SafeAreaPage(self.driver, self.base_url) self.base_page.open_page() self.base_page.click_chinese_button() self.driver.set_window_max() self.log_in_base.log_in() self.safe_area_page.click_control_after_click_safe_area() self.safe_area_page_read_csv = SafeAreaPageReadCsv() self.assert_text = AssertText() self.connect_sql = ConnectSql() self.search_sql = SafeAreaSearchSql() def tearDown(self): self.driver.quit_browser() def test_case_mark_operation(self): # 断言url expect_url = self.base_url + "/safearea/geozonemap?flag=0" self.assertEqual(expect_url, self.driver.get_current_url()) self.safe_area_page.click_mark_button() sleep(2) # 全选 self.safe_area_page.click_all_select_button_with_mark() # 点击删除 self.safe_area_page.click_detele_button_with_mark() # 点击取消 self.safe_area_page.click_cancel_detele_button() # 点击删除 self.safe_area_page.click_detele_button_with_mark() # 点击关闭 self.safe_area_page.click_close_detele_button() # 点击新建按钮 self.safe_area_page.click_create_mark_point() text = self.safe_area_page.get_text_after_create_map() self.assertEqual(self.assert_text.safe_area_page_map_text(), text) # 获取第一个地标的名称 mark_name = self.safe_area_page.get_first_mark_name_text() # 点击列表的编辑 self.safe_area_page.click_edit_button_in_list() # 点击保存 self.safe_area_page.click_ensure_edit_in_list('名称1', '描述1') # 获取保存之后的地标名称 mark_name_after_save = self.safe_area_page.get_first_mark_name_text() # 断言1:网页上名称的变化 self.assertNotEqual(mark_name, mark_name_after_save) # 断言2:用修改之前的名称在数据库搜索 # 创建数据库连接 connect = self.connect_sql.connect_tuqiang_sql() # 创建游标 cursor = connect.cursor() get_total_count_sql = self.search_sql.search_sql_in_test_case_131( '%s') % mark_name print(get_total_count_sql) cursor.execute(get_total_count_sql) current_total = cursor.fetchall() total_list1 = [] for range1 in current_total: for range2 in range1: total_list1.append(range2) total = len(total_list1) self.assertEqual(0, total) # 断言3:用修改之后的名称在数据库搜索 get_total_count_sql = self.search_sql.search_sql_in_test_case_131( '%s') % mark_name_after_save print(get_total_count_sql) cursor.execute(get_total_count_sql) current_total = cursor.fetchall() total_list2 = [] for range1 in current_total: for range2 in range1: total_list2.append(range2) total = len(total_list2) self.assertEqual(1, total) self.assertEqual('描述1', total_list2[0]) # 点击列表的编辑 self.safe_area_page.click_edit_button_in_list() # 点击保存 self.safe_area_page.click_ensure_edit_in_list('名称', '描述') # 点击列表的编辑 self.safe_area_page.click_edit_button_in_list() # 点击取消 self.safe_area_page.click_cancel_edit_in_list() # 点击列表中的删除 self.safe_area_page.click_delete_button_in_list() self.safe_area_page.click_cancel_detele_button() # 点击关闭 self.safe_area_page.click_delete_button_in_list() self.safe_area_page.click_close_detele_button()
class TestCase67CustManageCustTransferCustSearch(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.connect_sql = ConnectSql() self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_cust_manage_transfer_cust_search(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() sleep(2) # 点击编辑用户 self.cust_manage_basic_info_and_add_cust_page.click_transfer_customer() self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() self.cust_manage_basic_info_and_add_cust_page.click_transfer_customer() # 循环点击五次 for n in range(5): self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.driver.click_element('x,//*[@id="treeDemo2_%s_span"]' % str(n + 3)) sleep(2) self.driver.default_frame() # 搜索 # 1 搜索无数据的内容 """ self.cust_manage_basic_info_and_add_cust_page.search_cust('无数据') get_text = self.cust_manage_basic_info_and_add_cust_page.get_search_no_data_text() self.assertIn(self.assert_text.account_center_page_no_data_text(), get_text) """ # 2搜索 seatch_data = ["无", "test", "yonghu222啦啦啦", "休息休息12", "#@@@ %"] for user in range(len(seatch_data)): search_result = self.cust_manage_basic_info_and_add_cust_page.transfer_import_account_search( seatch_data[user]) if type(search_result) is str: self.assertIn( self.assert_text.account_center_page_no_data_text(), search_result, "搜索结果为暂无数据时,提示不一致") else: for subscript in range(len(search_result)): text = search_result[subscript].split("(")[0] self.assertIn(seatch_data[user], text, "搜索结果不一致")
class TestCase122LoginEnterThirdWebsite(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.driver.set_window_max() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_third_website(self): '''测试登录页底部第三方链接''' websites = ["可信网站", "网络警察", "公共信息网络安全监察", "不良信息举报中心", "工商网监"] # 打开途强在线首页-登录页 self.base_page.open_page() # 获取网站个数 url = self.base_url count = self.login_page.get_login_page_website_count(url) # 获取当前窗口句柄 tuqiang_handle = self.driver.get_current_window_handle() try: # 点击底部第三方链接-可信网站 expect_url_00 = "https://ss.knet.cn/verifyseal.dll?sn=e16112844030065399aooh000000&ct=df&a=1&pa=0.5438364866062911" self.login_page.enter_third_party_website(websites[0], count) self.driver.wait() # 获取当前所有窗口句柄 all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != tuqiang_handle: self.driver.switch_to_window(handle) self.driver.wait(1) web_url_00 = self.driver.get_current_url() # 判断当前第三方链接跳转是否正确 self.assertEqual(expect_url_00, web_url_00, "当前第三方链接跳转错误") self.driver.close_window() self.driver.switch_to_window(tuqiang_handle) print("有可信网站") except: print("没有可信网站############") # 点击底部第三方链接-01 expect_url_01 = "http://www.cyberpolice.cn/wfjb/" self.login_page.enter_third_party_website(websites[1], count) self.driver.wait() # 获取当前所有窗口句柄 all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != tuqiang_handle: self.driver.switch_to_window(handle) self.driver.wait(1) web_url_01 = self.driver.get_current_url() # 判断当前第三方链接跳转是否正确 self.assertEqual(expect_url_01, web_url_01, "当前第三方链接跳转错误") self.driver.wait() self.driver.close_window() self.driver.switch_to_window(tuqiang_handle) # 点击底部第三方链接-02 self.driver.switch_to_window(tuqiang_handle) self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "回到原窗口失败") expect_url_02 = "http://www.500wan.com/pages/info/about/wangan/index.htm" self.login_page.enter_third_party_website(websites[2], count) self.driver.wait() # 获取当前所有窗口句柄 all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != tuqiang_handle: self.driver.switch_to_window(handle) self.driver.wait(1) web_url_02 = self.driver.get_current_url() # 判断当前第三方链接跳转是否正确 self.assertEqual(expect_url_02, web_url_02, "当前第三方链接跳转错误") self.driver.wait() self.driver.close_window() self.driver.switch_to_window(tuqiang_handle) # 点击底部第三方链接-03 self.driver.switch_to_window(tuqiang_handle) self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "回到原窗口失败") expect_url_03 = "http://www.12377.cn/" self.login_page.enter_third_party_website(websites[3], count) self.driver.wait() # 获取当前所有窗口句柄 all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != tuqiang_handle: self.driver.switch_to_window(handle) self.driver.wait(1) web_url_03 = self.driver.get_current_url() # 判断当前第三方链接跳转是否正确 self.assertEqual(expect_url_03, web_url_03, "当前第三方链接跳转错误") self.driver.wait() self.driver.close_window() self.driver.switch_to_window(tuqiang_handle) self.driver.switch_to_window(tuqiang_handle) self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "回到原窗口失败") expect_url_04 = "http://szcert.ebs.org.cn/2a950f00-00fb-495c-8e30-5a04100f9b17" self.login_page.enter_third_party_website(websites[4], count) self.driver.wait() # 获取当前所有窗口句柄 all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != tuqiang_handle: self.driver.switch_to_window(handle) self.driver.wait(1) web_url_04 = self.driver.get_current_url() # 判断当前第三方链接跳转是否正确 self.assertEqual(expect_url_04, web_url_04, "当前第三方链接跳转错误") self.driver.wait() self.driver.close_window() self.driver.switch_to_window(tuqiang_handle) self.driver.switch_to_window(tuqiang_handle) self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "回到原窗口失败")
class TestCase405CustomerManagementAddUserCommandLimit(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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage(self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.assert_text = AssertText() self.assert_text2 = AssertText2() self.driver.set_window_max() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.close_window() self.driver.quit_browser() def test_add_user_command_limit_verify(self): '''测试客户管理-指令权限验证''' self.base_page.open_page() csv_file = self.cust_manage_page_read_csv.read_csv('add_user_command_limit_data.csv') csv_data = csv.reader(csv_file) for row in csv_data: info = { "keyword": row[0], "type": row[1], "name": row[2], "account": row[3], "passwd": row[4], "phone": row[5], "email": row[6], "conn": row[7], "com": row[8], "command": row[9], "working_mode": row[10] } # 登录 self.log_in_base.log_in() # 进入客户管理页面 current_handle = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() sleep(1) self.base_page.change_windows_handle(current_handle) self.cust_manage_basic_info_and_add_cust_page.add_acc() self.cust_manage_basic_info_and_add_cust_page.close_add_account() self.cust_manage_basic_info_and_add_cust_page.add_acc() self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.add_acc_input_info_edit(info["name"], info["account"], info["passwd"], info["phone"], info["email"], info["conn"], info["com"]) # 是或否批量下发指令 和批量下发工作模式 command_status = self.cust_manage_basic_info_and_add_cust_page.setting_command_permissions(info["command"]) working_mode_status = self.cust_manage_basic_info_and_add_cust_page.setting_working_mode_permissions( info["working_mode"]) self.assertEqual(info["command"], str(command_status), "勾选状态与期望不一致") self.assertEqual(info["working_mode"], str(working_mode_status), "勾选状态与期望不一致") self.driver.default_frame() sleep(2) self.cust_manage_basic_info_and_add_cust_page.acc_add_save() sleep(1) # 退出登录 self.account_center_page_navi_bar.usr_logout() self.log_in_base.log_in_with_csv(info["account"], info["passwd"]) hello_usr = self.account_center_page_navi_bar.usr_info_account() self.assertIn(info["account"], hello_usr, "登录成功后招呼栏账户名显示错误") sleep(1) # 进入设备管理/指令管理页面,获取功能按钮 current_handle_02 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.click_dev_management_button() self.base_page.change_windows_handle(current_handle_02) facility_manage_data = self.cust_manage_basic_info_and_add_cust_page.get_facility_manage_page_function_button() sleep(3) # command_manage_data = self.cust_manage_basic_info_and_add_cust_page.get_command_page_module() # 获取中文,依次是:选中发送指令、本次查询全部发送指令、选中设置工作模式、本次查询全部设置工作模式 # 工作模式模板管理, 下发工作模式任务管理, 下发工作模式管理, 下发指令任务管理, 下发指令管理 send_command = self.assert_text2.dev_manage_select_send_command() all_send_command = self.assert_text2.dev_manage_select_all_send_command() working_mode = self.assert_text2.dev_manage_setting_working_mode() all_working_mode = self.assert_text2.dev_manage_setting_all_working_mode() template_manage = self.assert_text.command_manager_page_work_type_template_management() working_mode_task_manage = self.assert_text2.comm_manage_send_working_mode_task_manage() working_mode_manage = self.assert_text2.comm_manage_send_working_mode_manage() task_manage = self.assert_text2.comm_manage_command_task_manage() comm_manager = self.assert_text.command_manager_page_issued_command_manager() command_list = [] working_mode_list = [] # 循环设备管理页面的数据 for b in facility_manage_data: # 选中发送指令 和 本次查询全部发送指令 if send_command in b or all_send_command in b: command_list.append(b) # 选中设置工作模式 和 本次查询全部设置工作模式 elif working_mode in b or all_working_mode in b: working_mode_list.append(b) # 循环指令管理页面的数据 '''for c in command_manage_data: # 下发指令任务管理 和 下发指令管理 if task_manage in c or comm_manager in c: command_list.append(c) # 工作模式模板管理, 下发工作模式任务管理, 下发工作模式管理 elif template_manage in c or working_mode_task_manage in c or working_mode_manage in c: working_mode_list.append(c)''' print("指令", command_list) print("工作模式", working_mode_list) # 验证设备、指令管理页面功能按钮 if command_status == True and working_mode_status == True: # 指令(设备页+指令管理页) self.assertEqual(send_command, command_list[0]) self.assertEqual(all_send_command, command_list[1]) self.assertEqual(task_manage, command_list[2]) self.assertEqual(comm_manager, command_list[3]) # 工作模式(设备页+指令管理页) self.assertEqual(working_mode, working_mode_list[0]) self.assertEqual(all_working_mode, working_mode_list[1]) self.assertEqual(template_manage, working_mode_list[2]) self.assertEqual(working_mode_task_manage, working_mode_list[3]) self.assertEqual(working_mode_manage, working_mode_list[4]) elif command_status == False and working_mode_status == False: # self.assertEqual(comm_manager, command_list[0]) self.assertEqual(0, len(working_mode_list)) elif command_status == True and working_mode_status == False: self.assertEqual(send_command, command_list[0]) self.assertEqual(all_send_command, command_list[1]) self.assertEqual(task_manage, command_list[2]) self.assertEqual(comm_manager, command_list[3]) self.assertEqual(0, len(working_mode_list)) elif command_status == False and working_mode_status == True: self.assertEqual(comm_manager, command_list[0]) self.assertEqual(working_mode, working_mode_list[0]) self.assertEqual(all_working_mode, working_mode_list[1]) self.assertEqual(template_manage, working_mode_list[2]) self.assertEqual(working_mode_task_manage, working_mode_list[3]) self.assertEqual(working_mode_manage, working_mode_list[4]) sleep(1) self.account_center_page_navi_bar.usr_logout() self.log_in_base.log_in() current_handle_01 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle_01) # 搜索新增客户 self.cust_manage_lower_account_page.input_search_info(info["account"]) # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 删除该新增客户 self.cust_manage_lower_account_page.delete_acc() self.cust_manage_lower_account_page.delete_acc_ensure() # 获取删除操作状态 del_status = self.cust_manage_lower_account_page.get_del_status() self.assertIn(self.assert_text.account_center_page_operation_done(), del_status, "操作失败") # 退出登录 sleep(1) self.account_center_page_navi_bar.usr_logout() csv_file.close()
class TestCase117LoginSuccessWithOrdinaryUser(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_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_ordinary_user_login_by_csv(self): '''通过csv测试普通用户账户成功登录和成功退出功能''' data = ["首页", "设备管理", "操控台", "统计报表", "安全区域", "设备分布"] csv_file = self.log_in_page_read_csv.read_csv( 'login_with_ordinary_user.csv') csv_data = csv.reader(csv_file) for row in csv_data: user_to_login = {"account": row[0], "passwd": row[1]} # 打开途强在线首页-登录页 self.base_page.open_page() # 输入用户信息进行登录 self.login_page.user_login(user_to_login["account"], user_to_login["passwd"]) self.driver.wait(1) # 点首页 self.login_page.click_home_page() # 判断登录成功后跳转页面是否正确 actual_url = self.driver.get_current_url() expect_url = self.base_url + "/nomalUserCenter" self.assertEqual(expect_url, actual_url, "登录成功后页面跳转错误") # 判断登录成功后招呼栏的用户名是否正确 hello_usr = self.account_center_page_navi_bar.hello_user_account() expect_usr = user_to_login["account"] self.assertIn(expect_usr, hello_usr, "登录成功后招呼栏账户名显示错误") # 验证模块 '''module = self.account_center_page_navi_bar.get_page_module() for m in range(len(module)): self.assertIn(data[m], module[m], "用户账号登录,模块显示错误")''' connect = self.connect_sql.connect_tuqiang_sql() cursor = connect.cursor() get_account_user_info_sql = "SELECT o.parentId from user_info o WHERE o.account = '" + \ user_to_login['account'] + "'" cursor.execute(get_account_user_info_sql) get_account_user_info = cursor.fetchall() current_user_info = [] for range1 in get_account_user_info: for range2 in range1: current_user_info.append(range2) print(current_user_info) # get_up_account_info_sql = "SELECT o.account,o.nickName,o.phone FROM user_info o WHERE o.userId = '" + \ # current_user_info[0] + "';" get_up_account_info_sql = "SELECT o.account,o.contact,o.phone FROM user_info o WHERE o.userId = '" + \ current_user_info[0] + "';" cursor.execute(get_up_account_info_sql) get_up_user_info = cursor.fetchall() up_user_info = [] for range1 in get_up_user_info: for range2 in range1: up_user_info.append(range2) print(up_user_info) usr_service_provider = self.account_center_page_navi_bar.ordinary_usr_service_provider( ) expect_usr_service_provider = up_user_info[0] self.assertIn(expect_usr_service_provider, usr_service_provider, "服务商显示错误") if up_user_info[1] != '': service_provider_connect = self.account_center_page_navi_bar.ordinary_usr_service_provider_connect( ) expect_service_provider_connect = up_user_info[1] self.assertIn(expect_service_provider_connect, service_provider_connect, "联系人显示错误") service_provider_phone = self.account_center_page_navi_bar.ordinary_usr_service_provider_phone( ) expect_service_provider_phone = up_user_info[2] self.assertIn(expect_service_provider_phone, service_provider_phone, "电话显示错误") # 成功退出系统 sleep(2) self.account_center_page_navi_bar.usr_log_out() # 判断是否成功退出到登录页 self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "退出系统失败") # 验证退出系统后“记住我”是否是未勾选状态 box_status = self.login_page.check_remember_me() self.assertEqual(False, box_status, '记住密码为勾选状态!') csv_file.close()
class TestCase40AccountCenterOperLoginLog(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.help_page = HelpPage(self.driver, self.base_url) self.account_center_page_operation_log = AccountCenterOperationLogPage(self.driver, self.base_url) self.help_page_sql = HelpPageSql() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.connect_sql = ConnectSql() self.log_in_base = LogInBaseServer(self.driver, self.base_page) 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_account_center_login_log(self): self.base_page.open_page() self.log_in_base.log_in() self.log_in_base.click_account_center_button() # 获取登录账号的用户名 current_account = self.log_in_base.get_log_in_account() # 点击招呼栏-业务日志 self.account_center_page_operation_log.click_help_button() self.help_page.click_log_in_log() # 判断当前页面是否正确跳转至业务日志页面 expect_url = self.base_url + "/userFeedback/toHelp" self.assertEqual(expect_url, self.driver.get_current_url(), "当前页面跳转错误") i = 0 csv_file = self.account_center_page_read_csv.read_csv('search_log_in_log_data.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue search_data = { 'account': row[0], 'begin_time': row[1], 'end_time': row[2] } self.help_page.search_login_log(search_data) connect = self.connect_sql.connect_tuqiang_sql() # 创建数据库游标 cur = connect.cursor() # 执行sql脚本查询当前登录账号的userId,fullParent get_id_sql = "select o.userId from user_info o where o.account = '" + current_account + "' ;" cur.execute(get_id_sql) # 读取数据 user_relation = cur.fetchall() # 遍历数据 for row1 in user_relation: user_relation_id = { "userId": row1[0] } get_total_sql = self.help_page_sql.search_log_in_sql(user_relation_id['userId'], search_data) print(get_total_sql) cur.execute(get_total_sql) # 读取数据 total_data = cur.fetchall() # 从数据tuple中获取最终查询记录统计条数 total_list = [] for range1 in total_data: for range2 in range1: total_list.append(range2) total = len(total_list) i += 1 print('第%s次查询数据库的条数为:%s' % (i, total)) web_total = self.help_page.get_current_login_log() print('第%s次查询页面的条数是:%s' % (i, web_total)) self.assertEqual(total, web_total) cur.close() connect.close() csv_file.close()
class TestCase206UserCenterDevLog(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.help_page = HelpPage(self.driver, self.base_url) self.account_center_page_operation_log = AccountCenterOperationLogPage( self.driver, self.base_url) self.help_page_sql = HelpPageSql() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.connect_sql = ConnectSql() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.user_center_page = UserCenterPage(self.driver, self.base_url) 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_user_center_dev_log(self): self.base_page.open_page() self.log_in_base.log_in() user_account = self.log_in_base.get_log_in_account() # 点击设备管理 current_handle = self.driver.get_current_window_handle() self.user_center_page.click_dev_management_button() sleep(3) self.base_page.change_windows_handle(current_handle) # 获取列表第一个imei号 sleep(3) imei = self.user_center_page.get_dev_list_first_imei() # 点击编辑 self.user_center_page.click_edit_dev_button() # 点击确定 self.user_center_page.click_ensure_button() # 销售 self.user_center_page.click_sale_button() # 进入帮助 - 业务日志页面 current_handle_01 = self.driver.get_current_window_handle() self.user_center_page.click_user_center_button() self.base_page.change_windows_handle(current_handle_01) # 点击帮助 self.user_center_page.click_help_button() # 切换到业务日志的frame里面 self.user_center_page.switch_to_business_frame() self.user_center_page.click_search_button_in_business_log() # 获取第一条数据的操作人、目标账号、操作平台、描述 sleep(3) operation = self.user_center_page.get_operation_in_business_log() target_account = self.user_center_page.get_target_account_in_business_log( ) operation_platform = self.user_center_page.get_operation_platform_in_business_log( ) desc = self.user_center_page.get_desc_in_business_log() self.assertEqual(' ' + user_account, operation) self.assertEqual(target_account, user_account) self.assertEqual('网页端', operation_platform) web_desc = "%s修改设备%s" % (user_account, imei) self.assertEqual(web_desc, desc) # 选择设备分配搜索 self.user_center_page.search_dev_sale_in_business_log() # 点击搜索 self.user_center_page.click_search_button_in_business_log() operation_01 = self.user_center_page.get_operation_in_business_log() target_account_01 = self.user_center_page.get_target_account_in_business_log( ) operation_platform_01 = self.user_center_page.get_operation_platform_in_business_log( ) desc_01 = self.user_center_page.get_desc_in_business_log() self.assertEqual(' ' + user_account, operation_01) self.assertEqual(target_account_01, user_account) self.assertEqual('网页端', operation_platform_01) web_desc_01 = "%s将设备%s从%s分配给%s" % (user_account, imei, user_account, user_account) self.assertEqual(web_desc_01, desc_01) self.driver.default_frame()
class TestCase412CustomerManagementEditUserSendWorkTemplateLimit( 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.assert_text2 = AssertText2() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.close_window() self.driver.quit_browser() def test_customer_management_edit_user_send_work_template_limit(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 进入客户管理页面 current_handle = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() user_account = self.cust_manage_basic_info_and_add_cust_page.get_user_account_in_customer_page( ) # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 获取批量下发指令的状态 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() web_login_status = self.cust_manage_basic_info_and_add_cust_page.get_send_work_template_status( ) self.driver.default_frame() if web_login_status == True: # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_send_work_template_status_ins( ) self.driver.default_frame() # 确定 self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') # 进入设备管理 获取设备管理页面操的文本 current_handle_01 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.click_dev_management_button( ) self.base_page.change_windows_handle(current_handle_01) dev_operation_text = self.cust_manage_basic_info_and_add_cust_page.get_facility_manage_page_function_button( ) working_mode = self.assert_text2.dev_manage_setting_working_mode() all_working_mode = self.assert_text2.dev_manage_setting_all_working_mode( ) self.assertNotIn(working_mode, dev_operation_text) self.assertNotIn(all_working_mode, dev_operation_text) # 登录 self.log_in_base.log_in() current_handle_02 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle_02) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_send_work_template_status_ins( ) self.driver.default_frame() self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') hello_usr = self.account_center_page_navi_bar.usr_info_account() self.assertIn(user_account, hello_usr) # 进入设备管理 获取设备管理页面操的文本 current_handle_03 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.click_dev_management_button( ) self.base_page.change_windows_handle(current_handle_03) dev_operation_text = self.cust_manage_basic_info_and_add_cust_page.get_facility_manage_page_function_button( ) working_mode = self.assert_text2.dev_manage_setting_working_mode() all_working_mode = self.assert_text2.dev_manage_setting_all_working_mode( ) self.assertIn(working_mode, dev_operation_text) self.assertIn(all_working_mode, dev_operation_text) elif web_login_status == False: # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_send_work_template_status_ins( ) self.driver.default_frame() self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') hello_usr = self.account_center_page_navi_bar.usr_info_account() self.assertIn(user_account, hello_usr) # 进入设备管理 获取设备管理页面操的文本 current_handle_04 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.click_dev_management_button( ) self.base_page.change_windows_handle(current_handle_04) dev_operation_text = self.cust_manage_basic_info_and_add_cust_page.get_facility_manage_page_function_button( ) working_mode = self.assert_text2.dev_manage_setting_working_mode() all_working_mode = self.assert_text2.dev_manage_setting_all_working_mode( ) self.assertIn(working_mode, dev_operation_text) self.assertIn(all_working_mode, dev_operation_text) # 退出登录 self.account_center_page_navi_bar.usr_logout() self.log_in_base.log_in() current_handle_05 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle_05) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_send_work_template_status_ins( ) self.driver.default_frame() # 确定 self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') # 进入设备管理 获取设备管理页面操的文本 current_handle_06 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.click_dev_management_button( ) self.base_page.change_windows_handle(current_handle_06) dev_operation_text = self.cust_manage_basic_info_and_add_cust_page.get_facility_manage_page_function_button( ) working_mode = self.assert_text2.dev_manage_setting_working_mode() all_working_mode = self.assert_text2.dev_manage_setting_all_working_mode( ) self.assertNotIn(working_mode, dev_operation_text) self.assertNotIn(all_working_mode, dev_operation_text)
class TestCase39AccountCenterOperCustLog(unittest.TestCase): """ 帮助--业务日志 """ # author:邓肖斌 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.help_page = HelpPage(self.driver, self.base_url) self.account_center_page_operation_log = AccountCenterOperationLogPage( self.driver, self.base_url) self.help_page_sql = HelpPageSql() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.connect_sql = ConnectSql() self.log_in_base = LogInBaseServer(self.driver, self.base_page) 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_account_center_oper_cust_log(self): self.base_page.open_page() self.log_in_base.log_in() self.log_in_base.click_account_center_button() # 获取登录账号的用户名 current_account = self.log_in_base.get_log_in_account() # 点击招呼栏-业务日志 self.account_center_page_operation_log.click_help_button() self.help_page.click_business_log() # 判断当前页面是否正确跳转至业务日志页面 expect_url = self.base_url + "/userFeedback/toHelp" self.assertEqual(expect_url, self.driver.get_current_url(), "当前页面跳转错误") i = 0 csv_file = self.account_center_page_read_csv.read_csv( 'search_cus_manager_log_data.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue search_data = { 'search_type': row[0], 'begin_time': row[1], 'end_time': row[2], 'more': row[3] } self.help_page.search_business_log(search_data) connect = self.connect_sql.connect_tuqiang_sql() # 创建数据库游标 cur = connect.cursor() # 执行sql脚本查询当前登录账号的userId,fullParent get_id_sql = \ "select o.account,o.userId,o.fullParentId from user_info o where o.account = " \ "'" + current_account + "' ;" cur.execute(get_id_sql) # 读取数据 user_relation = cur.fetchall() # 遍历数据 for row1 in user_relation: user_relation_id = { "account": row1[0], "userId": row1[1], "fullParent": row1[2] } # 执行sql脚本,根据当前登录账号的userId,fullParent查询出当前账户的所有下级账户 get_lower_account_sql = "select userId from user_info where fullParentId like" + \ "'" + user_relation_id["fullParent"] + user_relation_id["userId"] + "%'" + ";" cur.execute(get_lower_account_sql) # 读取数据 lower_account = cur.fetchall() lower_account_list = [user_relation_id["userId"]] for range1 in lower_account: for range2 in range1: lower_account_list.append(range2) lower_account_tuple = tuple(lower_account_list) get_total_sql = self.help_page_sql.business_log_sql( lower_account_tuple, search_data) print(get_total_sql) cur.execute(get_total_sql) # 读取数据 total_data = cur.fetchall() # 从数据tuple中获取最终查询记录统计条数 total_list = [] for range3 in total_data: for range4 in range3: total_list.append(range4) total = len(total_list) i += 1 print('第%s次查询数据库的条数为:%s' % (i, total)) web_total = self.help_page.get_current_customer_log() print('第%s次查询页面的条数是:%s' % (i, web_total)) self.assertEqual(total, web_total) cur.close() connect.close() csv_file.close()
class TestCase124LoginSuccessWithphAppUser(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.account_center_page_details = AccountCenterDetailsPage( 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_app_user_login_by_csv(self): '''通过csv测试app账户成功登录和成功退出功能''' data = ["首页", "设备管理", "操控台", "统计报表", "安全区域", "设备分布"] csv_file = self.log_in_read_csv.read_csv('login_with_app_user.csv') csv_data = csv.reader(csv_file) for row in csv_data: user_to_login = {"account": row[0], "passwd": row[1]} # 打开途强在线首页-登录页 self.base_page.open_page() # 输入用户信息进行登录 self.login_page.user_login(user_to_login["account"], user_to_login["passwd"]) # 点首页 # self.login_page.click_home_page() # 判断登录成功后跳转页面是否正确 actual_url = self.driver.get_current_url() expect_url = self.base_url + "/nomalUserCenter" self.assertEqual(expect_url, actual_url, "登录成功后页面跳转错误") # 判断登录成功后招呼栏的用户名是否正确 hello_usr = self.account_center_page_navi_bar.hello_user_account() expect_usr = user_to_login["account"] self.assertEqual(expect_usr, hello_usr, "登录成功后招呼栏账户名显示错误") # 验证模块 module = self.account_center_page_navi_bar.get_page_module() for m in range(len(module)): self.assertIn(data[m], module[m], "用户账号登录,模块显示错误") # 获取当前app账号有几个服务商 service_number = self.account_center_page_details.get_current_account_service_number( ) # 获取数据库服务商的个数 connect = self.connect_sql.connect_tuqiang_sql() cursor = connect.cursor() get_up_account_info_sql = "select userId from user_info where account = '%s';" % user_to_login[ 'account'] cursor.execute(get_up_account_info_sql) get_up_user_info = cursor.fetchall() get_current_id = [] for range1 in get_up_user_info: for range2 in range1: get_current_id.append(range2) print(get_current_id) get_service_sql = "select userId from equipment_mostly where bindUserId = '" + get_current_id[ 0] + "' group by userId ;" cursor.execute(get_service_sql) get_service = cursor.fetchall() service_number_list = [] for range1 in get_service: for range2 in range1: service_number_list.append(range2) service_total = len(service_number_list) cursor.close() connect.close() # 断言 # self.assertEqual(service_number - 1, service_total) self.assertEqual(service_number, service_total) # 成功退出系统 sleep(2) self.account_center_page_navi_bar.app_usr_logout() # 判断是否成功退出到登录页 self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "退出系统失败") break csv_file.close()
class TestCase210UserCenterLoginLog(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.help_page = HelpPage(self.driver, self.base_url) self.account_center_page_operation_log = AccountCenterOperationLogPage( self.driver, self.base_url) self.help_page_sql = HelpPageSql() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.connect_sql = ConnectSql() self.connect_es = ConnectEs() self.log_in_base = LogInBaseServer(self.driver, self.base_page) 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_user_center_login_log(self): self.base_page.open_page() self.log_in_base.log_in() sleep(3) current_handle = self.driver.get_current_window_handle() self.log_in_base.click_account_center_button() self.base_page.change_windows_handle(current_handle) # 获取登录账号的用户名 current_account = self.log_in_base.get_log_in_account() # 点击招呼栏-业务日志 self.account_center_page_operation_log.click_help_button() self.help_page.click_log_in_log() # 判断当前页面是否正确跳转至业务日志页面 expect_url = self.base_url + "/userFeedback/toHelp" self.assertEqual(expect_url, self.driver.get_current_url(), "当前页面跳转错误") i = 0 csv_file = self.account_center_page_read_csv.read_csv( 'search_log_in_log_data.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue search_data = { 'account': row[0], 'begin_time': row[1], 'end_time': row[2] } self.help_page.search_login_log(search_data) # 获取当前登录账号和下级账号全部的userid all_user_id = self.help_page.get_all_user_id(current_account) print(all_user_id) '''connect = self.connect_sql.connect_tuqiang_sql() cursor = connect.cursor() get_total_sql = self.help_page_sql.search_log_in_sql(all_user_id, search_data) cursor.execute(get_total_sql) total_list = cursor.fetchall() cursor.close() connect.close()''' # 连接Elastic search es = self.connect_es.connect_es() # 搜索的数据 query_data = self.help_page.get_search_log_in_log_query_data( all_user_id, search_data) res_01 = es.search(index='userlogin_log_2', body={ 'query': query_data, 'size': 20000 }) res_02 = es.search(index='userlogin_log_12', body={ 'query': query_data, 'size': 20000 }) res_03 = es.search(index='userlogin_log_1', body={ 'query': query_data, 'size': 20000 }) total = len(res_01['hits']['hits']) + len( res_02['hits']['hits']) + len(res_03['hits']['hits']) i += 1 print('第%s次查询数据库的条数为:%s' % (i, total)) web_total = self.help_page.get_current_login_log() print('第%s次查询页面的条数是:%s' % (i, web_total)) if total != 0: total += 10 self.assertEqual(total, web_total) csv_file.close()
class TestCase7408171CustManagelResetPasswordVerify(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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.assert_text2 = AssertText2() self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_cancel_and_ascertain_reset_password(self): '''客户管理-取消和确定重置密码操作''' account = ["xin_121313"] # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() self.driver.wait(1) # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() # 搜索账号 self.cust_manage_lower_account_page.input_search_info(account[0]) self.cust_manage_lower_account_page.click_search_btn() self.assertEqual( account[0], self.cust_manage_lower_account_page.get_search_result_account(), "搜索结果账号不一致") # 取消重置密码 self.cust_manage_lower_account_page.click_reset_passwd_dismiss() # 取消重置密码后的验证 self.log_in_base.click_account_center_button() sleep(2) self.account_center_page_navi_bar.usr_logout() self.log_in_base.log_in_with_csv(account[0], "jimi123") hello_usr = self.account_center_page_navi_bar.hello_user_account() self.assertIn(account[0], hello_usr, "登录成功后招呼栏账户名显示错误") sleep(1) self.account_center_page_navi_bar.usr_logout() #再次登录,重置密码 self.log_in_base.log_in() self.driver.wait(1) # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.cust_manage_lower_account_page.input_search_info(account[0]) self.cust_manage_lower_account_page.click_search_btn() # 点击单个用户的重置密码 self.cust_manage_lower_account_page.acc_reset_passwd() # 获取重置密码弹框文本内容 text = self.cust_manage_lower_account_page.reset_passwd_content() hint_password = text.split(":")[2] # 验证重密码是否正确显示 self.assertEqual("888888", hint_password, "弹框中的重置密码显示的不是888888") # 确定重置密码 self.cust_manage_lower_account_page.reset_passwd_ensure() # 获取重置状态 reset_status = self.cust_manage_lower_account_page.reset_passwd_content( ) # 验证操作状态是否成功 self.assertIn(self.assert_text.account_center_page_operation_done(), reset_status, "操作失败") # 退出登录 sleep(1) self.log_in_base.click_account_center_button() sleep(2) self.account_center_page_navi_bar.usr_logout() # 修改用户的默认密码 self.log_in_base.log_in_with_csv(account[0], hint_password) sleep(2) # 修改用户默认密码(jimi123) self.cust_manage_basic_info_and_add_cust_page.user_default_password_edit( "jimi123") sleep(2) # 获取密码修改成功 self.driver.click_element("x,/html/body/div[16]/div[3]/a") # status = self.cust_manage_basic_info_and_add_cust_page.user_default_password_edit_prompt() # self.assertIn(self.assert_text2.home_page_edit_password_success(), status, "修改密码失败!") sleep(2) self.assertEqual(self.base_url + "/", self.driver.get_current_url(), "修改默认密码后,没有返回到登录页")
class TestCase07AccountCenterMsgSearch(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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_operation_log = AccountCenterOperationLogPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.account_center_page_msg_center = AccountCenterMsgCenterPage( self.driver, self.base_url) self.assert_text = AssertText() self.driver.set_window_max() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.connect_sql = ConnectSql() self.search_sql = SearchSql() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_account_center_msg_search(self): self.base_page.open_page() self.log_in_base.log_in() self.account_center_page_navi_bar.click_account_center_button() # self.driver.switch_to_frame('x,//*[@id="usercenterFrame"]') # 获取登录账号的用户名 current_account = self.log_in_base.get_log_in_account() #self.driver.default_frame() # 进入消息中心 self.account_center_page_msg_center.enter_msg_center() self.driver.wait(10) # 进入iframe # self.account_center_page_msg_center.message_center_iframe() # 获取消息中心title msg_center_title = self.account_center_page_msg_center.get_msg_center_title( ) # 验证消息中心title是否正确显示 self.assertIn( self.assert_text.account_center_page_message_center_text(), msg_center_title, "消息中心title有误!") csv_file = self.account_center_page_read_csv.read_csv( 'search_massage_data.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue search_data = {'imei': row[0], 'type': row[1], 'status': row[2]} # 搜索 self.account_center_page_operation_log.add_data_to_search_massages( search_data) connect1 = self.connect_sql.connect_tuqiang_sql() # 创建数据库游标 cur = connect1.cursor() # 执行sql脚本查询当前登录账号的userId,fullParent get_id_sql = "select o.account,o.userId,o.fullParentId from user_info o where o.account = '" + current_account + "';" cur.execute(get_id_sql) # 读取数据 user_relation = cur.fetchall() # 遍历数据 for row in user_relation: user_relation_id = { "account": row[0], "userId": row[1], "fullParent": row[2] } # 执行sql脚本,根据当前登录账号的userId,fullParent查询出当前账户的所有下级账户 get_lower_account_sql = "select userId from user_info where fullParentId like" + \ "'" + user_relation_id["fullParent"] + user_relation_id["userId"] + "%'" + ";" cur.execute(get_lower_account_sql) # 读取数据 lower_account = cur.fetchall() lower_account_list = [user_relation_id["userId"]] for range1 in lower_account: for range2 in range1: lower_account_list.append(range2) self.lower_account_tuple = tuple(lower_account_list) cur.close() connect1.close() connect = self.connect_sql.connect_tuqiang_sql() # 创建数据库游标 cur = connect.cursor() get_total_sql = self.search_sql.search_massage_sql( self.lower_account_tuple, search_data) print(get_total_sql) cur.execute(get_total_sql) # 读取数据 total_data = cur.fetchall() # 从数据tuple中获取最终查询记录统计条数 total_list = [] for range1 in total_data: for range2 in range1: total_list.append(range2) total = len(total_list) print('本次查询数据库的条数为:%s' % total) web_total = self.account_center_page_operation_log.get_msg_number() print('本次查询页面的条数是:%s' % web_total) self.assertEqual(total, web_total) cur.close() connect.close() csv_file.close()
class TestCase58CustManageAddAcc(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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.assert_text2 = AssertText2() self.search_sql = SearchSql() self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.connect_sql = ConnectSql() self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_cust_manage_add_acc(self): '''测试客户管理-新增用户''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.cust_manage_basic_info_and_add_cust_page.add_acc() self.cust_manage_basic_info_and_add_cust_page.close_add_account() csv_file = self.cust_manage_page_read_csv.read_csv('acc_add.csv') csv_data = csv.reader(csv_file) for row in csv_data: add_info = { "keyword": row[0], "acc_type": row[1], "acc_name": row[2], "account": row[3], "passwd": row[4], "phone": row[5], "email": row[6], "conn": row[7], "com": row[8], "search_user": row[9] } # 左侧客户列表搜索并选中唯一客户 self.cust_manage_cust_list_page.acc_exact_search( add_info["keyword"]) # 点击新增用户 self.cust_manage_basic_info_and_add_cust_page.add_acc() sleep(2) # 验证所选中的上级用户类型来显示可创建的下级类型 user_list = add_info["search_user"].split("/") for type in user_list: self.cust_manage_basic_info_and_add_cust_page.acc_search(type) type_list = self.cust_manage_basic_info_and_add_cust_page.get_acc_user_type_list( ) sql_data = self.search_sql.search_current_account_data(type) user_type = self.assert_text.log_in_page_account_type( sql_data[2]) print(user_type) if user_type == "销售": self.assertEqual(3, type_list["length"]) self.assertIn( self.assert_text.log_in_page_account_type(11), type_list["sale"]) self.assertIn(self.assert_text.log_in_page_account_type(8), type_list["distributor"]) self.assertIn(self.assert_text.log_in_page_account_type(9), type_list["user"]) elif user_type == "代理商": self.assertEqual(2, type_list["length"]) self.assertIn(self.assert_text.log_in_page_account_type(8), type_list["distributor"]) self.assertIn(self.assert_text.log_in_page_account_type(9), type_list["user"]) elif user_type == "用户": self.assertNotEqual(1, type_list["length"]) #self.assertIn(self.assert_text.log_in_page_account_type(9),type_list["user"]) sleep(1) #添加用户类型获取提示 self.cust_manage_basic_info_and_add_cust_page.acc_search( "yonghu222") sleep(2) self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() # status = self.cust_manage_lower_account_page.edit_info_save_status() self.driver.default_frame() # self.assertEqual(self.assert_text2.cust_manage_add_user_type_prompt(), status, "提示显示不一致") # 右侧搜索栏中搜索并选中作为上级用户 self.cust_manage_basic_info_and_add_cust_page.acc_search( add_info["keyword"]) # 选择客户类型 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.acc_type_choose( add_info["acc_type"]) # 编辑用户输入框信息 self.cust_manage_basic_info_and_add_cust_page.add_acc_input_info_edit( add_info["acc_name"], add_info["account"], add_info["passwd"], add_info["phone"], add_info["email"], add_info["conn"], add_info["com"]) # 修改用户登录权限 self.cust_manage_basic_info_and_add_cust_page.acc_login_limit_modi( ) self.driver.default_frame() self.cust_manage_basic_info_and_add_cust_page.acc_add_save() # 获取保存操作状态 status = self.cust_manage_basic_info_and_add_cust_page.acc_info_save_status( ) # 验证是否操作成功 self.assertIn( self.assert_text.account_center_page_operation_done(), status, "操作失败") # 搜索新增客户 sleep(4) self.cust_manage_lower_account_page.input_search_info( add_info["account"]) # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 删除该新增客户 self.cust_manage_lower_account_page.delete_acc() # 确定删除 self.cust_manage_lower_account_page.delete_acc_ensure() # 获取删除操作状态 del_status = self.cust_manage_lower_account_page.get_del_status() # 验证是否操作成功 self.assertIn( self.assert_text.account_center_page_operation_done(), del_status, "操作失败") csv_file.close()
class TestCase09AccountCenterVisuEditAndDel(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_visual_account = AccountCenterVisualAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_page) 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_account_center_visu_edit_and_del(self): '''通过csv测试虚拟账户管理-编辑、删除功能''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() self.account_center_page_navi_bar.click_account_center_button() # 进入虚拟账户管理 self.account_center_page_visual_account.enter_visual_account() csv_file = self.account_center_page_read_csv.read_csv( 'add_visual_account.csv') csv_data = csv.reader(csv_file) for row in csv_data: acc_to_add = {"account": row[0], "passwd": row[1]} # 添加虚拟账户 self.account_center_page_visual_account.add_visual_account( acc_to_add["account"], acc_to_add["passwd"]) # 取消添加 self.account_center_page_visual_account.dis_save_add_info() self.driver.wait() # 编辑列表中的虚拟账户 self.account_center_page_visual_account.edit_visu_account( acc_to_add["passwd"]) # 验证是否保存成功 save_status = self.account_center_page_visual_account.get_save_status( ) self.assertIn( self.assert_text.account_center_page_operation_done(), save_status, "保存成功") self.account_center_page_visual_account.dis_edit() self.driver.wait(1) # 删除列表中的虚拟账户 self.account_center_page_visual_account.del_visu_account() # 验证是否操作成功 save_status = self.account_center_page_visual_account.get_save_status( ) self.assertIn( self.assert_text.account_center_page_operation_done(), save_status, "操作成功") self.driver.wait() csv_file.close()
class TestCase11AccountCenterOverviewTotal(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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_details = AccountCenterDetailsPage(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.assert_text = AssertText() self.driver.set_window_max() self.connect_sql = ConnectSql() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_account_center_overview_total(self): self.base_page.open_page() self.log_in_base.log_in() # self.log_in_base.log_in_with_csv("kankan111","jimi123") self.account_center_page_navi_bar.click_account_center_button() self.account_center_page_details.account_center_iframe() # 获取登录账号的用户名 # current_account = self.log_in_base.get_log_in_account() sleep(2) account_center_handle = self.driver.get_current_window_handle() expect_total = self.account_center_page_details.get_current_account_total_equipment() # 点击库存 self.account_center_page_details.account_overview('总进货数') self.driver.default_frame() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != account_center_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.driver.get_current_url() # 执行sql脚本查询当前登录账号的userId,fullParent actual_url = self.base_url + '/device/toDeviceManage?lowerDevFlag=1' self.assertEqual(expect_url, actual_url, '点击总进货数后,实际的url和期望的不一样!') # 断言包涵下级是否被勾选上 self.assertEqual(True, self.driver.get_element('x,//*[@id="lowerFlag"]/div/input').is_selected()) sleep(3) dev_count = self.account_center_page_details.get_total_dev_number_after_ckick_all_dev_number() self.assertEqual(expect_total, str(dev_count), '当前总进货数和实际数据库不一致!') # 验证清空按钮 self.account_center_page_details.click_clear_all_button() lower_user_input_value = self.account_center_page_details.get_lower_input_value() self.assertEqual(False, lower_user_input_value) # 点搜索 self.account_center_page_details.click_search_button() lower_user_input_value_again = self.account_center_page_details.get_lower_input_value() self.assertEqual(False, lower_user_input_value_again) # 查看控制台告警设置能否打开 self.account_center_page_navi_bar.click_alarm_button_in_console() # 断言 get_text = self.account_center_page_navi_bar.get_text_after_click_alarm_button() self.assertEqual(self.assert_text.account_center_page_alarm_manager_text(), get_text) self.account_center_page_navi_bar.close_alarm_in_console() self.driver.close_current_page() # 回到账户中心窗口 self.driver.switch_to_window(account_center_handle) self.driver.wait()
class TestCase69CustManageAllSelect(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage(self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage(self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage(self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() 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_cust_manage_all_select(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() sleep(2) # 点击全选 self.cust_manage_basic_info_and_add_cust_page.click_all_select_button() input_all_select = self.cust_manage_basic_info_and_add_cust_page.get_all_select_value() self.assertEqual(True, input_all_select) # 验证下面的是否被全选 # 获取本页列表的数量 list_number = self.cust_manage_basic_info_and_add_cust_page.get_per_account_number() for n in range(list_number): list_input_value = self.driver.get_element( 'x,//*[@id="customerlist"]/tr[%s]/td[1]/span/div/input' % str(n + 1)).is_selected() self.assertEqual(True, list_input_value) # 取消全选 self.cust_manage_basic_info_and_add_cust_page.click_all_select_button() input_all_select = self.cust_manage_basic_info_and_add_cust_page.get_all_select_value() self.assertEqual(False, input_all_select) for n in range(list_number): list_input_value = self.driver.get_element( 'x,//*[@id="customerlist"]/tr[%s]/td[1]/span/div/input' % str(n + 1)).is_selected() self.assertEqual(False, list_input_value) # 全选后取消选择其中一个 self.cust_manage_basic_info_and_add_cust_page.click_all_select_button() self.cust_manage_basic_info_and_add_cust_page.click_cancel_select_list() # 判断全选是否为真 self.assertEqual(False, self.cust_manage_basic_info_and_add_cust_page.get_all_select_value()) # 在一次选择上列表中的那个 self.cust_manage_basic_info_and_add_cust_page.click_cancel_select_list() # 判断全选是否为真 self.assertEqual(True, self.cust_manage_basic_info_and_add_cust_page.get_all_select_value()) # 在选择每页显示30条 self.cust_manage_basic_info_and_add_cust_page.select_per_page_numbers() self.assertEqual(False, self.cust_manage_basic_info_and_add_cust_page.get_all_select_value())
class TestCase450919AccountCenterRefillCardRefillRecordSearch(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='CHROME') 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.account_center_page_details = AccountCenterDetailsPage(self.driver, self.base_url) self.account_center_page_refill_card = AccountCenterRefillCardPage(self.driver, self.base_url) self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.connect_sql = ConnectSql() self.search_sql = SearchSql() self.assert_text = AssertText() self.driver.set_window_max() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_refill_record_search(self): '''充值卡-充值记录--搜索''' csv_file = self.account_center_page_read_csv.read_csv('search_refill_record_data.csv') csv_data = csv.reader(csv_file) # 打开途强在线首页-登录页 self.base_page.open_page() # 登录账号 self.log_in_base.log_in() self.driver.wait(1) self.account_center_page_navi_bar.click_account_center_button() # 进入充值卡页面 # self.account_center_page_navi_bar.switch_to_chongzhi_card() self.account_center_page_refill_card.click_refill_card() # 验证页面顶部我的账号 my_account = self.account_center_page_refill_card.get_title_display_account() self.assertIn(self.account_center_page_refill_card.get_current_login_account(), my_account, "登录账号显示一致") for row in csv_data: data = { "refill_type": row[0], "device_imei": row[1] } # 点击充值记录 self.account_center_page_refill_card.click_refill_record() # 搜索 count = self.account_center_page_refill_card.refill_record_search_data(data["refill_type"], data["device_imei"]) # 验证imei计数 self.assertEqual(count["import_count"], int(count["add_count"]), "输入框中imei的计数显示错误") # 获取页面列表条数 page_number = self.account_center_page_refill_card.get_refill_record_number() # 获取当前账号id sql_data = self.search_sql.search_current_account_data(my_account) connect1 = self.connect_sql.connect_tuqiang_sql() # 创建数据库游标 cur = connect1.cursor() # 获取数据库条数 get_sql = self.search_sql.search_refill_record_sql(sql_data[0], data) print(get_sql) cur.execute(get_sql) # 读取数据 total_data = cur.fetchall() # 从数据tuple中获取最终查询记录统计条数 total_list = [] for range1 in total_data: for range2 in range1: total_list.append(range2) total = len(total_list) print('本次查询数据库的条数为:%s' % total) # 获取数据库条数 self.assertEqual(total, page_number, "转移记录中,平台与sql搜索出来的数据条数不一致") # 点击充值记录 self.account_center_page_refill_card.click_refill_record() # 获取设备有多少个分页 total_page = self.account_center_page_refill_card.get_total_page_number_search_refill_record() print(total_page) if total_page[0] == 0: text = self.account_center_page_refill_card.get_refill_record_page_no_data_text() self.assertIn(self.assert_text.account_center_page_no_data_text(), text) elif total_page[0] == 1: up_page_class = self.account_center_page_refill_card.get_up_page_class_active_in_refill_search() self.assertEqual('active', up_page_class) else: for n in range(total_page[0]): self.account_center_page_refill_card.click_per_page(n) get_per_first_number = self.account_center_page_refill_card.get_per_frist_number_in_refill_search() self.assertEqual(get_per_first_number, str(10 * (n + 1) - 9)) # 点击每页20条 list = [20, 30, 50, 100] for m in list: self.account_center_page_refill_card.click_per_page_number_refill_record() page_number = self.account_center_page_refill_card.get_page_number_in_refill_record_search() print(page_number) self.assertEqual(int(total_page[1] / m) + 1, page_number) csv_file.close()
class TestCase410CustomerManagementEditUserWebLoginLimit(unittest.TestCase): # 测试编辑客户 -- 修改用户web登录权限 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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage( self.driver, self.base_url) self.cust_manage_cust_list_page = CustManageCustListPage( self.driver, self.base_url) self.cust_manage_my_dev_page = CustManageMyDevPage( self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage( self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage( self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.assert_text2 = AssertText2() self.connect_sql = ConnectSql() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.close_window() self.driver.quit_browser() def test_customer_management_edit_user_web_login_limit(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 进入客户管理页面 current_handle = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() user_account = self.cust_manage_basic_info_and_add_cust_page.get_user_account_in_customer_page( ) # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 获取web登录权限的 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() web_login_status = self.cust_manage_basic_info_and_add_cust_page.get_web_login_status( ) self.driver.default_frame() if web_login_status == True: # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_web_login_status_ins( ) self.driver.default_frame() # 确定 self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') self.assertEqual(self.assert_text2.login_no_permissions(), self.login_page.get_exception_text()) # 登录 self.log_in_base.log_in() current_handle_01 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle_01) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_web_login_status_ins( ) self.driver.default_frame() self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') hello_usr = self.account_center_page_navi_bar.usr_info_account() self.assertIn(user_account, hello_usr) elif web_login_status == False: # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_web_login_status_ins( ) self.driver.default_frame() self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') hello_usr = self.account_center_page_navi_bar.usr_info_account() self.assertIn(user_account, hello_usr) # 退出登录 self.account_center_page_navi_bar.usr_logout() self.log_in_base.log_in() current_handle_02 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle_02) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_web_login_status_ins( ) self.driver.default_frame() # 确定 self.cust_manage_basic_info_and_add_cust_page.click_ensure() # 退出登录 self.account_center_page_navi_bar.usr_logout() # 登录刚刚的账号 self.log_in_base.log_in_with_csv(user_account, 'jimi123') self.assertEqual(self.assert_text2.login_no_permissions(), self.login_page.get_exception_text()) self.log_in_base.log_in() current_handle_03 = self.driver.get_current_window_handle() self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() self.base_page.change_windows_handle(current_handle_03) # 搜索一个客户 self.cust_manage_lower_account_page.input_search_info('abc12344') # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 点击编辑 - 取消 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击取消 self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() # 点击编辑 self.cust_manage_basic_info_and_add_cust_page.click_edit_account_buttons( ) # 点击 self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() self.cust_manage_basic_info_and_add_cust_page.click_web_login_status_ins( ) self.driver.default_frame() # 确定 self.cust_manage_basic_info_and_add_cust_page.click_ensure()
class TestCase201UserCenterModifyInfo(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.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.account_center_page_details = AccountCenterDetailsPage(self.driver, self.base_url) self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.user_center_page = UserCenterPage(self.driver, self.base_url) self.assert_text = AssertText() self.driver.set_window_max() self.driver.clear_cookies() # 打开途强在线首页-登录页 self.base_page.open_page() sleep(1) # 登录账号 self.log_in_base.log_in() def tearDown(self): self.driver.quit_browser() def test_user_center_modify_info(self): # 通过csv测试修改资料功能 self.account_center_page_navi_bar.click_account_center_button() csv_file = self.account_center_page_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], "email": row[2] } # 获取当前登录账号 log_in_account = self.log_in_base.get_log_in_account() # 从数据库获取登录账号的客户名称、电话、邮箱 account_info = self.user_center_page.get_account_info(log_in_account) print(account_info) # 点击个人中心 - 修改资料 self.user_center_page.click_user_center_button() self.user_center_page.click_modify_user_info() # 获取修改资料里面的信息 user_account = self.user_center_page.get_user_account_in_modify_page() user_name = self.user_center_page.get_user_name_in_modify_page() user_phone = self.user_center_page.get_user_phone_in_modify_page() user_email = self.user_center_page.get_user_email_in_modify_page() # 断言 self.assertEqual(log_in_account, user_account) self.assertEqual(account_info[0], user_name) self.assertEqual(account_info[1], user_phone) self.assertEqual(account_info[2], user_email) # 填写客户名称、电话、邮箱 self.user_center_page.add_data_to_modify_info(user_to_modify_info) # 点击取消的按钮 self.user_center_page.click_cancel_button() # 从数据库获取登录账号的客户名称、电话、邮箱 account_info1 = self.user_center_page.get_account_info(log_in_account) print(account_info1) self.assertEqual(account_info, account_info1) # 点击个人中心 - 修改资料 self.user_center_page.click_user_center_button() self.user_center_page.click_modify_user_info() # 获取修改资料里面的信息 user_account = self.user_center_page.get_user_account_in_modify_page() user_name = self.user_center_page.get_user_name_in_modify_page() user_phone = self.user_center_page.get_user_phone_in_modify_page() user_email = self.user_center_page.get_user_email_in_modify_page() # 断言 self.assertEqual(log_in_account, user_account) self.assertEqual(account_info1[0], user_name) self.assertEqual(account_info1[1], user_phone) self.assertEqual(account_info1[2], user_email) # 点击关闭 # 填写客户名称、电话、邮箱 self.user_center_page.add_data_to_modify_info(user_to_modify_info) self.user_center_page.click_close_button() # 从数据库获取登录账号的客户名称、电话、邮箱 account_info2 = self.user_center_page.get_account_info(log_in_account) print(account_info2) self.assertEqual(account_info, account_info2) # 点击个人中心 - 修改资料 self.user_center_page.click_user_center_button() self.user_center_page.click_modify_user_info() # 获取修改资料里面的信息 user_account = self.user_center_page.get_user_account_in_modify_page() user_name = self.user_center_page.get_user_name_in_modify_page() user_phone = self.user_center_page.get_user_phone_in_modify_page() user_email = self.user_center_page.get_user_email_in_modify_page() # 断言 self.assertEqual(log_in_account, user_account) self.assertEqual(account_info2[0], user_name) self.assertEqual(account_info2[1], user_phone) self.assertEqual(account_info2[2], user_email) # 填写客户名称、电话、邮箱 self.user_center_page.add_data_to_modify_info(user_to_modify_info) # 点击确认 self.user_center_page.click_ensure_button() # 从数据库获取登录账号的客户名称、电话、邮箱 account_info3 = self.user_center_page.get_account_info(log_in_account) print(account_info3) web_data = [user_to_modify_info['username'], user_to_modify_info['phone'], user_to_modify_info['email']] self.assertEqual(account_info3, web_data) # 点击个人中心 - 修改资料 self.user_center_page.click_user_center_button() self.user_center_page.click_modify_user_info() # 获取修改资料里面的信息 user_account = self.user_center_page.get_user_account_in_modify_page() user_name = self.user_center_page.get_user_name_in_modify_page() user_phone = self.user_center_page.get_user_phone_in_modify_page() user_email = self.user_center_page.get_user_email_in_modify_page() # 断言 self.assertEqual(log_in_account, user_account) self.assertEqual(account_info3[0], user_name) self.assertEqual(account_info3[1], user_phone) self.assertEqual(account_info3[2], user_email) self.user_center_page.click_close_button() csv_file.close()
class TestCase37AccountCenterSearchLowerClientVerify(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.account_center_page_details = AccountCenterDetailsPage( self.driver, self.base_url) self.assert_text = AssertText() self.driver.set_window_max() self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.account_center_change_page = AccountCenterChangePage( self.driver, self.base_page) self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def tearDown(self): self.driver.quit_browser() def test_search_lower_client(self): '''通过csv测试账户详情--下级客户--查找不同账号功能''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录账号 self.log_in_base.log_in() self.driver.wait(1) self.account_center_page_navi_bar.click_account_center_button() self.account_center_change_page.switch_fast_sale_enable() self.account_center_change_page.switch_to_fast_sale_frame() csv_file = self.account_center_page_read_csv.read_csv( 'search_different_account.csv') csv_data = csv.reader(csv_file) for row in csv_data: search_account = {"account": row[0]} # 查找账户 search_result = self.account_center_page_details.subordinate_account_search( search_account["account"]) if type(search_result) is str: self.assertIn( self.assert_text.account_center_page_no_data_text(), search_result, "搜索结果为暂无数据时,提示不一致") else: for subscript in range(len(search_result)): text = search_result[subscript].split("(")[0] self.assertIn(search_account["account"], text, "搜索结果不一致") self.driver.wait() # 直接选择用户 for user in range(8): self.account_center_page_details.fast_sales() self.account_center_page_details.click_list_subordinate_client( user + 1) # 验证enter键输入 self.account_center_page_details.fast_sales() self.account_center_page_details.search_subordinate_client_click_enter( "1234") self.driver.wait() self.driver.default_frame() csv_file.close()
class TestCase30AccountCenterVisualEditException(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.visual_account_page = AccountCenterVisualAccountPage(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.base_page.open_page() self.assert_text = AssertText() self.driver.set_window_max() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) def test_visual_account_edit_exception(self): '''虚拟账户修改,异常错误提示''' # 登录 self.log_in_base.log_in() self.account_center_page_navi_bar.click_account_center_button() sleep(1) # 进入虚拟账户管理 self.visual_account_page.enter_visual_account() # 添加虚拟账号、保存 self.visual_account_page.add_visual_account("xnhtj001", "jimi123") self.visual_account_page.save_add_info() # 点击编辑 self.visual_account_page.click_editor() # 虚拟账号添加与编辑方法 # 长度不够 prompt = self.visual_account_page.get_visu_account_error_prompt("edit", "12", "") self.assertEqual(self.assert_text.account_center_page_password_len_text(), prompt["pwd_error_prompt"], "修改虚拟账号密码,提示不一致") self.assertEqual(self.assert_text.account_center_page_password_unlike(), prompt["pwd2_error_prompt"], "虚拟账号的确认密码,提示不一致") # 格式错误 prompt = self.visual_account_page.get_visu_account_error_prompt("edit", "abcdefgh", "") self.assertEqual(self.assert_text.account_center_page_password_formart_text(), prompt["pwd_error_prompt"], "修改虚拟账号密码,提示不一致") self.assertEqual(self.assert_text.account_center_page_password_unlike(), prompt["pwd2_error_prompt"], "虚拟账号的确认密码,提示不一致") # 密码相同,长度不够 prompt = self.visual_account_page.get_visu_account_error_prompt("edit", "123", "123") self.assertEqual(self.assert_text.account_center_page_password_len_text(), prompt["pwd_error_prompt"], "修改虚拟账号密码,提示不一致") self.assertEqual(self.assert_text.account_center_page_password_len_text(), prompt["pwd2_error_prompt"], "虚拟账号的确认密码,提示不一致") # 密码不一致 prompt = self.visual_account_page.get_visu_account_error_prompt("edit", "jimi123", "123") self.assertEqual("", prompt["pwd_error_prompt"], "修改虚拟账号密码,提示不一致") self.assertEqual(self.assert_text.account_center_page_password_unlike(), prompt["pwd2_error_prompt"], "虚拟账号的确认密码,提示不一致") # 验证密码输入长度 self.assertEqual(16, self.visual_account_page.get_visual_add_and_edit_len(), "密码限制长度显示不一致") # 点取消 self.visual_account_page.dis_save_add_info() self.driver.wait(1) # 删除 self.visual_account_page.del_visu_account() self.driver.wait() # 退出登录 # self.account_center_page_navi_bar.usr_logout() def tearDown(self): self.driver.quit_browser()
class TestCase410918AccountCenterRefillCardAddApply(unittest.TestCase): def setUp(self): self.driver = AutomateDriverServer(choose='chrome') 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.account_center_page_refill_card = AccountCenterRefillCardPage( self.driver, self.base_url) self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.account_center_page_read_csv = AccountCenterPageReadCsv() self.log_in_base = LogInBaseServer(self.driver, self.base_page) self.assert_text2 = AssertText2() 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_apply_refill_card(self): '''充值卡-申请记录--申请充值卡''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录账号 # self.log_in_base.log_in_with_csv("dzltest", "jimi123") self.log_in_base.log_in() self.driver.wait(1) self.account_center_page_navi_bar.click_account_center_button() # 进入充值卡页面 # self.account_center_page_navi_bar.switch_to_chongzhi_card() self.account_center_page_refill_card.click_refill_card() csv_file = self.account_center_page_read_csv.read_csv( 'apply_refill_card.csv') csv_data = csv.reader(csv_file) for row in csv_data: data = { "year": row[0], "lifetime": row[1], "name": row[2], "phone": row[3], "payment_account": row[4] } # 验证页面顶部我的账号 my_account = self.account_center_page_refill_card.get_title_display_account( ) # 取消 self.account_center_page_refill_card.apply_refill_card_cancel() # 验证账号 self.account_center_page_refill_card.click_apply_refill_card_button( ) apply_page_account = self.account_center_page_refill_card.get_refill_account( ) self.assertEqual(my_account, apply_page_account, "充值账号显示不一致") # 添加充值卡 self.account_center_page_refill_card.apply_refill_card_add( data["year"], data["lifetime"], data["name"], data["phone"], data["payment_account"]) information = self.account_center_page_refill_card.get_applicant_information( ) statu = self.account_center_page_refill_card.get_operate_status() self.assertEqual( self.assert_text2.account_center_refill_card_apply_succeed(), statu, "申请充值卡失败") # 验证添加数据与申请人信息 self.assertEqual(apply_page_account, information["applicant_account"], "申请人信息中,充值账号显示不一致") self.assertEqual(data["year"] + "张", information["year"], "申请人信息中,一年充值卡张数显示不一致") self.assertEqual(data["lifetime"] + "张", information["lifetime"], "申请人信息中,终身充值卡张数显示不一致") self.assertEqual(data["name"], information["name"], "申请人信息中,付款人姓名显示不一致") self.assertEqual(data["phone"], information["phone"], "申请人信息中,充值联系方式显示不一致") self.assertEqual(data["payment_account"], information["payment_account"], "申请人信息中,付款账号显示不一致") csv_file.close()
class TestCase730816CustManageEditUserCommandLimit(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.cust_manage_basic_info_and_add_cust_page = CustManageBasicInfoAndAddCustPage(self.driver, self.base_url) self.cust_manage_lower_account_page = CustManageLowerAccountPage(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url) self.log_in_base = LogInBaseServer(self.driver, self.base_url) self.cust_manage_page_read_csv = CustManagePageReadCsv() self.assert_text = AssertText() self.assert_text2 = AssertText2() 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_edit_account_command_limit_verify(self): '''测试客户管理-编辑指令权限后验证''' self.base_page.open_page() csv_file = self.cust_manage_page_read_csv.read_csv('add_user_command_limit_data.csv') csv_data = csv.reader(csv_file) for row in csv_data: info = { "passwd": row[4], "command": row[9], "working_mode": row[10], "wdit_account": row[11] } # 登录 self.log_in_base.log_in() # 进入客户管理页面 self.cust_manage_basic_info_and_add_cust_page.enter_cust_manage() # 搜索账号 self.cust_manage_lower_account_page.input_search_info(info["wdit_account"]) # 搜索 self.cust_manage_lower_account_page.click_search_btn() # 点击编辑用户 self.cust_manage_basic_info_and_add_cust_page.click_edit_customer() self.cust_manage_basic_info_and_add_cust_page.click_cancel_edit() self.cust_manage_basic_info_and_add_cust_page.click_edit_customer() self.cust_manage_basic_info_and_add_cust_page.locate_to_iframe() # 是或否批量下发指令 和批量下发工作模式 command_status = self.cust_manage_basic_info_and_add_cust_page.setting_command_permissions(info["command"]) working_mode_status = self.cust_manage_basic_info_and_add_cust_page.setting_working_mode_permissions( info["working_mode"]) self.assertEqual(info["command"], str(command_status), "勾选状态与期望不一致") self.assertEqual(info["working_mode"], str(working_mode_status), "勾选状态与期望不一致") self.driver.default_frame() sleep(2) self.cust_manage_basic_info_and_add_cust_page.acc_add_save() sleep(1) # 退出登录 self.log_in_base.click_account_center_button() sleep(2) self.account_center_page_navi_bar.usr_logout() self.log_in_base.log_in_with_csv(info["wdit_account"], info["passwd"]) sleep(1) hello_usr = self.account_center_page_navi_bar.hello_user_account() self.assertIn(info["wdit_account"], hello_usr, "登录成功后招呼栏账户名显示错误") sleep(1) # 进入设备管理/指令管理页面,获取功能按钮 facility_manage_data = self.cust_manage_basic_info_and_add_cust_page.get_facility_manage_page_function_button() sleep(2) command_manage_data = self.cust_manage_basic_info_and_add_cust_page.get_command_page_module() # 获取中文,依次是:选中发送指令、本次查询全部发送指令、选中设置工作模式、本次查询全部设置工作模式 #工作模式模板管理, 下发工作模式任务管理, 下发工作模式管理, 下发指令任务管理, 下发指令管理 send_command = self.assert_text2.dev_manage_select_send_command() all_send_command = self.assert_text2.dev_manage_select_all_send_command() working_mode = self.assert_text2.dev_manage_setting_working_mode() all_working_mode = self.assert_text2.dev_manage_setting_all_working_mode() template_manage = self.assert_text.command_manager_page_work_type_template_management() working_mode_task_manage = self.assert_text2.comm_manage_send_working_mode_task_manage() working_mode_manage = self.assert_text2.comm_manage_send_working_mode_manage() task_manage = self.assert_text2.comm_manage_command_task_manage() comm_manager = self.assert_text.command_manager_page_issued_command_manager() command_list =[] working_mode_list = [] #循环设备管理页面的数据 for b in facility_manage_data: #选中发送指令 和 本次查询全部发送指令 if send_command in b or all_send_command in b: command_list.append(b) #选中设置工作模式 和 本次查询全部设置工作模式 elif working_mode in b or all_working_mode in b: working_mode_list.append(b) #循环指令管理页面的数据 for c in command_manage_data: #下发指令任务管理 和 下发指令管理 if task_manage in c or comm_manager in c: command_list.append(c) #工作模式模板管理, 下发工作模式任务管理, 下发工作模式管理 elif template_manage in c or working_mode_task_manage in c or working_mode_manage in c: working_mode_list.append(c) print("指令", command_list) print("工作模式", working_mode_list) #验证设备、指令管理页面功能按钮显示情况 if command_status == True and working_mode_status == True: # 指令(设备页+指令管理页) self.assertEqual(send_command, command_list[0]) self.assertEqual(all_send_command, command_list[1]) self.assertEqual(task_manage, command_list[2]) self.assertEqual(comm_manager, command_list[3]) # 工作模式(设备页+指令管理页) self.assertEqual(working_mode, working_mode_list[0]) self.assertEqual(all_working_mode, working_mode_list[1]) self.assertEqual(template_manage, working_mode_list[2]) self.assertEqual(working_mode_task_manage, working_mode_list[3]) self.assertEqual(working_mode_manage, working_mode_list[4]) elif command_status == False and working_mode_status == False: # self.assertEqual(comm_manager, command_list[0]) self.assertEqual(0, len(working_mode_list)) elif command_status == True and working_mode_status == False: self.assertEqual(send_command, command_list[0]) self.assertEqual(all_send_command, command_list[1]) # self.assertEqual(task_manage, command_list[2]) self.assertEqual(comm_manager, command_list[3]) self.assertEqual(0, len(working_mode_list)) elif command_status == False and working_mode_status == True: self.assertEqual(comm_manager, command_list[0]) self.assertEqual(working_mode, working_mode_list[0]) self.assertEqual(all_working_mode, working_mode_list[1]) self.assertEqual(template_manage, working_mode_list[2]) self.assertEqual(working_mode_task_manage, working_mode_list[3]) self.assertEqual(working_mode_manage, working_mode_list[4]) # 退出登录 sleep(1) self.log_in_base.click_account_center_button() sleep(2) self.account_center_page_navi_bar.usr_logout() break csv_file.close()