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 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)
class TestCase713FormExportOBDTroubleFormExport(unittest.TestCase): # 测试 obd报表 故障报表 - 导出 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_obd_trouble_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_obd_trouble_form() self.statistical_form_page.switch_to_obd_trouble_frame() # 搜索数据 self.form_export_page.search_obd_trouble_data() # 让其展示所有列 # 点击展示列 self.form_page.click_display_line_button_obd_failure() # 获取有多少个展示列 display_line_number = self.form_page.get_display_line_name_number_obd_failure( ) print(display_line_number) for n in range(display_line_number): # 获取每一个展示列是否被勾选 display_style = self.form_page.get_per_display_style_obd_failure(n) if display_style == False: self.form_page.click_per_display_input_button_obd_failure(n) self.form_page.click_display_line_button_obd_failure() # 获取页面中的数据 web_data = [] total_page = self.statistical_form_page4.get_total_page_in_obd_car_condition( ) if total_page == 0: pass else: if total_page == 1: total_number_per_page = self.statistical_form_page4.get_total_number_per_page_in_obd_car_condition( ) for a in range(total_number_per_page): web_data.append( self.form_export_page.get_per_line_data_obd_trouble(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_obd_car_condition( ) for a in range(total_number_per_page): web_data.append( self.form_export_page. get_per_line_data_obd_trouble(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, n=0) del excel_data[0] print('excel', excel_data) print('web', web_data) self.assertEqual(web_data, excel_data) self.driver.default_frame()
class TestCase197OilVerifyTheDisplayLine(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_197_oil_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_oil_reoport() self.statistical_form_page.switch_to_oil_report() # 点击展示列 self.form_page.click_display_line_button_oil() # 获取有多少个展示列 display_line_number = self.form_page.get_display_line_number_oil() self.form_page.click_display_line_button_oil() for n in range(display_line_number): # 获取每一个展示列是否被勾选 self.form_page.click_display_line_button_oil() display_style = self.form_page.get_per_display_style_oil(n) display_style_list = [] for n1 in range(display_line_number): display_styles = self.form_page.get_per_display_style_oil(n1) if display_styles == True: display_style_list.append(display_styles) display_line_name = self.form_page.get_per_display_name_oil(n) # 点击 self.form_page.click_per_display_input_button_oil(n) # 点击展示列 self.form_page.click_display_line_button_oil() # 获取展示列数量 display_line_name_list = [] display_line_name_number = self.form_page.get_display_line_name_number_oil( ) for m in range(display_line_name_number): display_name = self.form_page.get_per_display_name_on_line_oil( m) display_line_name_list.append(display_name) if len(display_style_list) == 1: self.assertIn(display_line_name, display_line_name_list) else: 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()
class TestCase701FormExportSportOverviewExport(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.connect_sql = ConnectSql() self.search_sql = SearchSql(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.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_sport_overview_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.switch_to_sport_overview_form_frame() # 点击搜索按钮 self.form_export_page.click_search_button_in_sport_overview() # 让其展示所有列 # 点击展示列 self.form_page.click_display_line_button_sport_overview() # 获取有多少个展示列 display_line_number = self.form_page.get_display_line_number_sport_overview( ) for n in range(display_line_number): # 获取每一个展示列是否被勾选 display_style = self.form_page.get_per_display_style_sport_overview( n) if display_style == False: self.form_page.click_per_display_input_button(n) self.form_page.click_display_line_button_sport_overview() # 获取页面中的数据 data_total_number = self.form_export_page.get_data_total_number_in_sport_overview( ) web_data = [] for i in range(data_total_number): web_data.append(self.form_export_page.get_per_line_data(i)) print('web', web_data) # 点击导出所有列 self.form_export_page.click_export_button_in_sport_overview() # 判断有多少个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( ) # 查找刚刚导出的文件 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) self.assertEqual(web_data, excel_data) self.driver.default_frame()
class TestCase701FormExportSportOverviewExport(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.connect_sql = ConnectSql() self.search_sql = SearchSql(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.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_sport_overview_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.switch_to_sport_overview_form_frame() # 点击搜索按钮 self.form_export_page.click_search_button_in_sport_overview() # 让其展示所有列 # 点击展示列 self.form_page.click_display_line_button_sport_overview() # 获取有多少个展示列 display_line_number = self.form_page.get_display_line_number_sport_overview( ) for n in range(display_line_number): # 获取每一个展示列是否被勾选 display_style = self.form_page.get_per_display_style_sport_overview( n) if display_style == False: self.form_page.click_per_display_input_button(n) self.form_page.click_display_line_button_sport_overview() # 获取页面中的数据 data_total_number = self.form_export_page.get_data_total_number_in_sport_overview( ) web_data = [] for i in range(data_total_number): web_data.append(self.form_export_page.get_per_line_data(i)) print('web', web_data) l_data = [[ '序号', '所属账号', '客户名称', '设备名称', 'imei', '型号', '设备分组', '总里程(KM)', '超速(次)', '停留(次)', '司机名称', '电话', '车牌号', '身份证号', '车架号', '电动机/发动机号' ]] for m in web_data: l_data.append([ m['序号'], m['所属账号'], m['客户名称'], m['设备名称'], m['IMEI'], m['型号'], m['设备分组'], m['总里程(KM)'], m['超速(次)'], m['停留(次)'], m['司机名称'], m['电话'], m['车牌号'], m['身份证号'], m['车架号'], m['电动机/发动机号'] ]) print(l_data) write_excel('add', l_data) self.driver.default_frame()