class TestCase91DevManageShutDownByNextUser(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.dev_manage_page = DevManagePages(self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBase(self.driver, self.base_url) self.dev_manage_page_read_csv = DevManagePageReadCsv() 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_case_dev_manage_shut_down_by_next_user(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() # 点击进入设备管理 self.dev_manage_page.enter_dev_manage() # 搜索下级客户 csv_file = self.dev_manage_page_read_csv.read_csv("search_account.csv") csv_data = csv.reader(csv_file) for row in csv_data: self.data = {'acc': row[0]} # 输入用户名搜索 self.dev_manage_page.search_account(self.data['acc']) # 勾选包含下级,搜索 self.dev_manage_page.search_dev() # 测试选中停机 self.dev_manage_page.click_dev_in_list() # 点击选中停机 self.dev_manage_page.click_select_shut_down() # 点击确定 self.dev_manage_page.click_ensure() sleep(4) get_dev_status = self.dev_manage_page.get_dev_status_in_list() self.assertEqual(self.assert_text.dev_page_closing_down(), get_dev_status) # 点击选中停机 self.dev_manage_page.click_dev_in_list() self.dev_manage_page.click_select_shut_down() # 点击取消 self.dev_manage_page.click_cancel() get_dev_status = self.dev_manage_page.get_dev_status_in_list() self.assertEqual(self.assert_text.dev_page_closing_down(), get_dev_status) # 点击选中停机 self.dev_manage_page.click_select_shut_down() # 点击关闭 self.dev_manage_page.click_close() get_dev_status = self.dev_manage_page.get_dev_status_in_list() self.assertEqual(self.assert_text.dev_page_closing_down(), get_dev_status) # 点击本次查询全部停机 self.dev_manage_page.click_all_shut_down() self.dev_manage_page.click_ensure() sleep(4) # 断言 get_all_page = self.dev_manage_page.get_all_pages() if get_all_page == 0: pass elif get_all_page == 1: per_number = self.dev_manage_page.get_per_number() for m in range(per_number): text = self.dev_manage_page.get_text_dev_status(m + 1) self.assertEqual(self.assert_text.dev_page_closing_down(), text) else: for n in range(get_all_page): self.dev_manage_page.click_per_page(n + 1) sleep(2) # 获取当前页面有多少条 per_number = self.dev_manage_page.get_per_number() for m in range(per_number): text = self.dev_manage_page.get_text_dev_status(m + 1) self.assertEqual(self.assert_text.dev_page_closing_down(), text)
class TestCase76DevManageDevOperationNOActiveAndStop(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.dev_manage_page = DevManagePages(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPages( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.dev_manage_page_read_csv = DevManagePageReadCsv() self.connect_sql = ConnectSql() self.search_sql = SearchSql() 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_dev_manage_dev_operation_noactive_and_stop(self): # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() self.dev_manage_page.enter_dev_manage() # 选择已激活和开机的设备 self.dev_manage_page.choose_dev_noactive_and_stop() self.dev_manage_page.click_ensure() sleep(4) imei = self.dev_manage_page.get_imei_number() self.dev_manage_page.click_edit_button() self.dev_manage_page.click_close_edit_button() self.dev_manage_page.click_edit_button() csv_file = self.dev_manage_page_read_csv.read_csv( 'dev_operation_data.csv') csv_data = csv.reader(csv_file) for row in csv_data: self.data = { 'dev_name': row[0], 'sim': row[1], 'mark': row[2], 'd_name': row[3], 'd_phone': row[4], 'plate_numbers': row[5], 'iccid': row[6], 'sn': row[7], 'vin': row[8], 'engine_number': row[9], 'install_time': row[10], 'install_adress': row[11], 'install_comp': row[12], 'install_preson': row[13] } self.dev_manage_page.add_data_to_edit_dev_detila(self.data) # 验证是否修改成功 sleep(4) text = self.dev_manage_page.get_dev_name() self.assertEqual(self.data['dev_name'], text) csv_file.close() # 点击查看位置 current_handle = self.driver.get_current_window_handle() self.dev_manage_page.click_look_place_button() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.base_url + "/console" self.assertEqual(expect_url, self.driver.get_current_url()) # dev_name = self.dev_manage_page.get_dev_name_after_click_console() # self.assertEqual(self.data['dev_name'], dev_name) self.driver.close_current_page() self.driver.switch_to_window(current_handle) sleep(2)
class TestCase71DevManageDevSearchByIMEI(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.dev_manage_page = DevManagePages(self.driver, self.base_url) self.driver.set_window_max() self.log_in_base = LogInBase(self.driver, self.base_url) self.dev_manage_page_read_csv = DevManagePageReadCsv() self.assert_text = AssertText() self.driver.wait(1) self.driver.clear_cookies() self.driver.wait(1) # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() def tearDown(self): self.driver.quit_browser() def test_dev_manage_dev_search_by_imei(self): '''测试设备管理-设备搜索-by imei''' # 点击进入设备管理 self.dev_manage_page.enter_dev_manage() csv_file = self.dev_manage_page_read_csv.read_csv( 'single_search_info.csv') csv_data = csv.reader(csv_file) for row in csv_data: search_info = { "imei": row[0], "dev_name": row[1], "login_user_dev_type": row[2], "user_select": row[3], "select_user_dev_type": row[4], "vehicle_number": row[5], "car_frame": row[6], "SIM": row[7], "active_start_time": row[8], "active_end_time": row[9], "plat_expired_start_time": row[10], "plat_expired_end_time": row[11], "dev_use_range": row[12] } # 输入imei self.dev_manage_page.input_imei(search_info["imei"]) # 搜索 self.dev_manage_page.click_search_btn() # 获取搜索结果的imei号 imei = self.dev_manage_page.get_search_result_imei() # 验证搜索结果imei与输入的imei是否一致 self.assertEqual(search_info["imei"], imei, "搜索结果imei与输入的imei不一致") csv_file.close() '''# 设备IMEI输入框输入选中用户的多个设备IMEI(以enter键隔开),点击搜索,点击导出
class TestCase75DevManageDevComplexSearch(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.dev_manage_page = DevManagePages(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPages( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.dev_manage_page_read_csv = DevManagePageReadCsv() self.connect_sql = ConnectSql() self.search_sql = SearchSql() 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_dev_manage_dev_complex_search(self): '''测试设备管理-设备搜索-by imei+设备名称+设备型号+车牌号+车架号+SIM''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() self.dev_manage_page.click_account_center_button() current_account = self.log_in_base.get_log_in_account() self.dev_manage_page.enter_dev_manage() self.dev_manage_page.click_more_button() csv_file = self.dev_manage_page_read_csv.read_csv( 'dev_search_info.csv') csv_data = csv.reader(csv_file) is_header = True for row in csv_data: if is_header: is_header = False continue search_data = { 'dev_name': row[0], 'dev_type': row[1], 'past_due': row[2], 'plate_numbers': row[3], 'frame_number': row[4], 'sim': row[5], 'active': row[6], 'choose_time': row[7], 'begin_time': row[8], 'end_time': row[9], 'next': row[10], 'band_status': row[11], 'dev_mold': row[12], 'dev_group': row[13], 'sn': row[14] } self.dev_manage_page.add_data_to_search_dev(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 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) lower_account_tuple = tuple(lower_account_list) get_total_sql = self.search_sql.search_dev_sql( user_relation_id['userId'], 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.dev_manage_page.get_dev_number() print('本次查询页面的条数是:%s' % web_total) self.assertEqual(total, web_total) cur.close() connect.close() csv_file.close()
class TestCase79DevManageDevOperationActiveAndStart(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.dev_manage_page = DevManagePages(self.driver, self.base_url) self.account_center_page_navi_bar = AccountCenterNaviBarPages( self.driver, self.base_url) self.log_in_base = LogInBase(self.driver, self.base_url) self.dev_manage_page_read_csv = DevManagePageReadCsv() self.connect_sql = ConnectSql() self.search_sql = SearchSql() 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_dev_manage_dev_operation_active_and_start(self): '''测试设备管理-设备搜索-by imei+设备名称+设备型号+车牌号+车架号+SIM''' # 打开途强在线首页-登录页 self.base_page.open_page() # 登录 self.log_in_base.log_in() self.dev_manage_page.enter_dev_manage() # 选择已激活和开机的设备 self.dev_manage_page.choose_dev_active_and_statr() self.dev_manage_page.click_ensure() imei = self.dev_manage_page.get_imei_number() self.dev_manage_page.click_edit_button() self.dev_manage_page.click_close_edit_button() self.dev_manage_page.click_edit_button() csv_file = self.dev_manage_page_read_csv.read_csv( 'dev_operation_data.csv') csv_data = csv.reader(csv_file) for row in csv_data: self.data = { 'dev_name': row[0], 'sim': row[1], 'mark': row[2], 'd_name': row[3], 'd_phone': row[4], 'plate_numbers': row[5], 'iccid': row[6], 'sn': row[7], 'vin': row[8], 'engine_number': row[9], 'install_time': row[10], 'install_adress': row[11], 'install_comp': row[12], 'install_preson': row[13] } self.dev_manage_page.add_data_to_edit_dev_detila(self.data) # 验证是否修改成功 sleep(3) text = self.dev_manage_page.get_dev_name() self.assertEqual(self.data['dev_name'], text) csv_file.close() # 点击查看位置 current_handle = self.driver.get_current_window_handle() self.dev_manage_page.click_look_place_button() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.base_url + "/console" self.assertEqual(expect_url, self.driver.get_current_url()) # dev_name = self.dev_manage_page.get_dev_name_after_click_console() # self.assertEqual(self.data['dev_name'], dev_name) self.driver.close_current_page() self.driver.switch_to_window(current_handle) sleep(2) # 点击轨迹回放 self.dev_manage_page.click_track_playback_button() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.base_url + "/trackreplay/locus?imei=%s" % imei self.assertEqual(expect_url, self.driver.get_current_url()) text = self.dev_manage_page.click_track_playback_get_text() self.assertEqual(self.assert_text.dev_page_track_replay_text(), text) self.driver.close_current_page() self.driver.switch_to_window(current_handle) sleep(2) # 点行车记录 self.dev_manage_page.click_driving_recond_button() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.base_url + "/drivingrecord/driving?imei=%s" % imei self.assertEqual(expect_url, self.driver.get_current_url()) text = self.dev_manage_page.click_driving_recond_get_text() self.assertEqual( self.assert_text.dev_page_driving_record_text(), text) self.driver.close_current_page() self.driver.switch_to_window(current_handle) sleep(2) # 点街景 self.dev_manage_page.click_street_scape_button() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.base_url + "/trackpreset/tracking/%s?isTracking=1" % imei self.assertEqual(expect_url, self.driver.get_current_url()) text = self.dev_manage_page.click_street_scape_get_text() self.assertIn(self.assert_text.dev_page_track_preset_text(), text) self.driver.close_current_page() self.driver.switch_to_window(current_handle) sleep(2) # 点查看告警 self.dev_manage_page.click_look_alarm_button() all_handles = self.driver.get_all_window_handles() for handle in all_handles: if handle != current_handle: self.driver.switch_to_window(handle) sleep(2) expect_url = self.base_url + "/deviceReport/statisticalReport" self.assertEqual(expect_url, self.driver.get_current_url()) text = self.dev_manage_page.click_look_alarm_get_text() self.assertEqual( self.assert_text.account_center_page_alarm_details_text(), text) self.driver.close_current_page() self.driver.switch_to_window(current_handle) sleep(2)