def setUp(self):
     self.driver = AutomateDriverServer(choose='CHROME')
     self.base_url = self.driver.base_url
     self.base_page = BasePageServer(self.driver, self.base_url)
     self.login_page = LoginPage(self.driver, self.base_url)
     self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url)
     self.account_center_page_details = AccountCenterDetailsPage(self.driver, self.base_url)
     self.account_center_page_refill_card = AccountCenterRefillCardPage(self.driver, self.base_url)
     self.log_in_base = LogInBaseServer(self.driver, self.base_page)
     self.connect_sql = ConnectSql()
     self.search_sql = SearchSql()
     self.assert_text = AssertText()
     self.driver.set_window_max()
     self.account_center_page_read_csv = AccountCenterPageReadCsv()
     self.log_in_base = LogInBaseServer(self.driver, self.base_page)
     self.driver.wait(1)
     self.driver.clear_cookies()
     self.driver.wait(1)
 def setUp(self):
     self.driver = AutomateDriverServer(choose='chrome')
     self.base_url = self.driver.base_url
     self.base_page = BasePageServer(self.driver, self.base_url)
     self.login_page = LoginPage(self.driver, self.base_url)
     self.account_center_page_operation_log = AccountCenterOperationLogPage(
         self.driver, self.base_url)
     self.account_center_page_navi_bar = AccountCenterNaviBarPage(
         self.driver, self.base_url)
     self.account_center_page_msg_center = AccountCenterMsgCenterPage(
         self.driver, self.base_url)
     self.assert_text = AssertText()
     self.driver.set_window_max()
     self.account_center_page_read_csv = AccountCenterPageReadCsv()
     self.connect_sql = ConnectSql()
     self.search_sql = SearchSql()
     self.log_in_base = LogInBaseServer(self.driver, self.base_page)
     self.driver.wait(1)
     self.driver.clear_cookies()
     self.driver.wait(1)
class TestCase07AccountCenterMsgSearch(unittest.TestCase):
    def setUp(self):
        self.driver = AutomateDriverServer(choose='chrome')
        self.base_url = self.driver.base_url
        self.base_page = BasePageServer(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.account_center_page_operation_log = AccountCenterOperationLogPage(
            self.driver, self.base_url)
        self.account_center_page_navi_bar = AccountCenterNaviBarPage(
            self.driver, self.base_url)
        self.account_center_page_msg_center = AccountCenterMsgCenterPage(
            self.driver, self.base_url)
        self.assert_text = AssertText()
        self.driver.set_window_max()
        self.account_center_page_read_csv = AccountCenterPageReadCsv()
        self.connect_sql = ConnectSql()
        self.search_sql = SearchSql()
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

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

    def test_account_center_msg_search(self):
        self.base_page.open_page()
        self.log_in_base.log_in()
        self.account_center_page_navi_bar.click_account_center_button()

        # self.driver.switch_to_frame('x,//*[@id="usercenterFrame"]')
        # 获取登录账号的用户名
        current_account = self.log_in_base.get_log_in_account()
        #self.driver.default_frame()

        # 进入消息中心
        self.account_center_page_msg_center.enter_msg_center()
        self.driver.wait(10)

        # 进入iframe
        # self.account_center_page_msg_center.message_center_iframe()
        # 获取消息中心title
        msg_center_title = self.account_center_page_msg_center.get_msg_center_title(
        )
        # 验证消息中心title是否正确显示
        self.assertIn(
            self.assert_text.account_center_page_message_center_text(),
            msg_center_title, "消息中心title有误!")

        csv_file = self.account_center_page_read_csv.read_csv(
            'search_massage_data.csv')
        csv_data = csv.reader(csv_file)
        is_header = True
        for row in csv_data:
            if is_header:
                is_header = False
                continue
            search_data = {'imei': row[0], 'type': row[1], 'status': row[2]}
            # 搜索
            self.account_center_page_operation_log.add_data_to_search_massages(
                search_data)
            connect1 = self.connect_sql.connect_tuqiang_sql()
            # 创建数据库游标
            cur = connect1.cursor()
            # 执行sql脚本查询当前登录账号的userId,fullParent
            get_id_sql = "select o.account,o.userId,o.fullParentId from user_info o where o.account = '" + current_account + "';"
            cur.execute(get_id_sql)
            # 读取数据
            user_relation = cur.fetchall()
            # 遍历数据
            for row in user_relation:
                user_relation_id = {
                    "account": row[0],
                    "userId": row[1],
                    "fullParent": row[2]
                }

                # 执行sql脚本,根据当前登录账号的userId,fullParent查询出当前账户的所有下级账户
                get_lower_account_sql = "select userId from user_info where fullParentId like" + \
                                        "'" + user_relation_id["fullParent"] + user_relation_id["userId"] + "%'" + ";"
                cur.execute(get_lower_account_sql)
                # 读取数据
                lower_account = cur.fetchall()
                lower_account_list = [user_relation_id["userId"]]
                for range1 in lower_account:
                    for range2 in range1:
                        lower_account_list.append(range2)
                self.lower_account_tuple = tuple(lower_account_list)
            cur.close()
            connect1.close()

            connect = self.connect_sql.connect_tuqiang_sql()
            # 创建数据库游标
            cur = connect.cursor()
            get_total_sql = self.search_sql.search_massage_sql(
                self.lower_account_tuple, search_data)
            print(get_total_sql)
            cur.execute(get_total_sql)
            # 读取数据
            total_data = cur.fetchall()
            # 从数据tuple中获取最终查询记录统计条数
            total_list = []
            for range1 in total_data:
                for range2 in range1:
                    total_list.append(range2)
            total = len(total_list)
            print('本次查询数据库的条数为:%s' % total)
            web_total = self.account_center_page_operation_log.get_msg_number()
            print('本次查询页面的条数是:%s' % web_total)
            self.assertEqual(total, web_total)
            cur.close()
            connect.close()
        csv_file.close()
class TestCase450919AccountCenterRefillCardRefillRecordSearch(unittest.TestCase):
    def setUp(self):
        self.driver = AutomateDriverServer(choose='CHROME')
        self.base_url = self.driver.base_url
        self.base_page = BasePageServer(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.account_center_page_navi_bar = AccountCenterNaviBarPage(self.driver, self.base_url)
        self.account_center_page_details = AccountCenterDetailsPage(self.driver, self.base_url)
        self.account_center_page_refill_card = AccountCenterRefillCardPage(self.driver, self.base_url)
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.connect_sql = ConnectSql()
        self.search_sql = SearchSql()
        self.assert_text = AssertText()
        self.driver.set_window_max()
        self.account_center_page_read_csv = AccountCenterPageReadCsv()
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

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

    def test_refill_record_search(self):
        '''充值卡-充值记录--搜索'''
        csv_file = self.account_center_page_read_csv.read_csv('search_refill_record_data.csv')
        csv_data = csv.reader(csv_file)

        # 打开途强在线首页-登录页
        self.base_page.open_page()
        # 登录账号
        self.log_in_base.log_in()
        self.driver.wait(1)
        self.account_center_page_navi_bar.click_account_center_button()
        # 进入充值卡页面
        # self.account_center_page_navi_bar.switch_to_chongzhi_card()
        self.account_center_page_refill_card.click_refill_card()

        # 验证页面顶部我的账号
        my_account = self.account_center_page_refill_card.get_title_display_account()
        self.assertIn(self.account_center_page_refill_card.get_current_login_account(), my_account, "登录账号显示一致")

        for row in csv_data:
            data = {
                "refill_type": row[0],
                "device_imei": row[1]

            }
            # 点击充值记录
            self.account_center_page_refill_card.click_refill_record()
            # 搜索
            count = self.account_center_page_refill_card.refill_record_search_data(data["refill_type"],
                                                                                   data["device_imei"])
            # 验证imei计数
            self.assertEqual(count["import_count"], int(count["add_count"]), "输入框中imei的计数显示错误")

            # 获取页面列表条数
            page_number = self.account_center_page_refill_card.get_refill_record_number()

            # 获取当前账号id
            sql_data = self.search_sql.search_current_account_data(my_account)

            connect1 = self.connect_sql.connect_tuqiang_sql()
            # 创建数据库游标
            cur = connect1.cursor()
            # 获取数据库条数
            get_sql = self.search_sql.search_refill_record_sql(sql_data[0], data)
            print(get_sql)
            cur.execute(get_sql)
            # 读取数据
            total_data = cur.fetchall()
            # 从数据tuple中获取最终查询记录统计条数
            total_list = []
            for range1 in total_data:
                for range2 in range1:
                    total_list.append(range2)
            total = len(total_list)
            print('本次查询数据库的条数为:%s' % total)

            # 获取数据库条数
            self.assertEqual(total, page_number, "转移记录中,平台与sql搜索出来的数据条数不一致")
        # 点击充值记录
        self.account_center_page_refill_card.click_refill_record()
        # 获取设备有多少个分页
        total_page = self.account_center_page_refill_card.get_total_page_number_search_refill_record()
        print(total_page)
        if total_page[0] == 0:
            text = self.account_center_page_refill_card.get_refill_record_page_no_data_text()
            self.assertIn(self.assert_text.account_center_page_no_data_text(), text)

        elif total_page[0] == 1:
            up_page_class = self.account_center_page_refill_card.get_up_page_class_active_in_refill_search()
            self.assertEqual('active', up_page_class)

        else:
            for n in range(total_page[0]):
                self.account_center_page_refill_card.click_per_page(n)
                get_per_first_number = self.account_center_page_refill_card.get_per_frist_number_in_refill_search()
                self.assertEqual(get_per_first_number, str(10 * (n + 1) - 9))

            # 点击每页20条
            list = [20, 30, 50, 100]
            for m in list:
                self.account_center_page_refill_card.click_per_page_number_refill_record()
                page_number = self.account_center_page_refill_card.get_page_number_in_refill_record_search()
                print(page_number)
                self.assertEqual(int(total_page[1] / m) + 1, page_number)

        csv_file.close()