class TestCase56CommandManagerAbnormalStateSendCommand(unittest.TestCase): """ 异常状态imei下发模板 """ # author:邓肖斌 def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.command_management_page_read_csv = CommandManagementPageReadCsv() self.assert_text = AssertText() # 打开页面,填写用户名、密码、点击登录 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.command_management_page.click_control_after_click_command_management( ) sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_command_manage_abnormal_state_send_command(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual( expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type( ) self.assertEqual( expect_title_text_after_click_command_management, self.command_management_page. actual_title_text_after_click_command_management()) # 点击工作模式模板管理 self.command_management_page.click_lift_list( 'work_type_template_management') # 断言右侧页面的title文本 expect_title_text_after_click_work_type_template_management = \ self.assert_text.command_manager_page_work_type_template_management() self.assertEqual( expect_title_text_after_click_work_type_template_management, self.command_management_page. actual_title_text_after_click_work_type_template_management()) # 点击下发指令 self.command_management_page.click_send_command() # 读取数据 csv_file = self.command_management_page_read_csv.read_csv( "send_command_with_abnormal_dev.csv") csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue abnormal_state_data = {"state": row[0]} # 下发指令并获取文本 send_command_text = self.command_management_page. \ get_text_after_send_command_with_abnormal_dev(abnormal_state_data["state"]) # 断言 self.assertEqual( send_command_text, self.assert_text.text_with_abnormal_dev_send_command( abnormal_state_data["state"])) # 关闭提示框 self.command_management_page.close_send_command_fail_frame() csv_file.close()
class TestCase52CommandManageCreateTemplate(unittest.TestCase): """ 创建模板异常操作--上报周期为定时模式 """ # author:邓肖斌 driver = None base_url = None base_page = None log_in_page = None command_management_page = None def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.command_management_page_read_csv = CommandManagementPageReadCsv() self.assert_text = AssertText() # 打开页面,填写用户名、密码、点击登录 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() # 登录之后点击控制台,然后点击指令管理 self.command_management_page.click_control_after_click_command_management( ) sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_command_manage_create_template(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual( expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type( ) self.assertEqual( expect_title_text_after_click_command_management, self.command_management_page. actual_title_text_after_click_command_management()) # 点击工作模式模板管理 self.command_management_page.click_lift_list( 'work_type_template_management') # 断言右侧页面的title文本 expect_title_text_after_click_work_type_template_management = \ self.assert_text.command_manager_page_work_type_template_management() self.assertEqual( expect_title_text_after_click_work_type_template_management, self.command_management_page. actual_title_text_after_click_work_type_template_management()) # 点击创建模板 self.command_management_page.click_create_template() # 断言打开的创建模板的title文本 expect_title_text_after_click_create_template = self.assert_text.command_manager_page_new_command_text( ) self.assertEqual( expect_title_text_after_click_create_template, self.command_management_page. actual_title_text_after_click_create_template()) # 验证创建模板的提示语 template_name = self.command_management_page.get_create_template_name_text( ) self.assertEqual(self.assert_text.command_manager_page_template_name(), template_name) # 验证定时模式下输入框的规则 # 模板名称 1 为空 self.command_management_page.add_template_name_in_create_template('') self.command_management_page.click_ensure() get_name_text_fail = self.command_management_page.get_text_after_click_ensure( ) self.assertEqual(self.assert_text.command_manager_page_not_null(), get_name_text_fail) # 上班时间 为空 self.command_management_page.click_ensure() get_report_time_text_fail = self.command_management_page.get_report_time_text_fail( ) self.assertEqual(self.assert_text.command_manager_page_not_null(), get_report_time_text_fail) # 循环上报天数 为空 self.command_management_page.click_ensure() get_circulation_report_time_text_fail = self.command_management_page.get_circulation_report_time_text_fail( ) self.assertEqual(self.assert_text.command_manager_page_not_null(), get_circulation_report_time_text_fail) # 非正整数 self.command_management_page.add_circulation_report_time('sssa') self.command_management_page.click_ensure() get_circulation_report_time_text_fail = self.command_management_page.get_circulation_report_time_text_fail( ) self.assertEqual( self.assert_text.command_manager_page_must_be_integer(), get_circulation_report_time_text_fail) # 大于90 self.command_management_page.add_circulation_report_time('91') self.command_management_page.click_ensure() get_circulation_report_time_text_fail = self.command_management_page.get_circulation_report_time_text_fail( ) self.assertEqual(self.assert_text.command_manager_page_must_than_90(), get_circulation_report_time_text_fail) # 大于90且非正整数 self.command_management_page.add_circulation_report_time('91fdsf') self.command_management_page.click_ensure() get_circulation_report_time_text_fail = self.command_management_page.get_circulation_report_time_text_fail( ) get_circulation_report_time_texts_fail = self.command_management_page.get_circulation_report_time_texts_fail( ) self.assertEqual( self.assert_text.command_manager_page_must_than_90() + self.assert_text.command_manager_page_must_be_integer(), get_circulation_report_time_text_fail + get_circulation_report_time_texts_fail) # 点击添加 self.command_management_page.click_add_user_defined_template() # 验证是否添加成功 number = self.command_management_page.get_total_number_template() self.assertEqual(2, number) # 点击删除 self.command_management_page.click_delete_user_defined_template() number = self.command_management_page.get_total_number_template() self.assertEqual(1, number)
class TestCase55CommandManageCreateTemplateModifyTemplate(unittest.TestCase): driver = None base_url = None base_page = None log_in_page = None command_management_page = None def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.command_management_page_read_csv = CommandManagementPageReadCsv() self.assert_text = AssertText() # 打开页面,填写用户名、密码、点击登录 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() # 登录之后点击控制台,然后点击指令管理 self.command_management_page.click_control_after_click_command_management( ) sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_command_manage_create_template_modify_template(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual( expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type( ) self.assertEqual( expect_title_text_after_click_command_management, self.command_management_page. actual_title_text_after_click_command_management()) # 点击工作模式模板管理 self.command_management_page.click_lift_list( 'work_type_template_management') # 断言右侧页面的title文本 expect_title_text_after_click_work_type_template_management = \ self.assert_text.command_manager_page_work_type_template_management() self.assertEqual( expect_title_text_after_click_work_type_template_management, self.command_management_page. actual_title_text_after_click_work_type_template_management()) # 获取第一个模板的名称 get_template_name = self.command_management_page.get_template_name() print('当前模板名称为:%s' % get_template_name) # 点击修改模板 self.command_management_page.click_modify_template_button() # 获取点击修改后的模板名称 get_template_name_again = self.command_management_page.get_template_name_again( ) print('修改之后的模板名称为:%s' % get_template_name_again) self.assertIn(get_template_name, get_template_name_again) self.command_management_page.add_template_name_in_create_template('') self.command_management_page.click_ensure() get_name_text_fail = self.command_management_page.get_text_after_click_ensure( ) self.assertEqual(self.assert_text.command_manager_page_not_null(), get_name_text_fail)
class TestCase48IssuedWorkTypeManagementOperation(unittest.TestCase): """ 下发工作模式管理的操作 """ # author:邓肖斌 driver = None base_url = None base_page = None log_in_page = None command_management_page = None def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage( self.driver, self.base_url) 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) self.driver.clear_cookies() self.log_in_base.log_in_jimitest() # 登录之后点击控制台,然后点击指令管理 self.command_management_page.click_control_after_click_command_management( ) sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_issued_work_type_management_operation(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual( expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type( ) self.assertEqual( expect_title_text_after_click_command_management, self.command_management_page. actual_title_text_after_click_command_management()) # 点击下发工作模式管理 self.command_management_page.click_lift_list( 'issued_work_type_management') # 断言 expect_title_text_click_issued_work_type = self.assert_text.command_manager_page_issued_work_type( ) self.assertEqual( expect_title_text_click_issued_work_type, self.command_management_page.actual_text_click_look_equipment()) # 点击查看 self.command_management_page.click_look_issued_work_type() # 断言 expect_title_text_after_click_look_issued = self.assert_text.command_manager_page_issued_work_look_type( ) self.assertEqual( expect_title_text_after_click_look_issued, self.command_management_page.actual_text_after_click_look_issued()) # 点击关闭查看 self.command_management_page.click_close_look_issued_work_type() # 断言 self.assertEqual( expect_title_text_click_issued_work_type, self.command_management_page.actual_text_click_look_equipment())
class TestCase309SetUpIssuedCommandTaskManagementSearch(unittest.TestCase): # 测试 设置 - 指令管理 - 下发指令任务管理的搜索功能 driver = None base_url = None base_page = None log_in_page = None command_management_page = None base_paging_function = None def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage(self.driver, self.base_url) self.base_paging_function = BasePagingFunction(self.driver, self.base_url) self.command_management_page_read_csv = CommandManagementPageReadCsv() self.connect_sql = ConnectSql() self.log_in_base = LogInBase(self.driver, self.base_url) self.search_sql = SearchSql() self.assert_text = AssertText() # 打开页面,填写用户名、密码、点击登录 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() self.log_in_base.click_account_center_button() self.current_account = self.log_in_base.get_log_in_account() # 登录之后点击控制台,然后点击指令管理 self.command_management_page.click_control_after_click_command_management() sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_set_up_issued_command_task_management_search(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual(expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type() self.assertEqual(expect_title_text_after_click_command_management, self.command_management_page.actual_title_text_after_click_command_management()) # 点击下发任务指令管理 self.command_management_page.click_lift_list('issued_command_task_management') # 断言 expect_title_text_after_click_issued_command_task_management = \ self.assert_text.command_manager_page_issued_command_task() self.assertEqual(expect_title_text_after_click_issued_command_task_management, self.command_management_page.actual_text_after_click_issued_command_task()) csv_file = self.command_management_page_read_csv.read_csv('issued_command_task_management_serach_data.csv') csv_data = csv.reader(csv_file) i = 1 is_header = True for row in csv_data: if is_header: is_header = False continue search_data = { 'batch': row[0], 'name': row[1] } print(search_data) self.command_management_page.issued_command_task_add_data_to_search(search_data) '''# 建立数据库的连接 connect = self.connect_sql.connect_tuqiang_sql() # 建立游标 cursor = connect.cursor() # 查询登录用户的ID 和 父ID get_current_user_id = \ "select o.userId,o.fullParentId from user_info o where o.account = '" + self.current_account + "';" # 执行 cursor.execute(get_current_user_id) user = cursor.fetchall() for row1 in user: user_info = { 'id': row1[0], 'fullparent': row1[1] } # 查询当前登录用户的全部下级 get_next_id_sql = "select userId from user_info where fullParentId like" + \ "'" + user_info["fullparent"] + user_info["id"] + "%'" + ";" # 执行sql脚本 cursor.execute(get_next_id_sql) current_account = cursor.fetchall() current_account_list = [user_info['id']] for range1 in current_account: for range2 in range1: current_account_list.append(range2) current_user_next = tuple(current_account_list) print(current_user_next) # 查询数据库''' # 执行sql user_info = self.command_management_page.get_current_user_id(self.current_account) all_user_id = self.command_management_page.get_all_user_id(user_info) connect = self.connect_sql.connect_tuqiang_sql() cursor = connect.cursor() search_sql = self.search_sql.search_issued_command_task_management_sql(all_user_id, search_data) print(search_sql) cursor.execute(search_sql) current_total = cursor.fetchall() cursor.close() connect.close() total = len(current_total) web_total = self.command_management_page.search_total_number_with_issued_command_task() # 断言 print('第%s次sql查询的结果是%s' % (i, total)) print('第%s次web查询的结果是%s' % (i, web_total)) i += 1 self.assertEqual(total, web_total) csv_file.close()
class TestCase51IssuedCommandManagementSearch(unittest.TestCase): """ 下发指令管理页面的搜索 """ # author:邓肖斌 driver = None base_url = None base_page = None log_in_page = None command_management_page = None base_paging_function = None def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage( self.driver, self.base_url) self.base_paging_function = BasePagingFunction(self.driver, self.base_url) self.command_management_page_read_csv = CommandManagementPageReadCsv() self.connect_sql = ConnectSql() 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) self.driver.clear_cookies() self.log_in_base.log_in_jimitest() self.log_in_base.click_account_center_button() self.current_account = self.log_in_base.get_log_in_account() # 登录之后点击控制台,然后点击指令管理 self.command_management_page.click_control_after_click_command_management( ) sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_issued_command_management_search(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual( expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type( ) self.assertEqual( expect_title_text_after_click_command_management, self.command_management_page. actual_title_text_after_click_command_management()) # 点击下发指令管理 self.command_management_page.click_lift_list( 'issued_command_management') # 断言 expect_title_text = self.assert_text.command_manager_page_issued_command_manager( ) self.assertEqual( expect_title_text, self.command_management_page. actual_text_after_click_look_equipment()) # 读csv csv_file = self.command_management_page_read_csv.read_csv( 'issued_command_management_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 = {'imei': row[0], 'batch': row[1], 'statue': row[2]} # 添加搜索添加搜索 self.command_management_page.issued_command_management_search_data( search_data) # 连接数据库 connect = self.connect_sql.connect_tuqiang_sql() # 建立游标 cursor = connect.cursor() # 查询登录用户的ID 和 父ID get_current_user_id_sql = \ "select o.userId,o.fullParentId from user_info o where o.account = '" + self.current_account + "';" # 执行 cursor.execute(get_current_user_id_sql) user = cursor.fetchall() print(user) for row1 in user: user_info = {'id': row1[0], 'fullparent': row1[1]} # 判断搜索条件 get_sql = self.command_management_page. \ search_sql_for_issued_command_management_search(user_info['id'], search_data) # 执行sql print(get_sql) cursor.execute(get_sql) current_total = cursor.fetchall() total_list = [] for range1 in current_total: for range2 in range1: total_list.append(range2) total_num = len(total_list) web_total = self.command_management_page.search_total_number_issued_command_management( ) print("网页搜索数量:'%s'" % web_total) print("数据库搜索结果:'%s'" % total_num) self.assertEqual(total_num, web_total) cursor.close() connect.close()
class TestCase43WorkTypeTemplateManagementCreatTemplate(unittest.TestCase): """ 创建模板 """ # author:邓肖斌 driver = None base_url = None base_page = None log_in_page = None command_management_page = None def setUp(self): # 前置条件 # 实例化对象 self.driver = AutomateDriver(choose='firefox') self.base_url = self.driver.base_url self.base_page = BasePage(self.driver, self.base_url) self.command_management_page = CommandManagementPage( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.command_management_page_read_csv = CommandManagementPageReadCsv() self.assert_text = AssertText() # 打开页面,填写用户名、密码、点击登录 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() # 登录之后点击控制台,然后点击指令管理 self.command_management_page.click_control_after_click_command_management( ) sleep(3) def tearDown(self): self.driver.quit_browser() def test_case_work_type_template_management_creat_template(self): # 断言url expect_url_after_click_command_management = self.base_url + '/custom/toTemplate' self.assertEqual( expect_url_after_click_command_management, self.command_management_page.actual_url_click_command_management()) # 断言左侧列表的title文本 expect_title_text_after_click_command_management = self.assert_text.command_manager_page_command_type( ) self.assertEqual( expect_title_text_after_click_command_management, self.command_management_page. actual_title_text_after_click_command_management()) # 点击工作模式模板管理 self.command_management_page.click_lift_list( 'work_type_template_management') # 断言右侧页面的title文本 expect_title_text_after_click_work_type_template_management = \ self.assert_text.command_manager_page_work_type_template_management() self.assertEqual( expect_title_text_after_click_work_type_template_management, self.command_management_page. actual_title_text_after_click_work_type_template_management()) # 点击创建模板 self.command_management_page.click_create_template() # 断言打开的创建模板的title文本 expect_title_text_after_click_create_template = self.assert_text.command_manager_page_new_command_text( ) self.assertEqual( expect_title_text_after_click_create_template, self.command_management_page. actual_title_text_after_click_create_template()) # 关闭创建模板 self.command_management_page.click_close_create_template() # 断言是否关闭成功 self.assertEqual( expect_title_text_after_click_work_type_template_management, self.command_management_page. actual_title_text_after_click_work_type_template_management()) # 点击创建模板 self.command_management_page.click_create_template() # 断言打开的创建模板的title文本 self.assertEqual( expect_title_text_after_click_create_template, self.command_management_page. actual_title_text_after_click_create_template()) # 取消创建模板 self.command_management_page.click_cancel_create_template() # 断言是否关闭成功 self.assertEqual( expect_title_text_after_click_work_type_template_management, self.command_management_page. actual_title_text_after_click_work_type_template_management()) # 输入参数 csv_file = self.command_management_page_read_csv.read_csv( 'work_template_time_data.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue work_template_time_data = { 'name': row[0], 'type': row[1], 'day': row[2], 'circulation': row[3], 'circulation_day': row[4], 'week': row[5], 'circulation1': row[6], 'circulation_day1': row[7], 'jiange': row[8], 'circulation2': row[9], 'circulation_day2': row[10], } # 点击创建模板 self.command_management_page.click_create_template() # 断言打开的创建模板的title文本 self.assertEqual( expect_title_text_after_click_create_template, self.command_management_page. actual_title_text_after_click_create_template()) sleep(5) self.command_management_page.add_create_template_data( work_template_time_data) # 点击保存 self.command_management_page.create_template_click_ensure() sleep(2) # 点击删除 self.command_management_page.delete_add_new_template() csv_file.close()