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


class as_ServiceQueryScript2(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_Akhquery")
    def test_Akhquery(self):
        """填写所有内容后进行收费查询"""
        global driver
        driver = self.get_driver()
        is_element_load(driver, '//*[@id="top"]/div/div[1]/h3')
        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_Bhbquery")
    def test_Bhbquery(self):
        """填写所有内容后进行换表查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Cjbcbquery")
    def test_Cjbcbquery(self):
        """填写所有内容后进行机表抄表查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Egfsqquery")
    def test_Egfsqquery(self):
        """填写所有内容后进行免费送气查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Emhquery")
    def test_Emhquery(self):
        """填写所有内容后进行过户查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Enhquery")
    def test_Enhquery(self):
        """填写所有内容后进行记录转移查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Fqtquery")
    def test_Fqtquery(self):
        """填写所有内容后进行其他收费查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Fqtsfqfquery")
    def test_Fqtsfqfquery(self):
        """填写所有内容后进行其他收费查询"""
        close_current_page(driver)
        sleep(0.5)
        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):
        """填写所有内容后进行冲正查询"""
        close_current_page(driver)
        sleep(0.5)
        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):
        """填写所有内容后进行补卡查询"""
        close_current_page(driver)
        sleep(0.5)
        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_IDbjsbquery")
    def test_IDbjsbquery(self):
        """填写所有内容后进行业务查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Ibjsbquery")
    def test_Ibjsbquery(self):
        """填写所有内容后进行启用查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Gbjsbquery")
    def test_Gbjsbquery(self):
        """填写所有内容后进行停用查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Kbjsbquery")
    def test_Kbjsbquery(self):
        """填写所有内容后进行销户查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Lbjsbquery")
    def test_Lbjsbquery(self):
        """填写所有内容后进行减免优惠查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Mbjsbquery")
    def test_Mbjsbquery(self):
        """填写所有内容后进行业务查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Nbjsbquery")
    def test_Nbjsbquery(self):
        """填写所有内容后进行迁表查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Objsbquery")
    def test_Objsbquery(self):
        """填写所有内容后进行卡表抄表查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Pbjsbquery")
    def test_Pbjsbquery(self):
        """填写所有内容后进行收据查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Qbjsbquery")
    def test_Qbjsbquery(self):
        """填写所有内容后进行业务查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Rbjsbquery")
    def test_Rbjsbquery(self):
        """填写所有内容后进行预存查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Sbjsbquery")
    def test_Sbjsbquery(self):
        """填写所有内容后进行发折查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Tbjsbquery")
    def test_Tbjsbquery(self):
        """填写所有内容后进行可疑用户查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Ubjsbquery")
    def test_Ubjsbquery(self):
        """填写所有内容后进行气价变更查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Tjsbquery")
    def test_Tjsbquery(self):
        """填写所有内容后进行扎帐查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Ujsbquery")
    def test_Ujsbquery(self):
        """填写所有内容后进行调价记录查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Vbjsbquery")
    def test_Vbjsbquery(self):
        """填写所有内容后进行维护记录查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Wbjsbquery")
    def test_Wbjsbquery(self):
        """填写所有内容后进行气损收费查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Xbjsbquery")
    def test_Xbjsbquery(self):
        """填写所有内容后进行气价信息查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Ybjsbquery")
    def test_Ybjsbquery(self):
        """填写所有内容后进行团缴查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Yqfjtmxquery")
    def test_Yqfjtmxquery(self):
        """填写所有内容后进行气费阶梯明细查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Yzzywbgjlquery")
    # def test_Yzzywbgjlquery(self):
    #     """填写所有内容后进行增值业务变更记录"""
    #     close_current_page(driver)
    #     sleep(0.5)
    #     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_Yyhzzywcxquery")
    def test_Yyhzzywcxquery(self):
        """填写所有内容后进行用户增值业务查询"""
        close_current_page(driver)
        sleep(0.5)
        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_Yzzywxbcxquery")
    # def test_Yzzywxbcxquery(self):
    #     """填写所有内容后进行增值业务续保查询"""
    #     close_current_page(driver)
    #     sleep(0.5)
    #     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_YZquery")
    def test_YZquery(self):
        """填写所有内容后进行增值业务汇总查询"""
        close_current_page(driver)
        sleep(0.5)
        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):
        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')
        # 选择框
        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
