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()
예제 #2
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()