def setUp(self):
        # 前置条件
        # 实例化对象
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)

        self.alarm_info_page = AlarmInfoPage(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_page = StatisticalFormPage(self.driver, self.base_url)
        self.connect_sql = ConnectSql()
        self.statistical_form_page3 = StatisticFormPage3(self.driver, self.base_url)
        self.seasrch_sql = SearchSql(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.assert_text = AssertText()
        self.log_in_base.log_in_jimitest()
        # 登录之后点击控制台,然后点击指令管理
        self.statistical_form_page.click_control_after_click_statistical_form_page()
        sleep(3)
    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.statistical_form_page3 = StatisticFormPage3(
            self.driver, self.base_url)
        self.log_in_base = LogInBase(self.driver, self.base_url)
        self.connect_sql = ConnectSql()
        self.assert_text = AssertText()
        self.seasrch_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)
コード例 #3
0
class TestCase502FormSearchMileSearch(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.seasrch_sql = SearchSql(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.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_mile_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_mileage_form_buttons()
        # 断言
        self.assertEqual(
            self.assert_text.statistical_form_mile_form(),
            self.statistical_form_page.
            actual_text_after_click_mileage_form_buttons())

        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'milage_report_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],
                'type': row[1],
                'choose_date': row[2],
                'begin_time': row[3],
                'end_time': row[4]
            }
            self.statistical_form_page.add_datas_to_search_mileage_form(
                search_data)
            self.statistical_form_page.switch_to_mile_report_form_frame()

            # 连接数据库
            # 连接数据库
            all_dev = self.seasrch_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_01 = self.seasrch_sql.search_sport_mile_report_sql_01(
                all_dev, search_data)
            get_total_sql_02 = self.seasrch_sql.search_sport_mile_report_sql_02(
                all_dev, search_data)
            get_total_sql_03 = self.seasrch_sql.search_sport_mile_report_sql_03(
                all_dev, search_data)
            get_total_sql_04 = self.seasrch_sql.search_sport_mile_report_sql_04(
                all_dev, search_data)
            get_total_sql_05 = self.seasrch_sql.search_sport_mile_report_sql_05(
                all_dev, search_data)
            get_total_sql_06 = self.seasrch_sql.search_sport_mile_report_sql_06(
                all_dev, search_data)
            get_total_sql_07 = self.seasrch_sql.search_sport_mile_report_sql_07(
                all_dev, search_data)
            get_total_sql_08 = self.seasrch_sql.search_sport_mile_report_sql_08(
                all_dev, search_data)
            get_total_sql_09 = self.seasrch_sql.search_sport_mile_report_sql_09(
                all_dev, search_data)
            get_total_sql_10 = self.seasrch_sql.search_sport_mile_report_sql_10(
                all_dev, search_data)
            get_total_sql_11 = self.seasrch_sql.search_sport_mile_report_sql_11(
                all_dev, search_data)
            get_total_sql_12 = self.seasrch_sql.search_sport_mile_report_sql_12(
                all_dev, search_data)
            get_total_01 = self.seasrch_sql.search_sport_mile_report_sql_get_total_01(
                all_dev, search_data)
            get_total_02 = self.seasrch_sql.search_sport_mile_report_sql_get_total_02(
                all_dev, search_data)
            get_total_03 = self.seasrch_sql.search_sport_mile_report_sql_get_total_03(
                all_dev, search_data)
            get_total_04 = self.seasrch_sql.search_sport_mile_report_sql_get_total_04(
                all_dev, search_data)
            get_total_05 = self.seasrch_sql.search_sport_mile_report_sql_get_total_05(
                all_dev, search_data)
            get_total_06 = self.seasrch_sql.search_sport_mile_report_sql_get_total_06(
                all_dev, search_data)
            get_total_07 = self.seasrch_sql.search_sport_mile_report_sql_get_total_07(
                all_dev, search_data)
            get_total_08 = self.seasrch_sql.search_sport_mile_report_sql_get_total_08(
                all_dev, search_data)
            get_total_09 = self.seasrch_sql.search_sport_mile_report_sql_get_total_09(
                all_dev, search_data)
            get_total_10 = self.seasrch_sql.search_sport_mile_report_sql_get_total_10(
                all_dev, search_data)
            get_total_11 = self.seasrch_sql.search_sport_mile_report_sql_get_total_11(
                all_dev, search_data)
            get_total_12 = self.seasrch_sql.search_sport_mile_report_sql_get_total_12(
                all_dev, search_data)
            print(get_total_sql_01)
            print(get_total_01)

            # 判断查询的条件
            if search_data['type'] == 'mile':
                # 查询的选择里程
                cursor_02.execute(get_total_sql_01)
                get_all_mlie_and_time_01 = cursor_02.fetchall()
                get_all_mlie_and_time_list_01 = []
                for range1 in get_all_mlie_and_time_01:
                    for range2 in range1:
                        get_all_mlie_and_time_list_01.append(range2)

                cursor_02.execute(get_total_sql_02)
                get_all_mlie_and_time_02 = cursor_02.fetchall()
                get_all_mlie_and_time_list_02 = []
                for range1 in get_all_mlie_and_time_02:
                    for range2 in range1:
                        get_all_mlie_and_time_list_02.append(range2)

                cursor_02.execute(get_total_sql_03)
                get_all_mlie_and_time_03 = cursor_02.fetchall()
                get_all_mlie_and_time_list_03 = []
                for range1 in get_all_mlie_and_time_03:
                    for range2 in range1:
                        get_all_mlie_and_time_list_03.append(range2)

                cursor_02.execute(get_total_sql_04)
                get_all_mlie_and_time_04 = cursor_02.fetchall()
                get_all_mlie_and_time_list_04 = []
                for range1 in get_all_mlie_and_time_04:
                    for range2 in range1:
                        get_all_mlie_and_time_list_04.append(range2)

                cursor_02.execute(get_total_sql_05)
                get_all_mlie_and_time_05 = cursor_02.fetchall()
                get_all_mlie_and_time_list_05 = []
                for range1 in get_all_mlie_and_time_05:
                    for range2 in range1:
                        get_all_mlie_and_time_list_05.append(range2)

                cursor_02.execute(get_total_sql_06)
                get_all_mlie_and_time_06 = cursor_02.fetchall()
                get_all_mlie_and_time_list_06 = []
                for range1 in get_all_mlie_and_time_06:
                    for range2 in range1:
                        get_all_mlie_and_time_list_06.append(range2)

                cursor_02.execute(get_total_sql_07)
                get_all_mlie_and_time_07 = cursor_02.fetchall()
                get_all_mlie_and_time_list_07 = []
                for range1 in get_all_mlie_and_time_07:
                    for range2 in range1:
                        get_all_mlie_and_time_list_07.append(range2)

                cursor_02.execute(get_total_sql_08)
                get_all_mlie_and_time_08 = cursor_02.fetchall()
                get_all_mlie_and_time_list_08 = []
                for range1 in get_all_mlie_and_time_08:
                    for range2 in range1:
                        get_all_mlie_and_time_list_08.append(range2)

                cursor_02.execute(get_total_sql_09)
                get_all_mlie_and_time_09 = cursor_02.fetchall()
                get_all_mlie_and_time_list_09 = []
                for range1 in get_all_mlie_and_time_09:
                    for range2 in range1:
                        get_all_mlie_and_time_list_09.append(range2)

                cursor_02.execute(get_total_sql_10)
                get_all_mlie_and_time_10 = cursor_02.fetchall()
                get_all_mlie_and_time_list_10 = []
                for range1 in get_all_mlie_and_time_10:
                    for range2 in range1:
                        get_all_mlie_and_time_list_10.append(range2)

                cursor_02.execute(get_total_sql_11)
                get_all_mlie_and_time_11 = cursor_02.fetchall()
                get_all_mlie_and_time_list_11 = []
                for range1 in get_all_mlie_and_time_11:
                    for range2 in range1:
                        get_all_mlie_and_time_list_11.append(range2)

                cursor_02.execute(get_total_sql_12)
                get_all_mlie_and_time_12 = cursor_02.fetchall()
                get_all_mlie_and_time_list_12 = []
                for range1 in get_all_mlie_and_time_12:
                    for range2 in range1:
                        get_all_mlie_and_time_list_12.append(range2)

                cursor_02.execute(get_total_01)
                total_number_01 = cursor_02.fetchall()
                total_number_list_01 = []
                for range1 in total_number_01:
                    for range2 in range1:
                        total_number_list_01.append(range2)

                cursor_02.execute(get_total_02)
                total_number_02 = cursor_02.fetchall()
                total_number_list_02 = []
                for range1 in total_number_02:
                    for range2 in range1:
                        total_number_list_02.append(range2)

                cursor_02.execute(get_total_03)
                total_number_03 = cursor_02.fetchall()
                total_number_list_03 = []
                for range1 in total_number_03:
                    for range2 in range1:
                        total_number_list_03.append(range2)

                cursor_02.execute(get_total_04)
                total_number_04 = cursor_02.fetchall()
                total_number_list_04 = []
                for range1 in total_number_04:
                    for range2 in range1:
                        total_number_list_04.append(range2)

                cursor_02.execute(get_total_05)
                total_number_05 = cursor_02.fetchall()
                total_number_list_05 = []
                for range1 in total_number_05:
                    for range2 in range1:
                        total_number_list_05.append(range2)

                cursor_02.execute(get_total_06)
                total_number_06 = cursor_02.fetchall()
                total_number_list_06 = []
                for range1 in total_number_06:
                    for range2 in range1:
                        total_number_list_06.append(range2)

                cursor_02.execute(get_total_07)
                total_number_07 = cursor_02.fetchall()
                total_number_list_07 = []
                for range1 in total_number_07:
                    for range2 in range1:
                        total_number_list_07.append(range2)

                cursor_02.execute(get_total_08)
                total_number_08 = cursor_02.fetchall()
                total_number_list_08 = []
                for range1 in total_number_08:
                    for range2 in range1:
                        total_number_list_08.append(range2)

                cursor_02.execute(get_total_09)
                total_number_09 = cursor_02.fetchall()
                total_number_list_09 = []
                for range1 in total_number_09:
                    for range2 in range1:
                        total_number_list_09.append(range2)

                cursor_02.execute(get_total_10)
                total_number_10 = cursor_02.fetchall()
                total_number_list_10 = []
                for range1 in total_number_10:
                    for range2 in range1:
                        total_number_list_10.append(range2)

                cursor_02.execute(get_total_11)
                total_number_11 = cursor_02.fetchall()
                total_number_list_11 = []
                for range1 in total_number_11:
                    for range2 in range1:
                        total_number_list_11.append(range2)

                cursor_02.execute(get_total_12)
                total_number_12 = cursor_02.fetchall()
                total_number_list_12 = []
                for range1 in total_number_12:
                    for range2 in range1:
                        total_number_list_12.append(range2)

                total = len(total_number_list_01) + len(
                    total_number_list_02) + len(total_number_list_03) + len(
                        total_number_list_04
                    ) + len(total_number_list_05) + len(
                        total_number_list_06
                    ) + len(total_number_list_07) + len(
                        total_number_list_08
                    ) + len(total_number_list_09) + len(
                        total_number_list_10) + len(
                            total_number_list_11) + len(total_number_list_12)
                web_total = self.statistical_form_page.get_total_search_mileage_forms(
                )
                self.assertEqual(total, web_total)
                # 计算总里程 和 总时间
                total_mile = sum(get_all_mlie_and_time_list_01) + sum(
                    get_all_mlie_and_time_list_02
                ) + sum(get_all_mlie_and_time_list_03) + sum(
                    get_all_mlie_and_time_list_04
                ) + sum(get_all_mlie_and_time_list_05) + sum(
                    get_all_mlie_and_time_list_06) + sum(
                        get_all_mlie_and_time_list_07) + sum(
                            get_all_mlie_and_time_list_08) + sum(
                                get_all_mlie_and_time_list_09) + sum(
                                    get_all_mlie_and_time_list_10) + sum(
                                        get_all_mlie_and_time_list_11) + sum(
                                            get_all_mlie_and_time_list_12)
                # 断言总时间和总里程,总油耗
                # 计算总油耗
                if total_mile == 0:
                    self.assertEqual(
                        '0',
                        self.statistical_form_page.get_mileage_total_oil())
                else:
                    if self.statistical_form_page.get_mileage_total_oil(
                    ) == '0':
                        pass
                    else:
                        get_total_oil = total_mile / 1000 / 100 * 8
                        total_oil = '%.2f' % get_total_oil
                        self.assertEqual(
                            str(total_oil),
                            self.statistical_form_page.get_mileage_total_oil())

            elif search_data['type'] == 'day':
                # 如果选择天
                cursor_02.execute(get_total_sql_01)
                get_all_mile_data = cursor_02.fetchall()
                get_all_mile_list = []
                for range1 in get_all_mile_data:
                    for range2 in range1:
                        get_all_mile_list.append(range2)
                total = len(get_all_mile_list)
                web_total = self.statistical_form_page.get_total_search_mileage_form_with_day(
                )
                self.assertEqual(total, web_total)

                total_mile_with_day = sum(get_all_mile_list)
                # 断言
                self.assertAlmostEqual(
                    total_mile_with_day / 1000,
                    float(self.statistical_form_page.
                          get_mileage_with_day_total_mile()))

            # 点击导出
            self.driver.default_frame()
            cursor_02.close()
            connect_02.close()
        csv_file.close()
class TestCase602FormPortSearchTravelSearch(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.statistical_form_page3 = StatisticFormPage3(
            self.driver, self.base_url)
        self.log_in_base = LogInBase(self.driver, self.base_url)
        self.connect_sql = ConnectSql()
        self.assert_text = AssertText()
        self.seasrch_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_travel_search_port(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_mileage_form_button()
        # 断言
        self.assertEqual(
            self.assert_text.statistical_form_tracl_form(),
            self.statistical_form_page.
            actual_text_after_click_mileage_form_button())
        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'sport_statistical_milage_form_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],
                'type': row[1],
                'choose_date': row[2],
                'begin_time': row[3],
                'end_time': row[4]
            }
            self.statistical_form_page.add_data_to_search_mileage_form(
                search_data)
            self.statistical_form_page.switch_to_tracel_report_form_frame()
            all_dev = self.seasrch_sql.search_current_account_equipment(
                search_data['search_user'])
            imeis = self.statistical_form_page3.change_dev_imei_format(all_dev)
            begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
            )
            end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
            )

            if search_data['type'] == 'mile':
                # 获取页面总共得到的总页数
                sleep(4)
                total_page = self.statistical_form_page3.get_total_page_in_tracel_report_form(
                )
                print(total_page)

                if total_page == 0:
                    # 连接数据库
                    all_dev = self.seasrch_sql.search_current_account_equipment(
                        search_data['search_user'])
                    imeis = self.statistical_form_page3.change_dev_imei_format(
                        all_dev)
                    req_type = ''
                    if search_data['type'] == 'mile':
                        req_type = 'segment'
                    elif search_data['type'] == 'day':
                        req_type = 'day'
                    begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
                    )
                    end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
                    )

                    # 连接接口
                    request_url = request_base_url()
                    request_params = {
                        '_method_': 'getTrackSegment',
                        'imeis': imeis,
                        'type': req_type,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'startRow': 0,
                        'status': 0
                    }
                    res = requests.post(request_url, data=request_params)
                    sleep(30)
                    response = res.json()
                    print(response)
                    self.assertEqual(400, response['code'])
                    self.assertEqual('没有找到数据', response['msg'])

                elif total_page == 1:
                    # 获取这一个页有多少条记录
                    total_number_per_page = self.statistical_form_page3.get_total_number_per_page_in_tracel_form(
                    )
                    web_data = []
                    for n in range(total_number_per_page):
                        web_data.append({
                            'imei':
                            self.statistical_form_page3.
                            get_imei_in_tracel_form(n),
                            'distance':
                            self.statistical_form_page3.
                            get_distance_in_tracel_form(n),
                            'startTime':
                            self.statistical_form_page3.
                            get_start_time_in_tracel_form(n),
                            'endTime':
                            self.statistical_form_page3.
                            get_end_time_in_tracel_form(n),
                            'avgSpeed':
                            self.statistical_form_page3.
                            get_avg_speed_in_tracel_form(n),
                            'runTimeSecond':
                            self.statistical_form_page3.
                            get_run_time_second_in_tracel_form(n)
                        })
                    print(web_data)
                    # 连接数据库
                    all_dev = self.seasrch_sql.search_current_account_equipment(
                        search_data['search_user'])
                    imeis = self.statistical_form_page3.change_dev_imei_format(
                        all_dev)
                    req_type = ''
                    if search_data['type'] == 'mile':
                        req_type = 'segment'
                    elif search_data['type'] == 'day':
                        req_type = 'day'
                    begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
                    )
                    end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
                    )

                    # 连接接口
                    request_url = request_base_url()
                    request_params = {
                        '_method_': 'getTrackSegment',
                        'imeis': imeis,
                        'type': req_type,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'startRow': 0,
                        'status': 0
                    }
                    res = requests.post(request_url, data=request_params)
                    sleep(30)
                    response = res.json()
                    res_data = response['data']
                    print(res_data)
                    for data in res_data:
                        del data['endLat'], data['avgFuel'], data[
                            'startLat'], data['fuel'], data['endLng'], data[
                                'startLng'], data['status']
                    for data in res_data:
                        data['distance'] = float('%.3f' %
                                                 (data['distance'] / 1000))
                    print(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_page3.get_total_number_per_page_in_tracel_form(
                        )
                        for n in range(total_number_per_page):
                            web_data.append({
                                'imei':
                                self.statistical_form_page3.
                                get_imei_in_tracel_form(n),
                                'distance':
                                self.statistical_form_page3.
                                get_distance_in_tracel_form(n),
                                'startTime':
                                self.statistical_form_page3.
                                get_start_time_in_tracel_form(n),
                                'endTime':
                                self.statistical_form_page3.
                                get_end_time_in_tracel_form(n),
                                'avgSpeed':
                                self.statistical_form_page3.
                                get_avg_speed_in_tracel_form(n),
                                'runTimeSecond':
                                self.statistical_form_page3.
                                get_run_time_second_in_tracel_form(n)
                            })
                    print(web_data)
                    # 连接数据库
                    all_dev = self.seasrch_sql.search_current_account_equipment(
                        search_data['search_user'])
                    imeis = self.statistical_form_page3.change_dev_imei_format(
                        all_dev)
                    req_type = ''
                    if search_data['type'] == 'mile':
                        req_type = 'segment'
                    elif search_data['type'] == 'day':
                        req_type = 'day'
                    begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
                    )
                    end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
                    )

                    # 连接接口
                    request_url = request_base_url()
                    request_params = {
                        '_method_': 'getTrackSegment',
                        'imeis': imeis,
                        'type': req_type,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'startRow': 0,
                        'status': 0
                    }
                    res = requests.post(request_url, data=request_params)
                    sleep(30)
                    response = res.json()
                    res_data = response['data']
                    for data in res_data:
                        del data['endLat'], data['avgFuel'], data[
                            'startLat'], data['fuel'], data['endLng'], data[
                                'startLng'], data['status']
                    for data in res_data:
                        data['distance'] = float('%.3f' %
                                                 (data['distance'] / 1000))
                    print(res_data)
                    self.assertEqual(web_data, res_data)

            elif search_data['type'] == 'day':
                # 获取页面总共得到的总页数
                sleep(4)
                total_page = self.statistical_form_page3.get_total_page_in_tracel_form_with_day(
                )
                print(total_page)

                if total_page == 0:
                    # 连接数据库
                    all_dev = self.seasrch_sql.search_current_account_equipment(
                        search_data['search_user'])
                    imeis = self.statistical_form_page3.change_dev_imei_format(
                        all_dev)
                    req_type = ''
                    if search_data['type'] == 'mile':
                        req_type = 'segment'
                    elif search_data['type'] == 'day':
                        req_type = 'day'
                    begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
                    )
                    end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
                    )

                    # 连接接口
                    request_url = request_base_url()
                    request_params = {
                        '_method_': 'getTrackSegment',
                        'imeis': imeis,
                        'type': req_type,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'startRow': 0,
                        'status': 0
                    }
                    res = requests.post(request_url, data=request_params)
                    sleep(30)
                    response = res.json()
                    print(response)
                    self.assertEqual(400, response['code'])
                    self.assertEqual('没有找到数据', response['msg'])

                elif total_page == 1:
                    # 获取这一个页有多少条记录
                    total_number_per_page = self.statistical_form_page3.get_total_number_per_page_in_tracel_report_form_with_day(
                    )
                    web_data = []
                    for n in range(total_number_per_page):
                        web_data.append({
                            'imei':
                            self.statistical_form_page3.
                            get_imei_in_tracel_form_with_day(n),
                            'distance':
                            self.statistical_form_page3.
                            get_distance_in_tracel_report_form_with_day(n),
                            'atDay':
                            self.statistical_form_page3.
                            get_at_day_time_in_tracel_report_form_with_day(n)
                        })
                    print(web_data)
                    # 连接数据库
                    all_dev = self.seasrch_sql.search_current_account_equipment(
                        search_data['search_user'])
                    imeis = self.statistical_form_page3.change_dev_imei_format(
                        all_dev)
                    req_type = ''
                    if search_data['type'] == 'mile':
                        req_type = 'segment'
                    elif search_data['type'] == 'day':
                        req_type = 'day'
                    begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
                    )
                    end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
                    )

                    # 连接接口
                    request_url = request_base_url()
                    request_params = {
                        '_method_': 'getTrackSegment',
                        'imeis': imeis,
                        'type': req_type,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'startRow': 0,
                        'status': 0
                    }
                    res = requests.post(request_url, data=request_params)
                    sleep(30)
                    response = res.json()
                    res_data = response['data']
                    print(res_data)
                    for data in res_data:
                        del data['startTime'], data['runTimeSecond'], data['avgFuel'], data['startLng'], data['fuel'], \
                            data[
                                'endLat'], data['avgSpeed'], data['status'], data['endTime'], data[
                            'startLat'], data['endLng']
                    for data in res_data:
                        data['distance'] = float('%.3f' %
                                                 (data['distance'] / 1000))
                    for data in res_data:
                        data['atDay'] = data['atDay'].split(' ')[0]
                    print(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_page3.get_total_number_per_page_in_tracel_report_form_with_day(
                        )
                        for n in range(total_number_per_page):
                            web_data.append({
                                'imei':
                                self.statistical_form_page3.
                                get_imei_in_tracel_form_with_day(n),
                                'distance':
                                self.statistical_form_page3.
                                get_distance_in_tracel_report_form_with_day(n),
                                'atDay':
                                self.statistical_form_page3.
                                get_at_day_time_in_tracel_report_form_with_day(
                                    n)
                            })
                    print(web_data)
                    # 连接数据库
                    all_dev = self.seasrch_sql.search_current_account_equipment(
                        search_data['search_user'])
                    imeis = self.statistical_form_page3.change_dev_imei_format(
                        all_dev)
                    req_type = ''
                    if search_data['type'] == 'mile':
                        req_type = 'segment'
                    elif search_data['type'] == 'day':
                        req_type = 'day'
                    begin_time = self.statistical_form_page3.get_tracel_report_form_begin_time(
                    )
                    end_time = self.statistical_form_page3.get_tracel_report_form_end_time(
                    )

                    # 连接接口
                    request_url = request_base_url()
                    request_params = {
                        '_method_': 'getTrackSegment',
                        'imeis': imeis,
                        'type': req_type,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'startRow': 0,
                        'status': 0
                    }
                    res = requests.post(request_url, data=request_params)
                    sleep(30)
                    response = res.json()
                    res_data = response['data']
                    for data in res_data:
                        del data['startTime'], data['runTimeSecond'], data['avgFuel'], data['startLng'], data['fuel'], \
                            data[
                                'endLat'], data['avgSpeed'], data['status'], data['endTime'], data[
                            'startLat'], data['endLng']
                    for data in res_data:
                        data['distance'] = float('%.3f' %
                                                 (data['distance'] / 1000))
                    for data in res_data:
                        data['atDay'] = data['atDay'].split(' ')[0]
                    print(res_data)
                    self.assertEqual(web_data, res_data)
            # 请求行程报表统计接口
            request_url = request_base_url()
            req_data = {
                '_method_': 'getTrackSegmentSum',
                'imeis': imeis,
                'startTime': begin_time,
                'endTime': end_time,
            }
            res = requests.post(request_url, data=req_data)
            response_data = res.json()
            if response_data['code'] == 0:
                data_total = 0
                data_total_time = 0
                response_datas = response_data['data']
                for data_01 in response_datas:
                    data_total += data_01['totalDistiance']
                    data_total_time += data_01['totalTime']
                data_totals = '%.3f' % (data_total / 1000)
                web_total = ''
                if search_data['type'] == 'mile':
                    web_total = self.statistical_form_page3.get_web_total_in_tracel_form_with_search_mile(
                    )
                    web_total_time = self.statistical_form_page3.get_web_total_time_in_tracel_form_with_search_mile(
                    )
                    web_total_times = self.statistical_form_page3.change_time_format(
                        web_total_time)
                    self.assertEqual(data_total_time, web_total_times)
                elif search_data['type'] == 'day':
                    web_total = self.statistical_form_page3.get_web_total_in_tracel_form_with_search_day(
                    )
                    # self.assertEqual(data_totals, web_total)
            self.driver.default_frame()
        csv_file.close()
コード例 #5
0
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 TestCase145SportStatisticalStayForm(unittest.TestCase):
    '''
    运动统计,停留报表
    author : zhangAo
    '''

    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.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_stay_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_stay_form_button()
        # 断言
        self.assertEqual(self.assert_text.statistical_form_stay_form(),
                         self.statistical_form_page.actual_text_after_click_stay_form_button())
        # 读数据
        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv('sport_statistical_stay_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],
                'choose_date': row[1],
                'begin_time': row[2],
                'end_time': row[3]
            }
            self.statistical_form_page.add_data_to_search_stay_form(search_data)

            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_sport_stay_sql(all_dev, search_data)
            get_total_sql_01 = self.search_sql.search_sport_stay_sql_01(all_dev, search_data)
            get_total_sql_02 = self.search_sql.search_sport_stay_sql_02(all_dev, search_data)
            get_total_sql_03 = self.search_sql.search_sport_stay_sql_03(all_dev, search_data)
            get_total_sql_04 = self.search_sql.search_sport_stay_sql_04(all_dev, search_data)
            get_total_sql_05 = self.search_sql.search_sport_stay_sql_05(all_dev, search_data)
            get_total_sql_06 = self.search_sql.search_sport_stay_sql_06(all_dev, search_data)
            get_total_sql_07 = self.search_sql.search_sport_stay_sql_07(all_dev, search_data)
            get_total_sql_08 = self.search_sql.search_sport_stay_sql_08(all_dev, search_data)
            get_total_sql_09 = self.search_sql.search_sport_stay_sql_09(all_dev, search_data)
            get_total_sql_10 = self.search_sql.search_sport_stay_sql_10(all_dev, search_data)
            get_total_sql_11 = self.search_sql.search_sport_stay_sql_11(all_dev, search_data)
            get_total_sql_12 = self.search_sql.search_sport_stay_sql_12(all_dev, search_data)

            print(get_total_sql_01)

            '''cursor_02.execute(get_total_sql)
            get_total = cursor_02.fetchall()
            total_list = []
            for range1 in get_total:
                for range2 in range1:
                    total_list.append(range2)
            # 拆分列表
            total_number_list = []
            total_time_list = []
            for n in range(len(total_list)):
                if n % 2 == 0:
                    total_number_list.append(total_list[n])
                elif n % 2 == 1:
                    total_time_list.append(total_list[n])'''

            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)
            # 拆分列表
            total_number_list_01 = []
            total_time_list_01 = []
            for n in range(len(total_list_01)):
                if n % 2 == 0:
                    total_number_list_01.append(total_list_01[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_02 = []
            total_time_list_02 = []
            for n in range(len(total_list_02)):
                if n % 2 == 0:
                    total_number_list_02.append(total_list_02[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_03 = []
            total_time_list_03 = []
            for n in range(len(total_list_03)):
                if n % 2 == 0:
                    total_number_list_03.append(total_list_03[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_04 = []
            total_time_list_04 = []
            for n in range(len(total_list_04)):
                if n % 2 == 0:
                    total_number_list_04.append(total_list_04[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_05 = []
            total_time_list_05 = []
            for n in range(len(total_list_05)):
                if n % 2 == 0:
                    total_number_list_05.append(total_list_05[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_06 = []
            total_time_list_06 = []
            for n in range(len(total_list_06)):
                if n % 2 == 0:
                    total_number_list_06.append(total_list_06[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_07 = []
            total_time_list_07 = []
            for n in range(len(total_list_07)):
                if n % 2 == 0:
                    total_number_list_07.append(total_list_07[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_08 = []
            total_time_list_08 = []
            for n in range(len(total_list_08)):
                if n % 2 == 0:
                    total_number_list_08.append(total_list_08[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_09 = []
            total_time_list_09 = []
            for n in range(len(total_list_09)):
                if n % 2 == 0:
                    total_number_list_09.append(total_list_09[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_10 = []
            total_time_list_10 = []
            for n in range(len(total_list_10)):
                if n % 2 == 0:
                    total_number_list_10.append(total_list_10[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_11 = []
            total_time_list_11 = []
            for n in range(len(total_list_11)):
                if n % 2 == 0:
                    total_number_list_11.append(total_list_11[n])
                elif n % 2 == 1:
                    total_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)
            # 拆分列表
            total_number_list_12 = []
            total_time_list_12 = []
            for n in range(len(total_list_12)):
                if n % 2 == 0:
                    total_number_list_12.append(total_list_12[n])
                elif n % 2 == 1:
                    total_time_list_12.append(total_list_12[n])

            # 断言查询的条
            total = len(total_number_list_01) + len(total_number_list_02) + len(total_number_list_03) + len(
                total_number_list_04) + len(total_number_list_05) + len(total_number_list_06) + len(
                total_number_list_07) + len(total_number_list_08) + len(total_number_list_09) + len(
                total_number_list_10) + len(total_number_list_11) + len(total_number_list_12)
            sleep(3)
            self.statistical_form_page.switch_to_stay_report_form_frame()
            web_total = self.statistical_form_page.get_total_search_stay_form_number()
            self.assertEqual(total, web_total)

            # 断言查询的总的停留时间
            total_time = sum(total_time_list_01) + sum(total_time_list_02) + sum(total_time_list_03) + sum(
                total_time_list_04) + sum(total_time_list_05) + sum(total_time_list_06) + sum(total_time_list_07) + sum(
                total_time_list_08) + sum(total_time_list_09) + sum(total_time_list_10) + sum(total_time_list_11) + sum(
                total_time_list_12)
            chang_total_time_type = self.statistical_form_page.change_sec_time(total_time)
            web_total_time = self.statistical_form_page.get_total_stay_form_time()
            print(web_total_time)
            self.assertEqual(chang_total_time_type, web_total_time)

            # 点击导出停留报表
            self.driver.default_frame()
            cursor_02.close()
            connect_02.close()
        csv_file.close()
コード例 #7
0
class TestCase148SportStatisticalOverview(unittest.TestCase):
    '''
    运动统计,运动总览
    author:zhangAo
    '''
    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.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_sport_statistical_sport_overview(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(
            ))
        # 读数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'sport_statistical_sport_overview_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],
                'choose_date': row[1],
                'begin_time': row[2],
                'end_time': row[3]
            }
            self.statistical_form_page.add_data_to_search_sport_overview(
                search_data)

            # 连接数据库
            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_sport_overview_sql(
                all_dev, search_data)
            get_sum_total = self.search_sql.search_sum_sport_overview_sql(
                all_dev, search_data)
            print(get_sum_total)
            # 计算多少条数据
            cursor_02.execute(get_total_sql)
            get_total = cursor_02.fetchall()
            total_list = []
            for range1 in get_total:
                for range2 in range1:
                    total_list.append(range2)
            total = len(total_list)

            # 计算总里程,超速,停留次数
            cursor_02.execute(get_sum_total)
            get_sum_total = cursor_02.fetchall()
            data_list = []
            for range1 in get_sum_total:
                for range2 in range1:
                    data_list.append(range2)
            # 拆分列表
            sum_mlie_list = []
            sum_over_speed_list = []
            sum_stay_list = []
            for n in range(len(data_list)):
                if n % 3 == 0:
                    sum_mlie_list.append(data_list[n])
                elif n % 3 == 1:
                    sum_over_speed_list.append(data_list[n])
                elif n % 3 == 2:
                    sum_stay_list.append(data_list[n])
            # sql的总里程数
            total_mlie = sum(sum_mlie_list)

            new_over_speed_list = []
            for n in range(len(sum_over_speed_list)):
                if sum_over_speed_list[n] == None:
                    pass
                else:
                    new_over_speed_list.append(sum_over_speed_list[n])
            # sql的总超速数
            total_over_speed = sum(new_over_speed_list)
            # sql的总停留次数
            total_stay = sum(sum_stay_list)

            # 断言的部分
            # 断言查询条数
            web_total = self.statistical_form_page.get_total_search_sport_overview(
            )
            # self.assertEqual(total, web_total)

            # 断言总里程数
            web_mlie_total = self.statistical_form_page.get_total_search_mile_total(
            )
            #  self.assertAlmostEqual(total_mlie / 1000, float(web_mlie_total))

            # 断言总的超速数
            web_over_speed_total = self.statistical_form_page.get_total_search_over_speed_total(
            )
            # self.assertEqual(str(total_over_speed), web_over_speed_total)

            # 断言总的停留次数
            web_stay_total = self.statistical_form_page.get_total_search_stay_total(
            )
            # self.assertEqual(str(total_stay), web_stay_total)
            # 导出
            self.driver.default_frame()
            cursor_02.close()
            connect_02.close()
        csv_file.close()
class TestCase181AlarmOverviewSearch(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.alarm_info_page = AlarmInfoPage(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_page = StatisticalFormPage(self.driver, self.base_url)
        self.statistical_form_page3 = StatisticFormPage3(self.driver, self.base_url)
        self.seasrch_sql = SearchSql(self.driver, self.base_url)
        self.connect_sql = ConnectSql()
        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.statistical_form_page.click_control_after_click_statistical_form_page()
        time.sleep(3)

    def tearDown(self):
        self.driver.quit_browser()

    def test_case_alarm_overview_search(self):
        # 断言url
        expect_url = self.base_url + '/deviceReport/statisticalReport'
        self.assertEqual(expect_url, self.alarm_info_page.actual_url_click_alarm())

        # 点击告警总览
        self.alarm_info_page.click_alarm_overview_list()
        # 选择全部告警类型
        self.statistical_form_page3.select_all_alarm_type_in_alarm_overview_search()
        # 输入数据搜索
        csv_file = self.statistical_form_page_read_csv.read_csv('alarm_overview_search_datas.csv')
        csv_data = csv.reader(csv_file)
        is_header = True
        for row in csv_data:
            if is_header:
                is_header = False
                continue
            data = {
                'user_name': row[0],
                'choose_date': row[1],
                'began_time': row[2],
                'end_time': row[3],
                'is_next': row[4],
                'is_enter_dev': row[5]
            }
            self.statistical_form_page3.add_data_to_search_in_alarm_overview(data)

            # 开始时间和结束时间
            begin_time = self.statistical_form_page3.get_alarm_overview_form_begin_time()
            end_time = self.statistical_form_page3.get_alarm_overview_form_end_time()
            # 全部告警类型
            alarm_type = '1,10,11,12,128,13,14,15,16,17,18,19,20,192,194,195,2,22,23,24,25,3,32,4,5,6,9,90,ACC_OFF,ACC_ON,in,offline,out,overSpeed,riskPointAlarm,sensitiveAreasFence,stayAlert,stayTimeIn,stayTimeOut'
            all_dev = self.seasrch_sql.search_current_account_equipment(data['user_name'])
            imeis = self.statistical_form_page3.change_dev_imei_format(all_dev)
            # 用户id
            get_current_userid = self.seasrch_sql.search_current_account_user_id(data['user_name'])
            # 全父id
            get_current_full_id = self.seasrch_sql.search_current_account_user_full_id(data['user_name'])
            # 请求url
            request_url = request_base_url()

            if data['is_enter_dev'] == '1':
                request_params = {
                    '_method_': 'getAlarmSummary',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'status': alarm_type,
                    'userIds': get_current_userid
                }
                res = requests.post(request_url, data=request_params)
                time.sleep(10)
                response = res.json()

                # 判断有没有数据
                no_data_display = self.statistical_form_page3.get_no_data_display_in_alarm_overview()
                if no_data_display == 'display: block;':
                    print(response)
                    self.assertEqual(400, response['code'])
                    self.assertEqual('没有找到数据', response['msg'])

                else:
                    # 获取页面上的数据
                    web_total_number = self.statistical_form_page3.get_web_total_number_alarm_overview()
                    web_data = []
                    for n in range(web_total_number):
                        web_data.append({
                            'imei': self.statistical_form_page3.get_imei_in_alarm_overview(n),
                            'sos': self.statistical_form_page3.get_sos_number_in_alarm_overview(n),
                            'blindAreaEnter': self.statistical_form_page3.get_blind_area_enter_in_alarm_overview(
                                n),
                            'blindAreaExit': self.statistical_form_page3.get_blind_area_exit_in_alarm_overview(
                                n),
                            'bootingNotification': self.statistical_form_page3.booting_notification_in_alarm_overview(
                                n),
                            'rearviewMirrorVibrationAlert': self.statistical_form_page3.first_fix_notification_in_alarm_overview(
                                n),
                            'firstFixNotification': self.statistical_form_page3.get_low_external_power_in_alarm_overview(
                                n),
                            'lowExternalPower': self.statistical_form_page3.get_low_power_protection_in_alarm_overview(
                                n),
                            'lowPowerProtection': self.statistical_form_page3.get_sim_card_change_in_alarm_overview(
                                n),
                            'simCardChange': self.statistical_form_page3.get_over_speed_in_alarm_overview(n),
                            'powerOff': self.statistical_form_page3.get_power_off_in_alarm_overview(n),
                            'airplaneModeAfterLowPowerProtection': self.statistical_form_page3.airplane_mode_after_low_power_protection_in_alarm_overview(
                                n),
                            'disassembly': self.statistical_form_page3.disassembly_in_alarm_overview(n),
                            'illegalMobileAlert': self.statistical_form_page3.get_cut_power_in_alarm_overview(
                                n),
                            'insufficientBatteryBackupAlert': self.statistical_form_page3.get_vibration_in_alarm_overview(
                                n),
                            'overStepAlert': self.statistical_form_page3.get_movement_in_alarm_overview(n),
                            'cutPower': self.statistical_form_page3.get_low_power_in_alarm_overview(n),
                            'doorAlarm': self.statistical_form_page3.get_door_alarm_in_alarm_overview(n),
                            'voice': self.statistical_form_page3.get_exit_geozone_in_alarm_overview(n),
                            'lingerAlert': self.statistical_form_page3.enter_geozone_in_alarm_overview(n),
                            'openCoverAlarm': self.statistical_form_page3.open_conver_in_alarm_overview(n),
                            'lowPowerAlarm': self.statistical_form_page3.low_power_in_alarm_overview(n),
                            'vibration': self.statistical_form_page3.rearview_mirror_vibration_alert_in_alarm_overview(
                                n),
                            'sleepAlarm': self.statistical_form_page3.sleep_alarm_in_alarm_overview(n),
                            'enterTerminalGeozone': self.statistical_form_page3.get_enter_terminal_geozone_in_alarm_overview(
                                n),
                            'exitTerminalGeozone': self.statistical_form_page3.get_exit_terminal_geozone_in_alarm_overview(
                                n),
                            'overspeed': self.statistical_form_page3.get_off_line_in_alarm_overview(n),
                            'movement': self.statistical_form_page3.get_voice_in_alarm_overview(n),
                            'lowPower': self.statistical_form_page3.get_acc_open_in_alarm_overview(n),
                            'accOpen': self.statistical_form_page3.get_acc_shut_down_in_alarm_overview(n),
                            'accShutdown': self.statistical_form_page3.get_long_time_not_out_fence_in_alarm_overview(
                                n),
                            'enterGeozone': self.statistical_form_page3.get_long_time_not_into_fence_in_alarm_overview(
                                n),
                            'offline': self.statistical_form_page3.get_stay_alert_in_alarm_overview(n),
                            'exitGeozone': self.statistical_form_page3.get_linger_alert_in_alarm_overview(n),
                            'overspeedPlatform': self.statistical_form_page3.get_illegal_mobile_alert_in_alarm_overview(
                                n),
                            'riskPointAlarm': self.statistical_form_page3.get_risk_point_alert_in_alarm_overview(
                                n),
                            'sensitiveAreasFence': self.statistical_form_page3.insufficient_battery_back_up_alert_in_alarm_overview(
                                n),
                            'stayAlert': self.statistical_form_page3.get_over_step_alert_in_alarm_overview(n),
                            'longtimeNotIntoFence': self.statistical_form_page3.get_sensitive_areas_fence_in_alarm_overview(
                                n),
                            'longtimeNotOutFence': self.statistical_form_page3.get_over_speed_platform_in_alarm_overview(
                                n)
                        })
                    print(web_data)
                    res_data = response['data']
                    for data_1 in res_data:
                        del data_1['carCrash'], data_1['dvrVibration'], data_1['overspeedDVR'], data_1[
                            'rapidAcceleration'], data_1['rapidDeceleration'], data_1['sharpTurn'], data_1['status']
                    print(res_data)
                    # self.assertEqual(web_data, res_data)
                    self.assertEqual(len(web_data), len(res_data))
                    for datas in web_data:
                        self.assertIn(datas, res_data)

                    for datas2 in res_data:
                        self.assertIn(datas2, web_data)

            elif data['is_enter_dev'] == '0':
                if data['is_next'] == '0':
                    request_params = {
                        '_method_': 'getAlarmSummary',
                        'userIds': get_current_userid,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'status': alarm_type,
                        'imeis': imeis,
                    }
                    res = requests.post(request_url, data=request_params)
                    time.sleep(10)
                    response = res.json()
                    res_data = response['data']
                    for data_1 in res_data:
                        del data_1['carCrash'], data_1['dvrVibration'], data_1['overspeedDVR'], data_1[
                            'rapidAcceleration'], data_1['rapidDeceleration'], data_1['sharpTurn'], data_1['status']
                    print(res_data)
                    # 获取页面上的数据
                    web_total_number = self.statistical_form_page3.get_web_total_number_alarm_overview()
                    web_data = []
                    for n in range(web_total_number):
                        web_data.append({
                            'imei': self.statistical_form_page3.get_imei_in_alarm_overview(n),
                            'sos': self.statistical_form_page3.get_sos_number_in_alarm_overview(n),
                            'blindAreaEnter': self.statistical_form_page3.get_blind_area_enter_in_alarm_overview(
                                n),
                            'blindAreaExit': self.statistical_form_page3.get_blind_area_exit_in_alarm_overview(
                                n),
                            'bootingNotification': self.statistical_form_page3.booting_notification_in_alarm_overview(
                                n),
                            'rearviewMirrorVibrationAlert': self.statistical_form_page3.first_fix_notification_in_alarm_overview(
                                n),
                            'firstFixNotification': self.statistical_form_page3.get_low_external_power_in_alarm_overview(
                                n),
                            'lowExternalPower': self.statistical_form_page3.get_low_power_protection_in_alarm_overview(
                                n),
                            'lowPowerProtection': self.statistical_form_page3.get_sim_card_change_in_alarm_overview(
                                n),
                            'simCardChange': self.statistical_form_page3.get_over_speed_in_alarm_overview(n),
                            'powerOff': self.statistical_form_page3.get_power_off_in_alarm_overview(n),
                            'airplaneModeAfterLowPowerProtection': self.statistical_form_page3.airplane_mode_after_low_power_protection_in_alarm_overview(
                                n),
                            'disassembly': self.statistical_form_page3.disassembly_in_alarm_overview(n),
                            'illegalMobileAlert': self.statistical_form_page3.get_cut_power_in_alarm_overview(
                                n),
                            'insufficientBatteryBackupAlert': self.statistical_form_page3.get_vibration_in_alarm_overview(
                                n),
                            'overStepAlert': self.statistical_form_page3.get_movement_in_alarm_overview(n),
                            'cutPower': self.statistical_form_page3.get_low_power_in_alarm_overview(n),
                            'doorAlarm': self.statistical_form_page3.get_door_alarm_in_alarm_overview(n),
                            'voice': self.statistical_form_page3.get_exit_geozone_in_alarm_overview(n),
                            'lingerAlert': self.statistical_form_page3.enter_geozone_in_alarm_overview(n),
                            'openCoverAlarm': self.statistical_form_page3.open_conver_in_alarm_overview(n),
                            'lowPowerAlarm': self.statistical_form_page3.low_power_in_alarm_overview(n),
                            'vibration': self.statistical_form_page3.rearview_mirror_vibration_alert_in_alarm_overview(
                                n),
                            'sleepAlarm': self.statistical_form_page3.sleep_alarm_in_alarm_overview(n),
                            'enterTerminalGeozone': self.statistical_form_page3.get_enter_terminal_geozone_in_alarm_overview(
                                n),
                            'exitTerminalGeozone': self.statistical_form_page3.get_exit_terminal_geozone_in_alarm_overview(
                                n),
                            'overspeed': self.statistical_form_page3.get_off_line_in_alarm_overview(n),
                            'movement': self.statistical_form_page3.get_voice_in_alarm_overview(n),
                            'lowPower': self.statistical_form_page3.get_acc_open_in_alarm_overview(n),
                            'accOpen': self.statistical_form_page3.get_acc_shut_down_in_alarm_overview(n),
                            'accShutdown': self.statistical_form_page3.get_long_time_not_out_fence_in_alarm_overview(
                                n),
                            'enterGeozone': self.statistical_form_page3.get_long_time_not_into_fence_in_alarm_overview(
                                n),
                            'offline': self.statistical_form_page3.get_stay_alert_in_alarm_overview(n),
                            'exitGeozone': self.statistical_form_page3.get_linger_alert_in_alarm_overview(n),
                            'overspeedPlatform': self.statistical_form_page3.get_illegal_mobile_alert_in_alarm_overview(
                                n),
                            'riskPointAlarm': self.statistical_form_page3.get_risk_point_alert_in_alarm_overview(
                                n),
                            'sensitiveAreasFence': self.statistical_form_page3.insufficient_battery_back_up_alert_in_alarm_overview(
                                n),
                            'stayAlert': self.statistical_form_page3.get_over_step_alert_in_alarm_overview(n),
                            'longtimeNotIntoFence': self.statistical_form_page3.get_sensitive_areas_fence_in_alarm_overview(
                                n),
                            'longtimeNotOutFence': self.statistical_form_page3.get_over_speed_platform_in_alarm_overview(
                                n)
                        })
                    print(web_data)
                    self.assertEqual(len(web_data), len(res_data))
                    for datas in web_data:
                        self.assertIn(datas, res_data)

                    for datas2 in res_data:
                        self.assertIn(datas2, web_data)


                elif data['is_next'] == '1':
                    request_params = {
                        '_method_': 'getAlarmSummary',
                        'currentUser': get_current_full_id,
                        'startTime': begin_time,
                        'endTime': end_time,
                        'status': alarm_type,
                        'childUserFlag': '1'
                    }
                    res = requests.post(request_url, data=request_params)
                    time.sleep(10)
                    response = res.json()
                    res_data = response['data']
                    for data_1 in res_data:
                        del data_1['carCrash'], data_1['dvrVibration'], data_1['overspeedDVR'], data_1[
                            'rapidAcceleration'], data_1['rapidDeceleration'], data_1['sharpTurn'], data_1['status']
                    print(res_data)
                    # 获取页面上的数据
                    web_total_number = self.statistical_form_page3.get_web_total_number_alarm_overview()
                    web_data = []
                    for n in range(web_total_number):
                        web_data.append({
                            'imei': self.statistical_form_page3.get_imei_in_alarm_overview(n),
                            'sos': self.statistical_form_page3.get_sos_number_in_alarm_overview(n),
                            'blindAreaEnter': self.statistical_form_page3.get_blind_area_enter_in_alarm_overview(
                                n),
                            'blindAreaExit': self.statistical_form_page3.get_blind_area_exit_in_alarm_overview(
                                n),
                            'bootingNotification': self.statistical_form_page3.booting_notification_in_alarm_overview(
                                n),
                            'rearviewMirrorVibrationAlert': self.statistical_form_page3.first_fix_notification_in_alarm_overview(
                                n),
                            'firstFixNotification': self.statistical_form_page3.get_low_external_power_in_alarm_overview(
                                n),
                            'lowExternalPower': self.statistical_form_page3.get_low_power_protection_in_alarm_overview(
                                n),
                            'lowPowerProtection': self.statistical_form_page3.get_sim_card_change_in_alarm_overview(
                                n),
                            'simCardChange': self.statistical_form_page3.get_over_speed_in_alarm_overview(n),
                            'powerOff': self.statistical_form_page3.get_power_off_in_alarm_overview(n),
                            'airplaneModeAfterLowPowerProtection': self.statistical_form_page3.airplane_mode_after_low_power_protection_in_alarm_overview(
                                n),
                            'disassembly': self.statistical_form_page3.disassembly_in_alarm_overview(n),
                            'illegalMobileAlert': self.statistical_form_page3.get_cut_power_in_alarm_overview(
                                n),
                            'insufficientBatteryBackupAlert': self.statistical_form_page3.get_vibration_in_alarm_overview(
                                n),
                            'overStepAlert': self.statistical_form_page3.get_movement_in_alarm_overview(n),
                            'cutPower': self.statistical_form_page3.get_low_power_in_alarm_overview(n),
                            'doorAlarm': self.statistical_form_page3.get_door_alarm_in_alarm_overview(n),
                            'voice': self.statistical_form_page3.get_exit_geozone_in_alarm_overview(n),
                            'lingerAlert': self.statistical_form_page3.enter_geozone_in_alarm_overview(n),
                            'openCoverAlarm': self.statistical_form_page3.open_conver_in_alarm_overview(n),
                            'lowPowerAlarm': self.statistical_form_page3.low_power_in_alarm_overview(n),
                            'vibration': self.statistical_form_page3.rearview_mirror_vibration_alert_in_alarm_overview(
                                n),
                            'sleepAlarm': self.statistical_form_page3.sleep_alarm_in_alarm_overview(n),
                            'enterTerminalGeozone': self.statistical_form_page3.get_enter_terminal_geozone_in_alarm_overview(
                                n),
                            'exitTerminalGeozone': self.statistical_form_page3.get_exit_terminal_geozone_in_alarm_overview(
                                n),
                            'overspeed': self.statistical_form_page3.get_off_line_in_alarm_overview(n),
                            'movement': self.statistical_form_page3.get_voice_in_alarm_overview(n),
                            'lowPower': self.statistical_form_page3.get_acc_open_in_alarm_overview(n),
                            'accOpen': self.statistical_form_page3.get_acc_shut_down_in_alarm_overview(n),
                            'accShutdown': self.statistical_form_page3.get_long_time_not_out_fence_in_alarm_overview(
                                n),
                            'enterGeozone': self.statistical_form_page3.get_long_time_not_into_fence_in_alarm_overview(
                                n),
                            'offline': self.statistical_form_page3.get_stay_alert_in_alarm_overview(n),
                            'exitGeozone': self.statistical_form_page3.get_linger_alert_in_alarm_overview(n),
                            'overspeedPlatform': self.statistical_form_page3.get_illegal_mobile_alert_in_alarm_overview(
                                n),
                            'riskPointAlarm': self.statistical_form_page3.get_risk_point_alert_in_alarm_overview(
                                n),
                            'sensitiveAreasFence': self.statistical_form_page3.insufficient_battery_back_up_alert_in_alarm_overview(
                                n),
                            'stayAlert': self.statistical_form_page3.get_over_step_alert_in_alarm_overview(n),
                            'longtimeNotIntoFence': self.statistical_form_page3.get_sensitive_areas_fence_in_alarm_overview(
                                n),
                            'longtimeNotOutFence': self.statistical_form_page3.get_over_speed_platform_in_alarm_overview(
                                n)
                        })
                    print(web_data)
                    self.assertEqual(len(web_data), len(res_data))
                    for datas in web_data:
                        self.assertIn(datas, res_data)

                    for datas2 in res_data:
                        self.assertIn(datas2, web_data)

            self.driver.default_frame()
        csv_file.close()
コード例 #9
0
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()
コード例 #10
0
 def instance_search_sql(self):
     search_sql = SearchSql(self.driver, self.base_url)
     return search_sql
コード例 #11
0
class TestCase603FormPortSearchStaySearch(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.seasrch_sql = SearchSql(self.driver, self.base_url)
        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.statistical_form_page4 = StatisticFormPage4(
            self.driver, self.base_url)
        # 打开页面,填写用户名、密码、点击登录
        self.base_page.open_page()
        self.assert_text = AssertText()
        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_stay_search_port(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_stay_form_button()
        # 断言
        self.assertEqual(
            self.assert_text.statistical_form_stay_form(),
            self.statistical_form_page.
            actual_text_after_click_stay_form_button())

        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'sport_statistical_stay_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],
                'choose_date': row[1],
                'begin_time': row[2],
                'end_time': row[3]
            }
            # 搜索数据
            self.statistical_form_page.add_data_to_search_stay_form(
                search_data)
            self.statistical_form_page.switch_to_stay_report_form_frame()
            total_page = self.statistical_form_page4.get_total_page_in_over_stay_form(
            )
            begin_time = self.statistical_form_page4.get_over_stay_report_form_begin_time(
            )
            end_time = self.statistical_form_page4.get_over_stay_report_form_end_time(
            )
            all_dev = self.seasrch_sql.search_current_account_equipment(
                search_data['search_user'])
            imeis = self.statistical_form_page3.change_dev_imei_format(all_dev)
            total_saty_time = self.statistical_form_page4.get_total_stay_time_in_over_stay_form(
            )

            print(begin_time)
            print(end_time)
            print("总计", total_saty_time)
            print(type(total_saty_time))

            if total_page == 0:
                # 连接接口
                request_url = request_base_url()
                request_params = {
                    '_method_': 'getStopSegment',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'acc': "off"
                }
                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_stay_form(
                )
                web_data = []
                for n in range(total_number_per_page):
                    web_data.append({
                        # 'addr': self.statistical_form_page4.get_addr_in_over_stay_form(n),
                        'endTime':
                        self.statistical_form_page4.
                        get_end_time_in_over_stay_form(n),
                        'imei':
                        self.statistical_form_page4.get_imei_in_over_stay_form(
                            n),
                        'lat':
                        self.statistical_form_page4.get_lat_in_over_stay_form(
                            n),
                        'lng':
                        self.statistical_form_page4.get_lng_in_over_stay_form(
                            n),
                        'startTime':
                        self.statistical_form_page4.
                        get_start_time_in_over_stay_form(n),
                    })
                print("页面数据", web_data)
                # 连接接口
                request_url = request_base_url()
                request_params = {
                    '_method_': 'getStopSegment',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'acc': "off"
                }
                res = requests.post(request_url, data=request_params)
                sleep(30)
                response = res.json()
                res_data = response['data']
                for data in res_data:
                    del data['acc'], data['durSecond']
                print("接口数据", 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_stay_form(
                    )
                    for n in range(total_number_per_page):
                        web_data.append({
                            # 'addr': self.statistical_form_page4.get_addr_in_over_stay_form(n),
                            'endTime':
                            self.statistical_form_page4.
                            get_end_time_in_over_stay_form(n),
                            'imei':
                            self.statistical_form_page4.
                            get_imei_in_over_stay_form(n),
                            'lat':
                            self.statistical_form_page4.
                            get_lat_in_over_stay_form(n),
                            'lng':
                            self.statistical_form_page4.
                            get_lng_in_over_stay_form(n),
                            'startTime':
                            self.statistical_form_page4.
                            get_start_time_in_over_stay_form(n),
                        })
                print("页面数据", web_data)
                print(len(web_data))
                # 连接接口
                request_url = request_base_url()
                request_params = {
                    '_method_': 'getStopSegment',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'acc': "off"
                }
                res = requests.post(request_url, data=request_params)
                sleep(30)
                response = res.json()
                res_data = response['data']
                for data in res_data:
                    del data['acc'], data['durSecond']
                print("接口数据", res_data)
                print(len(res_data))
                self.assertEqual(web_data, res_data)

            # 总计停留时间
            # 连接接口
            request_url = request_base_url()
            request_params = {
                '_method_': 'getStopSegmentSum',
                'imeis': imeis,
                'startTime': begin_time,
                'endTime': end_time,
                'acc': "off"
            }
            res = requests.post(request_url, data=request_params)
            sleep(20)
            response = res.json()
            res_data = response['data']

            if total_saty_time == "0":
                self.assertEqual(int(total_saty_time), res_data)
            else:
                time = total_saty_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)

            self.driver.default_frame()
        csv_file.close()
class TestCase174SportStatisticalOverview(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.statistical_form_page3 = StatisticFormPage3(
            self.driver, self.base_url)
        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.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_sport_statistical_sport_overview(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(
            ))
        # 读数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'sport_statistical_sport_overview_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],
                'choose_date': row[1],
                'begin_time': row[2],
                'end_time': row[3]
            }
            self.statistical_form_page.add_data_to_search_sport_overview(
                search_data)

            # 处理搜索出来的数据
            web_total_number = self.statistical_form_page3.get_web_search_total_number_sport_overview(
            )
            data_web = []
            for n in range(web_total_number):
                data_web.append({
                    'imei':
                    self.statistical_form_page3.get_imei_in_sport_overview(n),
                    'mileage':
                    self.statistical_form_page3.get_mileage_in_sport_overview(
                        n),
                    'overSpeedTimes':
                    self.statistical_form_page3.
                    get_over_speed_times_in_sport_overview(n),
                    'stopTimes':
                    self.statistical_form_page3.
                    get_stop_times_in_sport_overview(n)
                })
            print('web', data_web)
            # 连接数据库
            all_dev = self.search_sql.search_current_account_equipment(
                search_data['search_user'])
            imeis = self.statistical_form_page3.change_dev_imei_format(all_dev)
            print(imeis)
            begin_time = self.statistical_form_page3.get_sport_overview_form_begin_time(
            )
            end_time = self.statistical_form_page3.get_sport_overview_form_end_time(
            )
            get_current_userid = self.search_sql.search_current_account_user_id(
                search_data['search_user'])
            # 连接接口
            request_url = request_base_url()
            request_params = {
                '_method_': 'getRunSummary',
                'imeis': imeis,
                'startTime': begin_time,
                'endTime': end_time,
                'userIds': get_current_userid
            }
            res = requests.post(request_url, data=request_params)
            sleep(30)
            response = res.json()
            res_data = response['data']
            for data in res_data:
                # if data['stopTimes'] != 0 or data['mileage'] != 0 or data['overSpeedTimes'] != 0:
                try:
                    del data['atDay']
                except:
                    pass
            print('res', res_data)
            self.assertEqual(len(data_web), len(res_data))

            for datas in data_web:
                self.assertIn(datas, res_data)
            for datas2 in res_data:
                self.assertIn(datas2, data_web)
            self.driver.default_frame()
        csv_file.close()
class TestCase143SportStatisticalTracelReportForm(unittest.TestCase):
    '''
    运动统计 行程报表
    author:zhangAo
    '''
    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()

        # 登录之后点击控制台,然后点击设置
        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_tracel_report_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_mileage_form_button()
        # 断言
        self.assertEqual(
            self.assert_text.statistical_form_tracl_form(),
            self.statistical_form_page.
            actual_text_after_click_mileage_form_button())
        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'sport_statistical_milage_form_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],
                'type': row[1],
                'choose_date': row[2],
                'begin_time': row[3],
                'end_time': row[4]
            }
            self.statistical_form_page.add_data_to_search_mileage_form(
                search_data)
            self.statistical_form_page.switch_to_tracel_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_sport_mile_sql(all_dev, search_data)
            get_total_sql_01 = self.search_sql.search_sport_mile_sql_01(
                all_dev, search_data)
            get_total_sql_02 = self.search_sql.search_sport_mile_sql_02(
                all_dev, search_data)
            get_total_sql_03 = self.search_sql.search_sport_mile_sql_03(
                all_dev, search_data)
            get_total_sql_04 = self.search_sql.search_sport_mile_sql_04(
                all_dev, search_data)
            get_total_sql_05 = self.search_sql.search_sport_mile_sql_05(
                all_dev, search_data)
            get_total_sql_06 = self.search_sql.search_sport_mile_sql_06(
                all_dev, search_data)
            get_total_sql_07 = self.search_sql.search_sport_mile_sql_07(
                all_dev, search_data)
            get_total_sql_08 = self.search_sql.search_sport_mile_sql_08(
                all_dev, search_data)
            get_total_sql_09 = self.search_sql.search_sport_mile_sql_09(
                all_dev, search_data)
            get_total_sql_10 = self.search_sql.search_sport_mile_sql_10(
                all_dev, search_data)
            get_total_sql_11 = self.search_sql.search_sport_mile_sql_11(
                all_dev, search_data)
            get_total_sql_12 = self.search_sql.search_sport_mile_sql_12(
                all_dev, search_data)
            print(get_total_sql_01)

            # 判断查询的条件
            if search_data['type'] == 'mile':
                # 查询的选择里程
                '''cursor_02.execute(get_total_sql_01)
                get_all_mlie_and_time = cursor_02.fetchall()
                get_all_mlie_and_time_list = []
                for range1 in get_all_mlie_and_time:
                    for range2 in range1:
                        get_all_mlie_and_time_list.append(range2)'''

                cursor_02.execute(get_total_sql_01)
                get_all_mlie_and_time_01 = cursor_02.fetchall()
                get_all_mlie_and_time_list_01 = []
                for range1 in get_all_mlie_and_time_01:
                    for range2 in range1:
                        get_all_mlie_and_time_list_01.append(range2)

                cursor_02.execute(get_total_sql_02)
                get_all_mlie_and_time_02 = cursor_02.fetchall()
                get_all_mlie_and_time_list_02 = []
                for range1 in get_all_mlie_and_time_02:
                    for range2 in range1:
                        get_all_mlie_and_time_list_02.append(range2)

                cursor_02.execute(get_total_sql_03)
                get_all_mlie_and_time_03 = cursor_02.fetchall()
                get_all_mlie_and_time_list_03 = []
                for range1 in get_all_mlie_and_time_03:
                    for range2 in range1:
                        get_all_mlie_and_time_list_03.append(range2)

                cursor_02.execute(get_total_sql_04)
                get_all_mlie_and_time_04 = cursor_02.fetchall()
                get_all_mlie_and_time_list_04 = []
                for range1 in get_all_mlie_and_time_04:
                    for range2 in range1:
                        get_all_mlie_and_time_list_04.append(range2)

                cursor_02.execute(get_total_sql_05)
                get_all_mlie_and_time_05 = cursor_02.fetchall()
                get_all_mlie_and_time_list_05 = []
                for range1 in get_all_mlie_and_time_05:
                    for range2 in range1:
                        get_all_mlie_and_time_list_05.append(range2)

                cursor_02.execute(get_total_sql_06)
                get_all_mlie_and_time_06 = cursor_02.fetchall()
                get_all_mlie_and_time_list_06 = []
                for range1 in get_all_mlie_and_time_06:
                    for range2 in range1:
                        get_all_mlie_and_time_list_06.append(range2)

                cursor_02.execute(get_total_sql_07)
                get_all_mlie_and_time_07 = cursor_02.fetchall()
                get_all_mlie_and_time_list_07 = []
                for range1 in get_all_mlie_and_time_07:
                    for range2 in range1:
                        get_all_mlie_and_time_list_07.append(range2)

                cursor_02.execute(get_total_sql_08)
                get_all_mlie_and_time_08 = cursor_02.fetchall()
                get_all_mlie_and_time_list_08 = []
                for range1 in get_all_mlie_and_time_08:
                    for range2 in range1:
                        get_all_mlie_and_time_list_08.append(range2)

                cursor_02.execute(get_total_sql_09)
                get_all_mlie_and_time_09 = cursor_02.fetchall()
                get_all_mlie_and_time_list_09 = []
                for range1 in get_all_mlie_and_time_09:
                    for range2 in range1:
                        get_all_mlie_and_time_list_09.append(range2)

                cursor_02.execute(get_total_sql_10)
                get_all_mlie_and_time_10 = cursor_02.fetchall()
                get_all_mlie_and_time_list_10 = []
                for range1 in get_all_mlie_and_time_10:
                    for range2 in range1:
                        get_all_mlie_and_time_list_10.append(range2)

                cursor_02.execute(get_total_sql_11)
                get_all_mlie_and_time_11 = cursor_02.fetchall()
                get_all_mlie_and_time_list_11 = []
                for range1 in get_all_mlie_and_time_11:
                    for range2 in range1:
                        get_all_mlie_and_time_list_11.append(range2)

                cursor_02.execute(get_total_sql_12)
                get_all_mlie_and_time_12 = cursor_02.fetchall()
                get_all_mlie_and_time_list_12 = []
                for range1 in get_all_mlie_and_time_12:
                    for range2 in range1:
                        get_all_mlie_and_time_list_12.append(range2)

                total = len(get_all_mlie_and_time_list_01) / 2 + len(
                    get_all_mlie_and_time_list_02
                ) / 2 + len(get_all_mlie_and_time_list_03) / 2 + len(
                    get_all_mlie_and_time_list_04
                ) / 2 + len(get_all_mlie_and_time_list_05) / 2 + len(
                    get_all_mlie_and_time_list_06
                ) / 2 + len(get_all_mlie_and_time_list_07) / 2 + len(
                    get_all_mlie_and_time_list_08) / 2 + len(
                        get_all_mlie_and_time_list_09) / 2 + len(
                            get_all_mlie_and_time_list_10) / 2 + len(
                                get_all_mlie_and_time_list_11) / 2 + len(
                                    get_all_mlie_and_time_list_12) / 2
                web_total = self.statistical_form_page.get_total_search_mileage_form(
                )
                self.assertEqual(total, web_total)

                # 拆分列表
                all_mile_list = []
                all_time_list = []
                '''for n in range(len(get_all_mlie_and_time_list)):
                    if n % 2 == 0:
                        all_mile_list.append(get_all_mlie_and_time_list[n])
                    elif n % 2 == 1:
                        all_time_list.append(get_all_mlie_and_time_list[n])'''

                # 拆分列表
                all_mile_list_01 = []
                all_time_list_01 = []
                for n in range(len(get_all_mlie_and_time_list_01)):
                    if n % 2 == 0:
                        all_mile_list_01.append(
                            get_all_mlie_and_time_list_01[n])
                    elif n % 2 == 1:
                        all_time_list_01.append(
                            get_all_mlie_and_time_list_01[n])

                # 拆分列表
                all_mile_list_02 = []
                all_time_list_02 = []
                for n in range(len(get_all_mlie_and_time_list_02)):
                    if n % 2 == 0:
                        all_mile_list_02.append(
                            get_all_mlie_and_time_list_02[n])
                    elif n % 2 == 1:
                        all_time_list_02.append(
                            get_all_mlie_and_time_list_02[n])

                # 拆分列表
                all_mile_list_03 = []
                all_time_list_03 = []
                for n in range(len(get_all_mlie_and_time_list_03)):
                    if n % 2 == 0:
                        all_mile_list_03.append(
                            get_all_mlie_and_time_list_03[n])
                    elif n % 2 == 1:
                        all_time_list_03.append(
                            get_all_mlie_and_time_list_03[n])

                # 拆分列表
                all_mile_list_04 = []
                all_time_list_04 = []
                for n in range(len(get_all_mlie_and_time_list_04)):
                    if n % 2 == 0:
                        all_mile_list_04.append(
                            get_all_mlie_and_time_list_04[n])
                    elif n % 2 == 1:
                        all_time_list_04.append(
                            get_all_mlie_and_time_list_04[n])

                # 拆分列表
                all_mile_list_05 = []
                all_time_list_05 = []
                for n in range(len(get_all_mlie_and_time_list_05)):
                    if n % 2 == 0:
                        all_mile_list_05.append(
                            get_all_mlie_and_time_list_05[n])
                    elif n % 2 == 1:
                        all_time_list_05.append(
                            get_all_mlie_and_time_list_05[n])

                # 拆分列表
                all_mile_list_06 = []
                all_time_list_06 = []
                for n in range(len(get_all_mlie_and_time_list_06)):
                    if n % 2 == 0:
                        all_mile_list_06.append(
                            get_all_mlie_and_time_list_06[n])
                    elif n % 2 == 1:
                        all_time_list_06.append(
                            get_all_mlie_and_time_list_06[n])

                # 拆分列表
                all_mile_list_07 = []
                all_time_list_07 = []
                for n in range(len(get_all_mlie_and_time_list_07)):
                    if n % 2 == 0:
                        all_mile_list_07.append(
                            get_all_mlie_and_time_list_07[n])
                    elif n % 2 == 1:
                        all_time_list_07.append(
                            get_all_mlie_and_time_list_07[n])

                # 拆分列表
                all_mile_list_08 = []
                all_time_list_08 = []
                for n in range(len(get_all_mlie_and_time_list_08)):
                    if n % 2 == 0:
                        all_mile_list_08.append(
                            get_all_mlie_and_time_list_08[n])
                    elif n % 2 == 1:
                        all_time_list_08.append(
                            get_all_mlie_and_time_list_08[n])

                # 拆分列表
                all_mile_list_09 = []
                all_time_list_09 = []
                for n in range(len(get_all_mlie_and_time_list_09)):
                    if n % 2 == 0:
                        all_mile_list_09.append(
                            get_all_mlie_and_time_list_09[n])
                    elif n % 2 == 1:
                        all_time_list_09.append(
                            get_all_mlie_and_time_list_09[n])

                # 拆分列表
                all_mile_list_10 = []
                all_time_list_10 = []
                for n in range(len(get_all_mlie_and_time_list_10)):
                    if n % 2 == 0:
                        all_mile_list_10.append(
                            get_all_mlie_and_time_list_10[n])
                    elif n % 2 == 1:
                        all_time_list_10.append(
                            get_all_mlie_and_time_list_10[n])

                # 拆分列表
                all_mile_list_11 = []
                all_time_list_11 = []
                for n in range(len(get_all_mlie_and_time_list_11)):
                    if n % 2 == 0:
                        all_mile_list_11.append(
                            get_all_mlie_and_time_list_11[n])
                    elif n % 2 == 1:
                        all_time_list_11.append(
                            get_all_mlie_and_time_list_11[n])

                # 拆分列表
                all_mile_list_12 = []
                all_time_list_12 = []
                for n in range(len(get_all_mlie_and_time_list_12)):
                    if n % 2 == 0:
                        all_mile_list_12.append(
                            get_all_mlie_and_time_list_12[n])
                    elif n % 2 == 1:
                        all_time_list_12.append(
                            get_all_mlie_and_time_list_12[n])

                # 计算总里程 和 总时间
                total_mile = sum(all_mile_list) + sum(all_mile_list_01) + sum(
                    all_mile_list_02
                ) + sum(all_mile_list_03) + sum(all_mile_list_04) + sum(
                    all_mile_list_05) + sum(all_mile_list_06) + sum(
                        all_mile_list_07) + sum(all_mile_list_08) + sum(
                            all_mile_list_09) + sum(all_mile_list_10) + sum(
                                all_mile_list_11) + sum(all_mile_list_12)
                total_time = sum(all_time_list) + 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_09) + sum(all_time_list_10) + sum(
                                all_time_list_11) + sum(all_time_list_12)
                # 断言总时间和总里程,总油耗
                web_total_mile = self.statistical_form_page.get_mileage_all_mile(
                )
                self.assertAlmostEqual(total_mile / 1000,
                                       float(web_total_mile))

                web_total_time = self.statistical_form_page.get_mileage_all_time(
                )
                chang_total_time_type = self.statistical_form_page.change_sec_time(
                    total_time)
                self.assertEqual(chang_total_time_type, web_total_time)

                # 计算总油耗
                if total_mile == 0:
                    self.assertEqual(
                        '0',
                        self.statistical_form_page.get_mileage_total_oil())
                else:
                    if self.statistical_form_page.get_mileage_total_oil(
                    ) == '0':
                        pass
                    else:
                        get_total_oil = total_mile / 1000 / 100 * 8
                        total_oil = '%.2f' % get_total_oil
                        self.assertEqual(
                            str(total_oil),
                            self.statistical_form_page.get_mileage_total_oil())

            # 点击导出
            self.driver.default_frame()
            cursor_02.close()
            connect_02.close()
        csv_file.close()
コード例 #14
0
class TestCase144SportStatisticalSpeedForm(unittest.TestCase):
    '''
    运动报表,超速报表
    author:zhangAo
    '''

    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.base_page.open_page()
        self.assert_text = AssertText()
        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_speed_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_over_speed_button()
        # 断言

        self.assertEqual(self.assert_text.statistical_form_over_speed_form(),
                         self.statistical_form_page.actual_text_after_click_over_speed_button())

        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv('sport_statistical_over_speed_search_dara.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],
                'speed': row[1],
                'choose_date': row[2],
                'begin_time': row[3],
                'end_time': row[4]
            }
            self.statistical_form_page.add_data_to_search_over_speed(search_data)
            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_sport_over_speed_sql(all_dev, search_data)
            print(get_total_sql)

            cursor_02.execute(get_total_sql)
            get_total = cursor_02.fetchall()
            total_list = []
            for range1 in get_total:
                for range2 in range1:
                    total_list.append(range2)
            total = len(total_list)
            web_total = self.statistical_form_page.get_total_search_over_speed_number()
            self.assertEqual(total, web_total)

            # 点击导出
            self.driver.default_frame()
            cursor_02.close()
            connect_02.close()
        csv_file.close()
コード例 #15
0
class TestCase140AlarmDetailSearch(unittest.TestCase):
    '''
    告警详情页面搜索
    author:zhangAo
    '''
    def setUp(self):
        # 前置条件
        # 实例化对象
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)

        self.alarm_info_page = AlarmInfoPage(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_page = StatisticalFormPage(
            self.driver, self.base_url)
        self.connect_sql = ConnectSql()
        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.driver.clear_cookies()
        self.assert_text = AssertText()
        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_alarm_detail_search(self):
        # 断言url
        expect_url = self.base_url + '/deviceReport/statisticalReport'
        self.assertEqual(expect_url,
                         self.alarm_info_page.actual_url_click_alarm())
        # 点击告警详情
        self.alarm_info_page.click_alarm_detail_list()
        # 断言
        self.driver.switch_to_frame('x,//*[@id="alarmDdetailsFrame"]')
        self.assertEqual(
            self.assert_text.account_center_page_alarm_details_text(),
            self.alarm_info_page.actual_text_after_click_alarm_detail())
        self.driver.default_frame()
        sleep(3)
        # 读数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'alarm_detail_search_data.csv')
        csv_data = csv.reader(csv_file)

        is_header = True
        for row in csv_data:
            if is_header:
                is_header = False
                continue
            data = {
                'user_name': row[0],
                'type': row[1],
                'status': row[2],
                'alarm_begin_time': row[3],
                'alarm_end_time': row[4],
                'push_begin_time': row[5],
                'push_end_time': row[6],
                'next_user': row[7]
            }
            self.alarm_info_page.add_data_to_search_alarm_detail(data)
            self.driver.switch_to_frame('x,//*[@id="alarmDdetailsFrame"]')

            # 连接数据库
            connect = self.connect_sql.connect_tuqiang_sql()
            # 创建游标
            cursor = connect.cursor()
            # 查询搜索用户的uesrID
            get_user_id_sql = "SELECT userId FROM user_info WHERE account ='" + data[
                'user_name'] + "';"
            # 执行sql
            cursor.execute(get_user_id_sql)
            get_user_id = cursor.fetchall()
            user_id = get_user_id[0][0]

            # 当前用户下设置
            get_current_user_all_equipment = "SELECT a.imei FROM equipment_mostly AS a WHERE a.status = 'NORMAL' and a.userId = " + user_id + " and a.expiration > CURDATE();"
            cursor.execute(get_current_user_all_equipment)
            all_equipment = cursor.fetchall()

            all_equipment_list = []
            for range1 in all_equipment:
                for range2 in range1:
                    all_equipment_list.append(range2)

            current_user_all_equipment = tuple(all_equipment_list)

            cursor.close()
            connect.close()

            # 连接另一个数据库
            connect_02 = self.connect_sql.connect_tuqiang_sql()
            # 创建游标
            cursor_02 = connect_02.cursor()
            # 判断查询条件

            get_total_sql = self.search_sql.search_alarm_details_sql(
                user_id, current_user_all_equipment, data)
            # 执行sql
            print(get_total_sql)
            cursor_02.execute(get_total_sql)
            get_total = cursor_02.fetchall()
            total_list = []
            for range1 in get_total:
                for range2 in range1:
                    total_list.append(range2)
            total = len(total_list)
            print(total)
            web_total = self.alarm_info_page.get_search_total()
            self.assertEqual(total, web_total)
            self.driver.default_frame()

            cursor_02.close()
            connect_02.close()
        csv_file.close()
class TestCase182AlarmDetailSearch(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.alarm_info_page = AlarmInfoPage(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_page = StatisticalFormPage(self.driver, self.base_url)
        self.connect_sql = ConnectSql()
        self.statistical_form_page3 = StatisticFormPage3(self.driver, self.base_url)
        self.seasrch_sql = SearchSql(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.assert_text = AssertText()
        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_alarm_detail_search(self):
        # 断言url
        expect_url = self.base_url + '/deviceReport/statisticalReport'
        self.assertEqual(expect_url, self.alarm_info_page.actual_url_click_alarm())
        # 点击告警详情
        self.alarm_info_page.click_alarm_detail_list()
        # 选择全部的告警类型查询
        self.statistical_form_page3.select_all_alarm_type_in_alarm_detail_search()
        # 读数据
        csv_file = self.statistical_form_page_read_csv.read_csv('alarm_detail_search_data.csv')
        csv_data = csv.reader(csv_file)

        is_header = True
        for row in csv_data:
            if is_header:
                is_header = False
                continue
            data = {
                'user_name': row[0],
                'type': row[1],
                'status': row[2],
                'alarm_begin_time': row[3],
                'alarm_end_time': row[4],
                'push_begin_time': row[5],
                'push_end_time': row[6],
                'is_input_dev': row[7]
            }
            self.statistical_form_page3.add_data_to_search_alarm_detail(data)

            get_alarm_begin_time = self.statistical_form_page3.get_alarm_begin_time_in_alarm_detail_page()
            get_alarm_end_time = self.statistical_form_page3.get_alarm_end_time_in_alarm_detail_page()
            get_push_begin_time = self.statistical_form_page3.get_push_begin_time_in_alarm_detail_page()
            get_push_end_time = self.statistical_form_page3.get_push_end_time_in_alarm_detail_page()
            all_dev = self.seasrch_sql.search_current_account_equipment(data['user_name'])
            imeis = self.statistical_form_page3.change_dev_imei_format(all_dev)
            get_current_userid = self.seasrch_sql.search_current_account_user_id(data['user_name'])
            request_url = request_base_url()

            if data['is_input_dev'] == '0':
                request_params = {
                    '_method_': 'getAlarmDetailNoPaging',
                    'startTime': get_alarm_begin_time,
                    'endTime': get_alarm_end_time,
                    'userIds': get_current_userid,
                }
                res = requests.post(request_url, data=request_params)
                sleep(20)
                response = res.json()
                res_data = response['data']
                for data_1 in res_data:
                    del data_1['alarmType'], data_1['id'], data_1['lat'], data_1['lng'], data_1['speed'], data_1[
                        'status'], data_1['userId']
                print(res_data)

                web_total_number = self.statistical_form_page3.get_web_total_number_in_alarm_detail_page()
                web_data = []
                for n in range(web_total_number):
                    web_data.append({
                        'imei': self.statistical_form_page3.get_imei_in_alarm_detail(n),
                        'createTime': self.statistical_form_page3.get_creat_time_in_alarm_detail(n),
                        'pushTime': self.statistical_form_page3.get_push_time_in_alarm_detail(n),
                        'addr': self.statistical_form_page3.get_addr_in_alarm_detail(n),
                        'readStatus': self.statistical_form_page3.get_read_status_in_alarm_detail(n)
                    })
                print(web_data)
                self.assertEqual(web_data, res_data)

            elif data['is_input_dev'] == '1':
                request_params = {
                    '_method_': 'getAlarmDetailNoPaging',
                    'startCreateTime': get_push_begin_time,
                    'endCreateTime': get_push_end_time,
                    'userIds': get_current_userid,
                    'imeis': imeis
                }
                res = requests.post(request_url, data=request_params)
                sleep(20)
                response = res.json()
                res_data = response['data']
                for data_1 in res_data:
                    del data_1['alarmType'], data_1['id'], data_1['lat'], data_1['lng'], data_1['speed'], data_1[
                        'status'], data_1['userId']
                print(res_data)

                web_total_number = self.statistical_form_page3.get_web_total_number_in_alarm_detail_page()
                web_data = []
                for n in range(web_total_number):
                    web_data.append({
                        'imei': self.statistical_form_page3.get_imei_in_alarm_detail(n),
                        'createTime': self.statistical_form_page3.get_creat_time_in_alarm_detail(n),
                        'pushTime': self.statistical_form_page3.get_push_time_in_alarm_detail(n),
                        'addr': self.statistical_form_page3.get_addr_in_alarm_detail(n),
                        'readStatus': self.statistical_form_page3.get_read_status_in_alarm_detail(n)
                    })
                print(web_data)
                self.assertEqual(web_data, res_data)
            self.driver.default_frame()
        csv_file.close()
コード例 #17
0
class TestCase142SportStatisticalElectricReport(unittest.TestCase):
    '''
    电量报表
    author:zhangAo
    '''
    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()

        # 登录之后点击控制台,然后点击设置
        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_electric_report(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_electric_report_form_buttons()
        # 断言
        self.assertEqual(
            self.assert_text.statistical_form_electric_report(),
            self.statistical_form_page.
            actual_text_after_click_electric_report_buttons())
        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'search_electric_report_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],
                'electric': row[1],
                'dev_type': row[2],
                'next': row[3]
            }
            self.statistical_form_page.add_data_to_search_electric_report(
                search_data)

            all_dev = self.search_sql.search_current_account_equipment(
                search_data['search_user'])
            all_user_dev = self.search_sql.search_current_account_equipment_and_next(
                search_data['search_user'])
            connect = self.connect_sql.connect_tuqiang_sql()
            cursor = connect.cursor()
            get_electric_total_sql = self.search_sql.get_total_electric_report_sql(
                all_user_dev, all_dev, search_data)
            print(get_electric_total_sql)
            cursor.execute(get_electric_total_sql)
            get_total_number = cursor.fetchall()
            total_list = []
            for range1 in get_total_number:
                for range2 in range1:
                    total_list.append(range2)
            cursor.close()
            connect.close()
            total = len(total_list)
            web_total = self.statistical_form_page.get_web_total_electric_report(
            )
            self.assertEqual(total, web_total)
        csv_file.close()
コード例 #18
0
class TestCase177SportStatisticalSpeedForm(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.seasrch_sql = SearchSql(self.driver, self.base_url)
        self.statistical_form_page3 = StatisticFormPage3(
            self.driver, self.base_url)
        # 打开页面,填写用户名、密码、点击登录
        self.base_page.open_page()
        self.assert_text = AssertText()
        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_speed_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_over_speed_button()
        # 断言

        self.assertEqual(
            self.assert_text.statistical_form_over_speed_form(),
            self.statistical_form_page.
            actual_text_after_click_over_speed_button())

        # 读取查询数据
        csv_file = self.statistical_form_page_read_csv.read_csv(
            'sport_statistical_over_speed_search_dara.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],
                'speed': row[1],
                'choose_date': row[2],
                'begin_time': row[3],
                'end_time': row[4]
            }
            self.statistical_form_page.add_data_to_search_over_speed(
                search_data)
            sleep(4)
            total_page = self.statistical_form_page3.get_total_page_in_over_speed_form(
            )
            print(total_page)
            begin_time = self.statistical_form_page3.get_over_speed_report_form_begin_time(
            )
            end_time = self.statistical_form_page3.get_over_speed_report_form_end_time(
            )
            all_dev = self.seasrch_sql.search_current_account_equipment(
                search_data['search_user'])
            imeis = self.statistical_form_page3.change_dev_imei_format(all_dev)
            get_current_userid = self.seasrch_sql.search_current_account_user_id(
                search_data['search_user'])

            if total_page == 0:
                # 连接接口
                request_url = request_base_url()
                request_params = {
                    '_method_': 'getOverSpeed',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'speed': int(search_data['speed']),
                    'userIds': get_current_userid
                }
                res = requests.post(request_url, data=request_params)
                sleep(30)
                response = res.json()
                print(response)
                self.assertEqual(400, response['code'])
                self.assertEqual('没有找到数据', response['msg'])

            elif total_page == 1:
                total_number_per_page = self.statistical_form_page3.get_total_number_per_page_in_over_speed_form(
                )
                web_data = []
                for n in range(total_number_per_page):
                    web_data.append({
                        'imei':
                        self.statistical_form_page3.
                        get_imei_in_over_speed_form(n),
                        'speed':
                        self.statistical_form_page3.
                        get_speed_in_over_speed_form(n),
                        # 'addr': self.statistical_form_page3.get_addr_in_over_speed_form(n),
                        'time':
                        self.statistical_form_page3.
                        get_time_in_over_speed_form(n),
                        'lat':
                        self.statistical_form_page3.get_lat_in_over_speed_form(
                            n),
                        'lng':
                        self.statistical_form_page3.get_lng_in_over_speed_form(
                            n)
                    })
                print(web_data)
                # 连接接口
                request_url = request_base_url()
                request_params = {
                    '_method_': 'getOverSpeed',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'speed': int(search_data['speed']),
                    'userIds': get_current_userid
                }
                res = requests.post(request_url, data=request_params)
                sleep(30)
                response = res.json()
                res_datas = response['data']
                for data in res_datas:
                    del data['status'], data['times'], data['addr']
                print(res_datas)
                self.assertEqual(web_data, res_datas)
            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_page3.get_total_number_per_page_in_over_speed_form(
                    )
                    for n in range(total_number_per_page):
                        web_data.append({
                            'imei':
                            self.statistical_form_page3.
                            get_imei_in_over_speed_form(n),
                            'speed':
                            self.statistical_form_page3.
                            get_speed_in_over_speed_form(n),
                            # 'addr': self.statistical_form_page3.get_addr_in_over_speed_form(n),
                            'time':
                            self.statistical_form_page3.
                            get_time_in_over_speed_form(n),
                            'lat':
                            self.statistical_form_page3.
                            get_lat_in_over_speed_form(n),
                            'lng':
                            self.statistical_form_page3.
                            get_lng_in_over_speed_form(n)
                        })
                print(web_data)
                # 连接接口
                request_url = request_base_url()
                request_params = {
                    '_method_': 'getOverSpeed',
                    'imeis': imeis,
                    'startTime': begin_time,
                    'endTime': end_time,
                    'speed': int(search_data['speed']),
                    'userIds': get_current_userid
                }
                res = requests.post(request_url, data=request_params)
                sleep(30)
                response = res.json()
                res_datas = response['data']
                for data in res_datas:
                    del data['status'], data['times'], data['addr']
                print(res_datas)
                self.assertEqual(web_data, res_datas)
            self.driver.default_frame()
        csv_file.close()