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


class as_Writemetersearch2(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_AAkhquery")
    def test_AAkhquery(self):
        """填写所有内容后进行计划下发查询"""
        global driver
        driver = self.get_driver()
        id_click(driver, "抄表管理")
        id_click(driver, "机表抄表")
        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_Bquery")
    def test_Bquery(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_Cquery")
    def test_Cquery(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_Dquery")
    def test_Dquery(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_Equery")
    def test_Equery(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)

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

    def click_topbutton(self, driver, but_name):
        topbuttons = present_waits(driver, By.XPATH, '//ul[@role="tablist"]//button')
        for topbutton in topbuttons:
            if topbutton.text == but_name:
                topbutton.click()
                break

    def public_ctrl(self, driver):
        sleep(2)
        # 输入框
        input_border(driver, '//div[@class="col-sm-2 form-group"]/input')
        # 选择框
        choose_border(driver, '//div[@class="btn-group"]')
        # 选择小区
        area_choose(driver)
        # 日期框
        data_border(driver, '//div[@class="datepicker"]')

        search_buttons = present_waits(driver, By.XPATH, '//button[text()="查询"]')
        for search_button in search_buttons:
            if search_button.is_displayed():
                search_button.click()
                break
        result = is_element_load(driver, '//p[contains(text(),"错误码")]')
        expect = '测试'
        if not result:
            print(' 查询功能未报错，测试通过 ')
            expect = '查询功能未报错，测试通过'
        else:
            print(' 查询功能报错，测试失败 ')
        self.assertEqual(expect, '查询功能未报错，测试通过')

    def tearDown(self):
        pass
