import sys
import os

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

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

# 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(current_dir, '..', '..', 'data', '统一平台PC端测试用例.xlsx')

class Unified_Platform_0001:
    #执行指令:
    # cd ./统一平台/
    # hytest --tag 成都太行
    tags = ['数据统计','成都太行']
    ddt_cases = read_xlsx_data(xlsx_file_path, sheet_name="数据统计")
    def teststeps(self):
        wd = GSTORE['wd']
        name = self.name
        wd.refresh()
        for step in self.para:
            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')
            print(f"执行JSON:{step}")
            # # 添加刷新页面的判断
            # if element_type == "refresh":
            #     wd.refresh()
            if step.get("page") == "StatisticsModule":
                if element_type == "input":
                    safe_send_keys((locator_type, locator_value), element_value, wd)
                    sleep(1)
                elif element_type == "click":
                    safe_click((locator_type, locator_value), wd)
                    sleep(1)
                elif element_type == "getText":
                    # 获取提示文本
                    notify_text = elment_get_text((locator_type,locator_value), wd)
                    INFO(f"获取弹窗提示内容为:{notify_text}")
                    CHECK_POINT("判断是否跟预期一致", expented_result == notify_text)
        SELENIUM_LOG_SCREEN(wd, "50%")