#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
更新登录测试用例 - 修复断言超时问题
"""

import requests

BASE_URL = "http://localhost:8001/api"

# 更新正常登录用例
case_id = "case_39aab8d4284c4b508465e0eae871d801"

updated_steps = [
    {"order": 1, "name": "打开登录页面", "action": "navigate",
     "params": {"url": "https://192.168.5.44"}, "expected": ""},
    {"order": 2, "name": "等待登录表单加载", "action": "wait",
     "params": {"selector": "input", "timeout": 10000}, "expected": ""},
    {"order": 3, "name": "输入用户名", "action": "fill",
     "params": {"selector": "input[type='text']", "value": "admin@xty"}, "expected": ""},
    {"order": 4, "name": "输入密码", "action": "fill",
     "params": {"selector": "input[type='password']", "value": "Ubains@13579"}, "expected": ""},
    {"order": 5, "name": "输入验证码", "action": "fill",
     "params": {"selector": "input[type='text']:nth-of-type(3)", "value": "csba"}, "expected": ""},
    {"order": 6, "name": "点击登录按钮", "action": "click",
     "params": {"selector": "button"}, "expected": ""},
    {"order": 7, "name": "等待页面跳转完成", "action": "wait",
     "params": {"selector": "text=统一管理平台", "timeout": 10000}, "expected": ""}
]

response = requests.put(
    f"{BASE_URL}/cases/{case_id}",
    json={"steps": updated_steps}
)

if response.status_code == 200:
    print("用例更新成功！")
    print("修改内容：")
    print("  - 删除了URL断言步骤（会立即检查导致超时）")
    print("  - 改为等待页面元素'统一管理平台'出现")
    print("  - 等待时间增加到10秒")
else:
    print(f"更新失败: {response.text}")