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


class as_Security_sheck3(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_Aajjgckquery")
    def test_Aajjgckquery(self):
        """填写所有内容后进行安检结果查看查询"""
        global driver
        driver = self.get_driver()
        id_click(driver, '安检查看')
        id_click(driver, '安检结果查看')
        bottom_push_click(driver)
        input_border(driver, '//div[@class="form-group col-sm-2"]//input')
        area_choose(driver)
        choose_border(driver, '//div[@class="form-group col-sm-2"]//div[@class="btn-group select_list select"]')
        choose_border(driver, '//div[@class="col-sm-6 form-group"]//div[@class="btn-group select_list select"]')
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Bajykhquery")
    def test_Bajykhquery(self):
        """填写所有内容后进行安检员考核查询"""
        close_current_page(driver)
        id_click(driver, '安检员考核')
        choose_border(driver, '//div[@class="col-sm-6 form-group"]//div[@class="btn-group select_list select"]')
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Cyhajqkquery")
    def test_Cyhajqkquery(self):
        """填写所有内容后进行用户安检情况查询"""
        close_current_page(driver)
        id_click(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 select select_list"]')
        choose_border(driver, '//div[@class="col-sm-2 form-group"]//div[@class="btn-group select_list select"]')
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Dyhckquery")
    def test_Dyhckquery(self):
        """填写所有内容后进行隐患查看查询"""
        close_current_page(driver)
        id_click(driver, '隐患查看')
        bottom_push_click(driver)
        choose_border(driver, '//div[@class="col-sm-2 form-group"]//div[@class="btn-group select select_list"]')
        choose_border(driver, '//div[@class="col-sm-2 form-group"]//div[@class="btn-group select_list select"]')
        input_border(driver, '//div[@class="col-sm-2 form-group"]//input')
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Eajhzquery")
    def test_Eajhzquery(self):
        """填写所有内容后进行安检汇总查询"""
        close_current_page(driver)
        id_click(driver, '安检汇总')
        bottom_push_click(driver)
        choose_border(driver, '//div[@class="col-sm-6 form-group"]//div[@class="btn-group select_list select"]')
        input_border(driver, '//label[text()="小区名称"]/following-sibling::input')
        choose_border(driver, '//label[text()="计划名称"]/following-sibling::div')
        self.public_ctrl(driver)

    @BeautifulReport.add_test_img("test_Fyhbbquery")
    def test_Fyhbbquery(self):
        """填写所有内容后进行隐患报表查询"""
        close_current_page(driver)
        id_click(driver, '隐患报表')
        choose_border(driver, '//div[@class="col-sm-6 form-group"]//div[@class="btn-group select_list select"]')
        self.public_ctrl(driver)

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

    def public_ctrl(self, driver):
        # 日期框
        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
