class TestCase164SportStatisticalAccFormOperation(unittest.TestCase): def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.statistical_form_page = StatisticalFormPage( self.driver, self.base_url) self.statistical_form_page_read_csv = StatisticalFormPageReadCsv() self.log_in_base = LogInBase(self.driver, self.base_url) # 打开页面,填写用户名、密码、点击登录 self.base_page.open_page() self.driver.set_window_max() self.driver.implicitly_wait(5) self.log_in_base.log_in_jimitest() # 登录之后点击控制台,然后点击设置 self.statistical_form_page.click_control_after_click_statistical_form_page( ) sleep(3) def tearDown(self): # 退出浏览器 self.driver.quit_browser() def test_case_sport_statistical_acc_form_operation(self): # 断言url expect_url_after_click_statistical_form = self.base_url + '/deviceReport/statisticalReport' self.assertEqual( expect_url_after_click_statistical_form, self.statistical_form_page.actual_url_after_statistical_form()) # 点击停留报表 self.statistical_form_page.click_acc_form_button() for n in range(5): self.statistical_form_page.click_customer_in_acc_form(n) # 点击搜索设备按钮 self.statistical_form_page.click_search_dev_button_in_acc_form() # 获取有多少组 number = self.statistical_form_page.get_group_number_in_acc_form() if number == 0: pass else: for m in range(number): # 收起默认组 self.statistical_form_page.click_defalut_group_in_acc_form( ) # 获取每个组设备的数量 dev_number = self.statistical_form_page.get_dev_number_in_acc_form( m) # 点开每一个分组 self.statistical_form_page.click_per_group_in_acc_form(m) dev_number_list = self.statistical_form_page.get_dev_number_list_in_acc_form( m) self.assertEqual(str(dev_number_list), dev_number)
class TestCase156SportStatisticalAccFormExceptionSearch(unittest.TestCase): def setUp(self): self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.statistical_form_page = StatisticalFormPage(self.driver, self.base_url) self.statistical_form_page2 = StatisticalFormPage2(self.driver, self.base_url) self.statistical_form_page_read_csv = StatisticalFormPageReadCsv() self.log_in_base = LogInBase(self.driver, self.base_url) self.assert_text = AssertText() # 打开页面,填写用户名、密码、点击登录 self.base_page.open_page() self.driver.set_window_max() self.driver.implicitly_wait(5) def test_acc_form_exception_search(self): """ acc报表页面,异常搜索数据验证 """ # 登录 self.log_in_base.log_in_jimitest() # 点击进入统计报表、acc报表 self.statistical_form_page.click_control_after_click_statistical_form_page() self.statistical_form_page.click_acc_form_button() # 取开始、结束时间 type = ["今天", "本周", "昨天", "上周", "本月", "上月", "自定义"] data = ["暂无数据"] for time in type: time = self.statistical_form_page2.acc_form_validation_time(time) self.assertEqual(time["page_time"]["page_start_time"], time["sql_time"]["sql_start_time"], "实际与显示的开始时间不相符") self.assertEqual(time["page_time"]["page_end_time"], time["sql_time"]["sql_end_time"], "实际与显示的结束时间不相符") # 验证提示 for user in data: text = self.statistical_form_page2.search_inexistence_user(user) print(text) self.assertIn(user, text, "搜索后的数据不存在实际搜索出的数据中") # 验证搜索下级的imei可以搜索到 # 填写下级的imei搜索 sleep(2) self.statistical_form_page2.input_imei_to_search_in_acc_form(self.statistical_form_page2.get_imei()) # 断言 # 获取查询设备的imei search_imei = self.statistical_form_page2.get_search_imei_in_acc_form() self.assertEqual(search_imei, self.statistical_form_page2.get_imei()) # 验证停机的设备无法搜索到 self.statistical_form_page2.input_imei_to_search_in_acc_form( self.statistical_form_page2.get_shut_down_imei()) # 获取搜索的数量 get_number_after_search = self.statistical_form_page.get_number_after_search_in_acc_form() self.assertEqual(0, get_number_after_search) get_text_after_search = self.statistical_form_page.get_text_after_search_in_acc_form() self.assertIn(self.assert_text.account_center_page_no_data_text(), get_text_after_search) # 验证未激活的设备无法搜索到 self.statistical_form_page2.input_imei_to_search_in_acc_form( self.statistical_form_page2.get_no_active_imei()) # 获取搜索的数量 get_number_after_search = self.statistical_form_page.get_number_after_search_in_acc_form() self.assertEqual(0, get_number_after_search) get_text_after_search = self.statistical_form_page.get_text_after_search_in_acc_form() self.assertIn(self.assert_text.account_center_page_no_data_text(), get_text_after_search) def tearDown(self): # 退出浏览器 self.driver.quit_browser()
class TestCase180SportStatisticalAccForm(unittest.TestCase): ''' 运动报表,acc报表 接口与页面数据对比 ''' def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.statistical_form_page = StatisticalFormPage(self.driver, self.base_url) self.statistical_form_page_read_csv = StatisticalFormPageReadCsv() self.log_in_base = LogInBase(self.driver, self.base_url) self.statistical_form_page3 = StatisticFormPage3(self.driver, self.base_url) self.statistical_form_page4 = StatisticFormPage4(self.driver, self.base_url) self.connect_sql = ConnectSql() self.assert_text = AssertText() self.search_sql = SearchSql(self.driver, self.base_url) # 打开页面,填写用户名、密码、点击登录 self.base_page.open_page() self.driver.set_window_max() self.driver.implicitly_wait(5) self.log_in_base.log_in_jimitest() # 登录之后点击控制台,然后点击设置 self.statistical_form_page.click_control_after_click_statistical_form_page() sleep(3) def tearDown(self): # 退出浏览器 self.driver.quit_browser() def test_case_sport_statistical_acc_form(self): # 断言url expect_url_after_click_statistical_form = self.base_url + '/deviceReport/statisticalReport' self.assertEqual(expect_url_after_click_statistical_form, self.statistical_form_page.actual_url_after_statistical_form()) # 点击停留报表 self.statistical_form_page.click_acc_form_button() # 断言 self.assertEqual(self.assert_text.statistical_form_acc_form(), self.statistical_form_page.actual_text_after_click_acc_button()) # 读数据 # 读取查询数据 csv_file = self.statistical_form_page_read_csv.read_csv('sport_statistical_acc_search_data2.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_user': row[0], 'status': row[1], 'choose_date': row[2], 'begin_time': row[3], 'end_time': row[4] } # 搜素数据+ self.statistical_form_page.add_data_to_search_acc_form(search_data) self.statistical_form_page.switch_to_acc_report_form_frame() total_page = self.statistical_form_page4.get_total_page_in_over_acc_form() begin_time = self.statistical_form_page4.get_over_acc_report_form_begin_time() end_time = self.statistical_form_page4.get_over_acc_report_form_end_time() acc_state = self.statistical_form_page4.get_over_acc_report_form_acc_state() all_dev = self.search_sql.search_current_account_equipment(search_data['search_user']) imeis = self.statistical_form_page3.change_dev_imei_format(all_dev) total_time = self.statistical_form_page4.get_total_time_in_over_acc_form() open_count = self.statistical_form_page4.get_total_time_in_open_count_acc_form() close_count = self.statistical_form_page4.get_total_time_in_close_count_acc_form() if total_page == 0: # 连接接口 request_url = request_base_url() request_params = { '_method_': 'getAccSegment', 'imeis': imeis, 'startTime': begin_time, 'endTime': end_time, 'acc': acc_state, } res = requests.post(request_url, data=request_params) sleep(30) response = res.json() self.assertEqual(400, response['code']) self.assertEqual('没有找到数据', response['msg']) elif total_page == 1: total_number_per_page = self.statistical_form_page4.get_total_number_per_page_in_over_acc_form() web_data = [] for n in range(total_number_per_page): web_data.append({ 'start': self.statistical_form_page4.get_start_time_in_over_acc_form(n), 'end': self.statistical_form_page4.get_end_time_in_over_acc_form(n), 'imei': self.statistical_form_page4.get_imei_in_over_acc_form(n), 'acc': int(self.statistical_form_page4.get_state_in_over_acc_form(n)), }) print("页面数据", web_data) print(len(web_data)) # 连接接口 request_url = request_base_url() request_params = { '_method_': 'getAccSegment', 'imeis': imeis, 'startTime': begin_time, 'endTime': end_time, 'acc': acc_state, } res = requests.post(request_url, data=request_params) sleep(30) response = res.json() res_data = response['data'] for data in res_data: del data['duration'] print("接口数据", res_data) print(len(res_data)) self.assertEqual(web_data, res_data) else: web_data = [] for i in range(total_page): # 循环点击每一页 self.statistical_form_page3.click_per_page_in_mile_report_form(i) total_number_per_page = self.statistical_form_page4.get_total_number_per_page_in_over_acc_form() for n in range(total_number_per_page): web_data.append({ 'start': self.statistical_form_page4.get_start_time_in_over_acc_form(n), 'end': self.statistical_form_page4.get_end_time_in_over_acc_form(n), 'imei': self.statistical_form_page4.get_imei_in_over_acc_form(n), 'acc': int(self.statistical_form_page4.get_state_in_over_acc_form(n)), }) print("页面数据", web_data) print(len(web_data)) # 连接接口 request_url = request_base_url() request_params = { '_method_': 'getAccSegment', 'imeis': imeis, 'startTime': begin_time, 'endTime': end_time, 'acc': acc_state, } res = requests.post(request_url, data=request_params) sleep(30) response = res.json() res_data = response['data'] for data in res_data: del data['duration'] print("接口数据", res_data) print(len(res_data)) self.assertEqual(web_data, res_data) # 总用时 # 连接接口 request_url = request_base_url() request_params = { '_method_': 'getAccSegmentSum', 'imeis': imeis, 'startTime': begin_time, 'endTime': end_time, 'acc': acc_state, } res = requests.post(request_url, data=request_params) sleep(20) response = res.json() print(response) try: res_data = response['data'] except: print("无数据") if total_time == "0": pass else: time = total_time.split("小时") print(time[0]) time2 = time[1].split("分") print(time2[0]) sec = time2[1].split("秒")[0] print(sec) web_total_time = (int(time[0]) * 60 * 60) + (int(time2[0]) * 60) + int(sec) print(web_total_time) self.assertEqual(web_total_time, res_data["duration"]) self.assertEqual(int(open_count), res_data["accOn"]) self.assertEqual(int(close_count), res_data["accOff"]) self.driver.default_frame() csv_file.close()
class TestCase708FormExportAccFormExport(unittest.TestCase): # 测试 报表 acc报表 - 导出 def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.statistical_form_page = StatisticalFormPage( self.driver, self.base_url) self.statistical_form_page_read_csv = StatisticalFormPageReadCsv() self.log_in_base = LogInBase(self.driver, self.base_url) self.connect_sql = ConnectSql() self.search_sql = SearchSql(self.driver, self.base_url) self.statistical_form_page3 = StatisticFormPage3( self.driver, self.base_url) self.assert_text = AssertText() self.form_page = FormPage(self.driver, self.base_url) self.page = Page(self.driver, self.base_url) self.form_export_page = FormExportPage(self.driver, self.base_url) self.statistical_form_page4 = StatisticFormPage4( self.driver, self.base_url) # 打开页面,填写用户名、密码、点击登录 self.base_page.open_page() self.driver.set_window_max() self.driver.implicitly_wait(5) self.driver.clear_cookies() self.log_in_base.log_in_jimitest() current_handle = self.driver.get_current_window_handle() self.statistical_form_page.click_control_after_click_statistical_form_page( ) sleep(3) self.base_page.change_windows_handle(current_handle) def tearDown(self): self.driver.close_window() # 退出浏览器 self.driver.quit_browser() def test_case_acc_form_export(self): # 断言url expect_url_after_click_statistical_form = self.base_url + '/deviceReport/statisticalReport' self.assertEqual( expect_url_after_click_statistical_form, self.statistical_form_page.actual_url_after_statistical_form()) # 断言 self.assertEqual( self.assert_text.statistical_form_sport_overview_form(), self.statistical_form_page.actual_text_after_click_sport_overview( )) # 切换到里程报表的frame self.statistical_form_page.click_acc_form_button() self.statistical_form_page.switch_to_acc_report_form_frame() # 搜索数据 self.form_export_page.search_acc_data() # 让其展示所有列 # 点击展示列 self.form_page.click_display_line_button_acc() # 获取有多少个展示列 display_line_number = self.form_page.get_display_line_number_acc() for n in range(display_line_number): # 获取每一个展示列是否被勾选 display_style = self.form_page.get_per_display_style_acc(n) if display_style == False: self.form_page.click_per_display_input_button_acc(n) self.form_page.click_display_line_button_acc() # 获取页面中的数据 web_data = [] total_page = self.statistical_form_page4.get_total_page_in_acc() if total_page == 0: pass else: if total_page == 1: total_number_per_page = self.statistical_form_page4.get_total_number_per_page_in_acc( ) for a in range(total_number_per_page): web_data.append( self.form_export_page.get_per_line_data_acc(a)) else: for x in range(total_page): self.statistical_form_page3.click_per_page_in_mile_report_form( x) total_number_per_page = self.statistical_form_page4.get_total_number_per_page_in_acc( ) for a in range(total_number_per_page): web_data.append( self.form_export_page.get_per_line_data_acc(a)) # 点击导出所有列 self.form_export_page.click_export_button_in_mileage() # 切换到导出的frame中 self.form_export_page.switch_export_frame() # 判断有多少个div的标签 export_div_number = self.form_export_page.get_sport_overview_export_div_number( ) for m in range(export_div_number - 2): # 获取基本信息和客户信息是否被勾选 input_style = self.form_export_page.get_input_style_select_in_sport_overview_export( m) if input_style == False: self.form_export_page.click_per_in_sport_overview_export(m) # 点击生成任务按钮 self.form_export_page.click_create_task_button_in_sport_overview_export_stay( ) # 查找刚刚导出的文件 file = self.form_export_page.find_expect_file() print(file) # 读excel文件 excel_data = self.form_export_page.read_excel_file_by_index( file, col_name_index=1) del excel_data[0] print('excel', excel_data) print('web', web_data) self.assertEqual(web_data, excel_data) self.driver.default_frame()
class TestCase506FormSearchAccSearch(unittest.TestCase): # 测试 报表 acc报表搜索功能 def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.statistical_form_page = StatisticalFormPage( self.driver, self.base_url) self.statistical_form_page_read_csv = StatisticalFormPageReadCsv() self.log_in_base = LogInBase(self.driver, self.base_url) self.connect_sql = ConnectSql() self.assert_text = AssertText() self.search_sql = SearchSql(self.driver, self.base_url) # 打开页面,填写用户名、密码、点击登录 self.base_page.open_page() self.driver.set_window_max() self.driver.implicitly_wait(5) self.log_in_base.log_in_jimitest() current_handle = self.driver.get_current_window_handle() self.statistical_form_page.click_control_after_click_statistical_form_page( ) sleep(3) self.base_page.change_windows_handle(current_handle) def tearDown(self): self.driver.close_window() # 退出浏览器 self.driver.quit_browser() def test_case_acc_search(self): # 断言url expect_url_after_click_statistical_form = self.base_url + '/deviceReport/statisticalReport' self.assertEqual( expect_url_after_click_statistical_form, self.statistical_form_page.actual_url_after_statistical_form()) # 点击停留报表 self.statistical_form_page.click_acc_form_button() # 断言 self.assertEqual( self.assert_text.statistical_form_acc_form(), self.statistical_form_page.actual_text_after_click_acc_button()) # 读数据 # 读取查询数据 csv_file = self.statistical_form_page_read_csv.read_csv( 'sport_statistical_acc_search_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_user': row[0], 'status': row[1], 'choose_date': row[2], 'begin_time': row[3], 'end_time': row[4] } self.statistical_form_page.add_data_to_search_acc_form(search_data) self.statistical_form_page.switch_to_acc_report_form_frame() all_dev = self.search_sql.search_current_account_equipment( search_data['search_user']) # 连接另一个数据库 connect_02 = self.connect_sql.connect_tuqiang_form() # 创建游标 cursor_02 = connect_02.cursor() # get_total_sql = self.search_sql.search_acc_sql(all_dev, search_data) get_total_sql_01 = self.search_sql.search_acc_sql_01( all_dev, search_data) get_total_sql_02 = self.search_sql.search_acc_sql_02( all_dev, search_data) get_total_sql_03 = self.search_sql.search_acc_sql_03( all_dev, search_data) get_total_sql_04 = self.search_sql.search_acc_sql_04( all_dev, search_data) get_total_sql_05 = self.search_sql.search_acc_sql_05( all_dev, search_data) get_total_sql_06 = self.search_sql.search_acc_sql_06( all_dev, search_data) get_total_sql_07 = self.search_sql.search_acc_sql_07( all_dev, search_data) get_total_sql_08 = self.search_sql.search_acc_sql_08( all_dev, search_data) get_total_sql_09 = self.search_sql.search_acc_sql_09( all_dev, search_data) get_total_sql_10 = self.search_sql.search_acc_sql_10( all_dev, search_data) get_total_sql_11 = self.search_sql.search_acc_sql_11( all_dev, search_data) get_total_sql_12 = self.search_sql.search_acc_sql_12( all_dev, search_data) print(get_total_sql_01) cursor_02.execute(get_total_sql_01) get_total_01 = cursor_02.fetchall() total_list_01 = [] for range1 in get_total_01: for range2 in range1: total_list_01.append(range2) get_total_list_01 = [] acc_open_list_01 = [] acc_close_list_01 = [] all_time_list_01 = [] for n in range(len(total_list_01)): if n % 3 == 0: get_total_list_01.append(total_list_01[n]) elif n % 3 == 1: if total_list_01[n] == 1: acc_open_list_01.append(total_list_01[n]) elif total_list_01[n] == 0: acc_close_list_01.append(total_list_01[n]) elif n % 3 == 2: all_time_list_01.append(total_list_01[n]) cursor_02.execute(get_total_sql_02) get_total_02 = cursor_02.fetchall() total_list_02 = [] for range1 in get_total_02: for range2 in range1: total_list_02.append(range2) get_total_list_02 = [] acc_open_list_02 = [] acc_close_list_02 = [] all_time_list_02 = [] for n in range(len(total_list_02)): if n % 3 == 0: get_total_list_02.append(total_list_02[n]) elif n % 3 == 1: if total_list_02[n] == 1: acc_open_list_02.append(total_list_02[n]) elif total_list_02[n] == 0: acc_close_list_02.append(total_list_02[n]) elif n % 3 == 2: all_time_list_02.append(total_list_02[n]) cursor_02.execute(get_total_sql_03) get_total_03 = cursor_02.fetchall() total_list_03 = [] for range1 in get_total_03: for range2 in range1: total_list_03.append(range2) get_total_list_03 = [] acc_open_list_03 = [] acc_close_list_03 = [] all_time_list_03 = [] for n in range(len(total_list_03)): if n % 3 == 0: get_total_list_03.append(total_list_03[n]) elif n % 3 == 1: if total_list_03[n] == 1: acc_open_list_03.append(total_list_03[n]) elif total_list_03[n] == 0: acc_close_list_03.append(total_list_03[n]) elif n % 3 == 2: all_time_list_03.append(total_list_03[n]) cursor_02.execute(get_total_sql_04) get_total_04 = cursor_02.fetchall() total_list_04 = [] for range1 in get_total_04: for range2 in range1: total_list_04.append(range2) get_total_list_04 = [] acc_open_list_04 = [] acc_close_list_04 = [] all_time_list_04 = [] for n in range(len(total_list_04)): if n % 3 == 0: get_total_list_04.append(total_list_04[n]) elif n % 3 == 1: if total_list_04[n] == 1: acc_open_list_04.append(total_list_04[n]) elif total_list_04[n] == 0: acc_close_list_04.append(total_list_04[n]) elif n % 3 == 2: all_time_list_04.append(total_list_04[n]) cursor_02.execute(get_total_sql_05) get_total_05 = cursor_02.fetchall() total_list_05 = [] for range1 in get_total_05: for range2 in range1: total_list_05.append(range2) get_total_list_05 = [] acc_open_list_05 = [] acc_close_list_05 = [] all_time_list_05 = [] for n in range(len(total_list_05)): if n % 3 == 0: get_total_list_05.append(total_list_05[n]) elif n % 3 == 1: if total_list_05[n] == 1: acc_open_list_05.append(total_list_05[n]) elif total_list_05[n] == 0: acc_close_list_05.append(total_list_05[n]) elif n % 3 == 2: all_time_list_05.append(total_list_05[n]) cursor_02.execute(get_total_sql_06) get_total_06 = cursor_02.fetchall() total_list_06 = [] for range1 in get_total_06: for range2 in range1: total_list_06.append(range2) get_total_list_06 = [] acc_open_list_06 = [] acc_close_list_06 = [] all_time_list_06 = [] for n in range(len(total_list_06)): if n % 3 == 0: get_total_list_06.append(total_list_06[n]) elif n % 3 == 1: if total_list_06[n] == 1: acc_open_list_06.append(total_list_06[n]) elif total_list_06[n] == 0: acc_close_list_06.append(total_list_06[n]) elif n % 3 == 2: all_time_list_06.append(total_list_06[n]) cursor_02.execute(get_total_sql_07) get_total_07 = cursor_02.fetchall() total_list_07 = [] for range1 in get_total_07: for range2 in range1: total_list_07.append(range2) get_total_list_07 = [] acc_open_list_07 = [] acc_close_list_07 = [] all_time_list_07 = [] for n in range(len(total_list_07)): if n % 3 == 0: get_total_list_07.append(total_list_07[n]) elif n % 3 == 1: if total_list_07[n] == 1: acc_open_list_07.append(total_list_07[n]) elif total_list_07[n] == 0: acc_close_list_07.append(total_list_07[n]) elif n % 3 == 2: all_time_list_07.append(total_list_07[n]) cursor_02.execute(get_total_sql_08) get_total_08 = cursor_02.fetchall() total_list_08 = [] for range1 in get_total_08: for range2 in range1: total_list_08.append(range2) get_total_list_08 = [] acc_open_list_08 = [] acc_close_list_08 = [] all_time_list_08 = [] for n in range(len(total_list_08)): if n % 3 == 0: get_total_list_08.append(total_list_08[n]) elif n % 3 == 1: if total_list_08[n] == 1: acc_open_list_08.append(total_list_08[n]) elif total_list_08[n] == 0: acc_close_list_08.append(total_list_08[n]) elif n % 3 == 2: all_time_list_08.append(total_list_08[n]) cursor_02.execute(get_total_sql_09) get_total_09 = cursor_02.fetchall() total_list_09 = [] for range1 in get_total_09: for range2 in range1: total_list_09.append(range2) get_total_list_09 = [] acc_open_list_09 = [] acc_close_list_09 = [] all_time_list_09 = [] for n in range(len(total_list_09)): if n % 3 == 0: get_total_list_09.append(total_list_09[n]) elif n % 3 == 1: if total_list_09[n] == 1: acc_open_list_09.append(total_list_09[n]) elif total_list_09[n] == 0: acc_close_list_09.append(total_list_09[n]) elif n % 3 == 2: all_time_list_09.append(total_list_09[n]) cursor_02.execute(get_total_sql_10) get_total_10 = cursor_02.fetchall() total_list_10 = [] for range1 in get_total_10: for range2 in range1: total_list_10.append(range2) get_total_list_10 = [] acc_open_list_10 = [] acc_close_list_10 = [] all_time_list_10 = [] for n in range(len(total_list_10)): if n % 3 == 0: get_total_list_10.append(total_list_10[n]) elif n % 3 == 1: if total_list_10[n] == 1: acc_open_list_10.append(total_list_10[n]) elif total_list_10[n] == 0: acc_close_list_10.append(total_list_10[n]) elif n % 3 == 2: all_time_list_10.append(total_list_10[n]) cursor_02.execute(get_total_sql_11) get_total_11 = cursor_02.fetchall() total_list_11 = [] for range1 in get_total_11: for range2 in range1: total_list_11.append(range2) get_total_list_11 = [] acc_open_list_11 = [] acc_close_list_11 = [] all_time_list_11 = [] for n in range(len(total_list_11)): if n % 3 == 0: get_total_list_11.append(total_list_11[n]) elif n % 3 == 1: if total_list_11[n] == 1: acc_open_list_11.append(total_list_11[n]) elif total_list_11[n] == 0: acc_close_list_11.append(total_list_11[n]) elif n % 3 == 2: all_time_list_11.append(total_list_11[n]) cursor_02.execute(get_total_sql_12) get_total_12 = cursor_02.fetchall() total_list_12 = [] for range1 in get_total_12: for range2 in range1: total_list_12.append(range2) get_total_list_12 = [] acc_open_list_12 = [] acc_close_list_12 = [] all_time_list_12 = [] for n in range(len(total_list_12)): if n % 3 == 0: get_total_list_12.append(total_list_12[n]) elif n % 3 == 1: if total_list_12[n] == 1: acc_open_list_12.append(total_list_12[n]) elif total_list_12[n] == 0: acc_close_list_12.append(total_list_12[n]) elif n % 3 == 2: all_time_list_12.append(total_list_12[n]) total = len(get_total_list_01) + len(get_total_list_02) + len( get_total_list_03) + len(get_total_list_04) + len( get_total_list_05) + len(get_total_list_06) + len( get_total_list_07) + len(get_total_list_08) + len( get_total_list_10) + len(get_total_list_11) + len( get_total_list_12) total_acc_open = len(acc_open_list_01) + len( acc_open_list_02) + len(acc_open_list_03) + len( acc_open_list_04) + len(acc_open_list_05) + len( acc_open_list_06) + len(acc_open_list_07) + len( acc_open_list_08) + len(acc_open_list_10) + len( acc_open_list_11) + len(acc_open_list_12) total_acc_close = len(acc_close_list_01) + len( acc_close_list_02) + len(acc_close_list_03) + len( acc_close_list_04) + len(acc_close_list_05) + len( acc_close_list_06) + len(acc_close_list_07) + len( acc_close_list_08) + len(acc_close_list_10) + len( acc_close_list_11) + len(acc_close_list_12) total_time = sum(all_time_list_01) + sum(all_time_list_02) + sum( all_time_list_03) + sum(all_time_list_04) + sum( all_time_list_05) + sum(all_time_list_06) + sum( all_time_list_07) + sum(all_time_list_08) + sum( all_time_list_10) + sum(all_time_list_11) + sum( all_time_list_12) # 断言总条数 web_total = self.statistical_form_page.get_total_search_acc_form_number( ) self.assertEqual(total, web_total) # 断言acc打开几次 web_acc_open_total = self.statistical_form_page.get_total_search_acc_open( ) self.assertEqual(str(total_acc_open), web_acc_open_total) # 断言acc关闭几次 web_acc_close_total = self.statistical_form_page.get_total_search_acc_close( ) self.assertEqual(str(total_acc_close), web_acc_close_total) # 断言总时间 total_times = self.statistical_form_page.change_sec_time( total_time) web_all_time_total = self.statistical_form_page.get_total_search_all_time( ) self.assertEqual(total_times, web_all_time_total) # 点击导出报表 self.driver.default_frame() cursor_02.close() connect_02.close() csv_file.close()
class TestCase194AccVerifyTheDisplayLine(unittest.TestCase): def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver() self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.statistical_form_page = StatisticalFormPage( self.driver, self.base_url) self.statistical_form_page3 = StatisticFormPage3( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.assert_text = AssertText() self.form_page = FormPage(self.driver, self.base_url) # 打开页面,填写用户名、密码、点击登录 self.base_page.open_page() self.driver.set_window_max() self.driver.implicitly_wait(5) self.driver.clear_cookies() self.log_in_base.log_in_jimitest() # 登录之后点击控制台,然后点击设置 self.statistical_form_page.click_control_after_click_statistical_form_page( ) sleep(3) def tearDown(self): # 退出浏览器 self.driver.quit_browser() def test_case_194_acc_verify_the_display_line(self): # 断言url expect_url_after_click_statistical_form = self.base_url + '/deviceReport/statisticalReport' self.assertEqual( expect_url_after_click_statistical_form, self.statistical_form_page.actual_url_after_statistical_form()) # 断言 self.assertEqual( self.assert_text.statistical_form_sport_overview_form(), self.statistical_form_page.actual_text_after_click_sport_overview( )) self.statistical_form_page.click_acc_form_button() self.statistical_form_page.switch_to_acc_report_form_frame() # 点击展示列 self.form_page.click_display_line_button_acc() # 获取有多少个展示列 display_line_number = self.form_page.get_display_line_number_acc() self.form_page.click_display_line_button_acc() for n in range(display_line_number): # 获取每一个展示列是否被勾选 self.form_page.click_display_line_button_acc() display_style = self.form_page.get_per_display_style_acc(n) display_line_name = self.form_page.get_per_display_name_acc(n) # 点击 self.form_page.click_per_display_input_button_acc(n) # 点击展示列 self.form_page.click_display_line_button_acc() # 获取展示列数量 display_line_name_list = [] display_line_name_number = self.form_page.get_display_line_name_number_acc( ) for m in range(display_line_name_number): display_name = self.form_page.get_per_display_name_on_line_acc( m) display_line_name_list.append(display_name) if display_style == True: self.assertNotIn(display_line_name, display_line_name_list) elif display_style == False: self.assertIn(display_line_name, display_line_name_list) self.driver.default_frame()