from BeautifulReport import BeautifulReport
from PublicScript import *
from BasePage import basepage


class as_FinancialQueryScript2(basepage):
    def save_img(self, img_name):
        self.driver.get_screenshot_as_file("./img/" + img_name + ".png")

    @classmethod
    def setUpClass(cls):
        cls.set_driver()

    @BeautifulReport.add_test_img("test_Aqifyszkhzquery")
    def test_Aqifyszkhzquery(self):
        """填写所有内容后进行气费应收账款汇总"""
        global driver
        driver = self.get_driver()
        present_wait(driver, By.ID, "vc-tree-name-综合查询").click()
        present_wait(driver, By.ID, "vc-tree-name-财务查询").click()
        target_list = find_li(driver)
        if '气费应收账款汇总' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            self.click_topbutton(driver, '气费应收账款汇总')
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Bqifskqkhzquery")
    def test_Bqifskqkhzquery(self):
        """填写所有内容后进行气费预收款情况汇总"""
        present_wait(driver, By.ID, "vc-tree-name-财务查询").click()
        target_list = find_li(driver)
        if '气费预收款情况汇总' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            self.click_topbutton(driver, '气费预收款情况汇总')
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Czhinjqkhzquery")
    def test_Czhinjqkhzquery(self):
        """填写所有内容后进行滞纳金情况汇总"""
        present_wait(driver, By.ID, "vc-tree-name-财务查询").click()
        target_list = find_li(driver)
        if '滞纳金情况汇总' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            self.click_topbutton(driver, '滞纳金情况汇总')
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Dqifskqkhzquery")
    def test_Dqifskqkhzquery(self):
        """填写所有内容后进行气费收款情况汇总"""
        present_wait(driver, By.ID, "vc-tree-name-财务查询").click()
        target_list = find_li(driver)
        if '气费收款情况汇总' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            self.click_topbutton(driver, '气费收款情况汇总')
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Eweixskhzquery")
    def test_Eweixskhzquery(self):
        """填写所有内容后进行微信收款汇总"""
        present_wait(driver, By.ID, "vc-tree-name-财务查询").click()
        target_list = find_li(driver)
        if '微信收款汇总' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            self.click_topbutton(driver, '微信收款汇总')
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Fqifhklquery")
    def test_Fqifhklquery(self):
        """填写所有内容后进行气费回款率"""
        present_wait(driver, By.ID, "vc-tree-name-财务查询").click()
        target_list = find_li(driver)
        if '气费回款率' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            self.click_topbutton(driver, '气费回款率')
            self.public_ctrl2(driver)

    def test_zZZZ_END(self):
        """当前测试模块结束，关闭浏览器"""
        driver.quit()

    def click_topbutton(self, driver, but_name):

        top_button_group = present_waits(driver, By.XPATH, '//div[@class = "flex foot_tabset"]//li/button')
        for target_button in top_button_group:
            if target_button.text == but_name:
                target_button.click()

    def public_ctrl(self, driver):
        bottom_push_click(driver)

        # 输入框
        input_border(driver, '//div[@class="col-sm-2 form-group"]/input')
        # 选择小区
        area_choose(driver)
        # 选择框
        choose_border(driver, '//div[@class="col-sm-2 form-group"]//div[@class="btn-group"]')
        # 日期框
        data_border(driver, '//div[@class="datepicker"]')
        # 查询按钮
        search_button_click(driver)
        sleep(1)
        result = is_element_load(driver, '//p[contains(text(),"错误码")]')
        wrong = '错误信息：服务器内部错误，组件：undefined'
        if result == False:
            print('查询功能未报错，测试通过')
            wrong = '查询功能未报错，测试通过'
        else:
            print('查询功能报错，测试失败')
        self.assertEqual(wrong, '查询功能未报错，测试通过')

    def public_ctrl2(self, driver):

        # 选择框
        choose_border(driver, '//div[@class="col-sm-2 form-group"]//div[@class="btn-group"]')
        # 日期框
        data_border(driver, '//div[@class="datepicker"]')
        # 查询按钮
        search_button_click(driver)
        sleep(1)
        result = is_element_load(driver, '//p[contains(text(),"错误码")]')
        wrong = '错误信息：服务器内部错误，组件：undefined'
        if not result:
            print('查询功能未报错，测试通过')
            wrong = '查询功能未报错，测试通过'
        else:
            print('查询功能报错，测试失败')
        self.assertEqual(wrong, '查询功能未报错，测试通过')

    def tearDown(self):
        pass
