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


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

    @classmethod
    def setUpClass(cls):
        cls.set_driver()
        global driver
        driver = cls.get_driver()

    @BeautifulReport.add_test_img("test_Akhquery")
    def test_Akhquery(self):
        """填写所有内容后进行客户查询"""
        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_Bbjquery")
    def test_Bbjquery(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_Cbjsbquery")
    def test_Cbjsbquery(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_Dbjsbquery")
    def test_Dbjsbquery(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_Ebjsbquery")
    def test_Ebjsbquery(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_FDbjsbquery")
    def test_FDbjsbquery(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_GDbjsbquery")
    def test_GDbjsbquery(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_HDbjsbquery")
    def test_HDbjsbquery(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_zzzzzz_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()

        topbuttons = present_waits(driver, By.XPATH, '//div[@class="button_spacing button_shrink_bottom"]')
        for topbutton in topbuttons:
            if topbutton.is_displayed():
                topbutton.click()
                break

    def public_ctrl(self, driver):
        #  输入框
        input_border(driver, '//div[@class="col-sm-2 form-group"]/input')
        #  选择小区
        area_choose(driver)
        #  日期框
        data_border(driver, '//div[@class="datepicker"]')
        #  选择框
        choose_border(driver, '//div[@class="col-sm-2 form-group"]//div[@class="btn-group"]')
        search_buttons = present_waits(driver, By.XPATH, './/button[text()="查询"]')
        for search_button in search_buttons:
            if search_button.is_displayed():
                search_button.click()
                break
        sleep(1)
        result = is_element_load(driver, '//p[contains(text(),"错误码")]')
        expect = '测试'
        if not result:
            print('查询功能未报错，测试通过')
            expect = '查询功能未报错，测试通过'
        else:
            print('查询功能报错，测试失败')
        self.assertEqual(expect, '查询功能未报错，测试通过')

    def tearDown(self):
        pass
