import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *


class user_login_001:
    name = 'login_test_01'
    def teststeps(self):
        wd = GSTORE['wd']

        # 读取 CSV 文件
        csv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'testdata', '01登录模块', '登录信息.csv'))

        with open(csv_path, newline='', encoding='utf-8') as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                username = row['username']
                password = row['password']
                captcha = row['captcha']

                STEP(1, f'用户 {username} 登录')
                user_login(username, password, captcha)

                STEP(2, '验证是否登录成功')
                try:
                    get_menu = WebDriverWait(wd, 10).until(
                        EC.presence_of_element_located((By.CSS_SELECTOR, '.el-message__content'))
                    )
                    get_menu1 = get_menu.text
                    CHECK_POINT('检查是否出现弹窗', get_menu1 == "操作成功!")
                except Exception as e:
                    print(f"登录失败,原因是: {get_menu1}")