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


class as_Wechatmanage2(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_Ayyzxquery")
    def test_Ayyzxquery(self):
        """填写所有内容后进行预约中心查询"""
        global driver
        driver = self.get_driver()
        id_click(driver, '微信管理')
        id_click(driver, '预约中心')
        bottom_push_click(driver)
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Bwzglquery")
    def test_Bwzglquery(self):
        """填写所有内容后进行文章管理查询"""
        close_current_page(driver)
        id_click(driver, '文章管理')
        bottom_push_click(driver)
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Cwxjbquery")
    def test_Cwxjbquery(self):
        """填写所有内容后进行微信解绑查询"""
        close_current_page(driver)
        id_click(driver, '微信解绑')
        bottom_push_click(driver)
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_EAwxshglquery")
    def test_EAwxshglquery(self):
        """填写所有内容后进行微信商户管理查询"""
        close_current_page(driver)
        id_click(driver, '微信参数管理')
        target_list = find_li(driver)
        if '微信商户管理' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            present_wait(driver, By.XPATH, '//button[text()="微信商户管理"]').click()
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_EBwxcsglquery")
    def test_EBwxcsglquery(self):
        """填写所有内容后进行微信参数管理查询"""
        close_current_page(driver)
        id_click(driver, '微信参数管理')
        target_list = find_li(driver)
        if '微信参数管理' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            present_wait(driver, By.XPATH, '//button[text()="微信参数管理"]').click()
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_FAqftsquery")
    def test_FAqftsquery(self):
        """填写所有内容后进行欠费推送查询"""
        close_current_page(driver)
        id_click(driver, '模板消息推送')
        target_list = find_li(driver)
        if '欠费推送' not in target_list:
            print('当前页面不存在此测试项')
            self.assertEqual(1, 1)
        else:
            present_wait(driver, By.XPATH, '//button[text()="欠费推送"]').click()
            self.myself_ctrl()
            self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Gqssfquery")
    def test_Gqssfquery(self):
        """填写所有内容后进行停气公告查询"""
        close_current_page(driver)
        id_click(driver, '停气公告')
        bottom_push_click(driver)
        self.public_ctrl(driver)

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

    def public_ctrl(self, driver):
        sleep(2)
        # 输入框
        input_border(driver, '//div[@class="col-sm-4 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 myself_ctrl(self):
        present_wait(driver, By.XPATH, '//div[@class="binary-right"]//'
                                       'div[@class="button_spacing button_shrink_bottom"]').click()

    def tearDown(self):
        pass
