import sys
import os

# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径
预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..','..'))
# 添加路径
sys.path.append(预定系统_path)
# 导入模块
from 预定系统.Base.base import *

# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))

# 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(current_dir, '..', '..', '测试数据', '会议预定测试用例.xlsx')


class MeetingList_000x:
    tags = ['新-会议室列表', 'JSON测试']
    """
        执行指令是:
            1.cd 预定系统
            2.hytest --report_title 账号密码登录测试报告 --report_url_prefix http://nat.ubainsyun.com:31133 --tag 新-会议室列表
    """

    def teststeps(self):
        wd = GSTORE['wd']
        ddt_cases = read_xlsx_data(xlsx_file_path,"会议室列表")

        # 遍历 ddt_cases 并获取每一个 JSON 对象
        for case in ddt_cases:
            for step in case:
                print(f"当前步骤: {step}")
                if "MeetingRoomToken" in step.get("page"):
                    # 先赋值
                    locator_type = get_by_enum(step.get('locator_type'))
                    locator_value = step.get('locator_value')
                    element_type = step.get('element_type')
                    element_value = step.get('element_value')
                    expented_result = step.get('expented_result')

                    if element_type == "input":
                        # 点击展开筛选界面
                        STEP(1, "搜索会议室")
                        safe_send_keys((locator_type, locator_value), element_value, wd)
                        send_keyboard((locator_type, locator_value), wd)
                        sleep(2)
                        # 点击【查询】按钮
                        safe_click((By.XPATH, "//span[contains(text(),'查询')]"), wd)
                        sleep(1)

                    elif element_type == "click":
                        # 点击会议室,查看提示信息
                        STEP(2, "点击【会议预约】")
                        safe_click((locator_type, locator_value), wd)
                        sleep(2)
                        # 判断是否为已授权的会议室,如果是,则点击会议预定判断是否进入会议预定界面,否则,点击会议预定,查看提示信息
                        if "会议" in expented_result:
                            notify_text = elment_get_text((By.XPATH, "//div[@class='reserve_Title']"), wd)
                        else:
                            notify_text = get_notify_text(wd, (By.XPATH, "//p[@class='el-message__content']"),
                                                          "MeetingList", "RoomToken", f"未授权会议室点击【会议预定】")
                            INFO(f"提示信息为:{notify_text}")
                        # 判断提示信息是否正确
                        sleep(1)
                        CHECK_POINT("提示信息是否正确", expented_result in notify_text)
                        SELENIUM_LOG_SCREEN(wd, "50")