Skip to content
Back to skills

Save Verify Strategy

ASecurity

表单保存后验证(Toast / 重定向 / 数据对比 / 富文本清空)。触发:保存验证、toast、重定向检测、Meta+A、保存成功判断。

  • 158 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 20, 2026
documentationpython

Works with

  • cli

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned September 20, 2026

npx -y skills add DanielSuo117/velocitai --skill save-verify-strategy --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Save Verify Strategy?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Save Verify Strategy
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/danielsuo117-save-verify-strategy/badge)](https://www.skillsdirectory.com/skills/danielsuo117-save-verify-strategy)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: save-verify-strategy
description: 表单保存后验证(Toast / 重定向 / 数据对比 / 富文本清空)。触发:保存验证、toast、重定向检测、Meta+A、保存成功判断。
---

# 表单保存验证策略

---

## 一、macOS 富文本编辑器全选

macOS 上富文本编辑器的全选按键差异(Control+A 无效)→
[references/macos-select-all.md](./references/macos-select-all.md)

## 二、保存后验证策略:三级选择

| 保存后行为 | 验证方式 | 可靠性 | 适用场景 |
|-----------|---------|--------|---------|
| 显示 Toast | `is_visible(toast_locator)` — 必须在 networkidle 后**立即**检测 | 低(2-3s 消失) | 有明确 Toast 的场景 |
| 页面重定向 | 检测编辑页特征元素消失 `wait_for(state="hidden")` | 中(持久状态) | 保存后自动跳转的场景 |
| 无 UI 反馈 | 写入标记数据 → 重新打开 → 读取对比 | 高(数据级验证) | 无 Toast、不确定是否重定向 |

**原则**:三级可组合使用。优先用持久状态变更,Toast 仅作辅助。

### 2.1 Toast 时序陷阱

`click_save()` 方法中的 `wait_for_timeout()` 会消耗 Toast 存活时间。**必须**在 networkidle 后立即检测 Toast,不能先等待再检测。

❌ 反例:

```python
def click_save(self):
    self.click(self.SAVE_BTN)
    self.page.wait_for_load_state("networkidle")
    self.page.wait_for_timeout(3000)   # Toast 在这 3s 内出现又消失了

# 调用方
assert page.is_visible(toast)          # Toast 已消失,永远 False
```

✅ 正例:

```python
def click_save(self):
    self.click(self.SAVE_BTN)
    self.page.wait_for_load_state("networkidle")
    # 不加额外等待 — 让调用方立即检测 Toast

# 调用方
is_ok = page.is_visible(toast, timeout=10000)   # 立即开始等 Toast
page.wait_for_timeout(3000)                      # 检测完再等页面稳定
```

### 2.2 重定向检测

保存后页面可能重定向离开编辑页。通过检测编辑页**特征元素消失**来确认保存成功:

```python
def is_save_success(self) -> bool:
    """编辑页 header 消失 = 保存成功并已离开编辑页"""
    try:
        self.page.locator(self.EDIT_PAGE_HEADER).first.wait_for(
            state="hidden", timeout=15000
        )
        return True
    except Exception:
        return False
```

### 2.3 重定向目的地不可假设

保存后的重定向目的地可能因**导航上下文**不同而异(直接 URL 访问 vs SPA 内跳转 vs 新 tab 中操作)。不要断言重定向到某个特定页面。

❌ 反例:

```python
# 假设保存后一定重定向到首页
redirected_home = HomePage(page)
assert redirected_home.is_page_loaded()   # 实际可能跳到其他页面
```

✅ 正例:

```python
# 只验证离开了编辑页,不假设去了哪里
assert edit_page.is_save_success()        # 编辑页 header 消失 = 保存成功
```

---

## 三、多 tab 保存后:关闭旧 tab,从原始 tab 重入

保存动作发生在新开 tab 中时的处理 →
[references/multi-tab-reentry.md](./references/multi-tab-reentry.md)

## 四、数据对比验证模式(最终验证)

保存前后做数据比对的实现方式 →
[references/data-comparison.md](./references/data-comparison.md)

Files in this skill

  • SKILL.md3.2 KB
  • references/data-comparison.md1.2 KB
  • references/macos-select-all.md1.1 KB
  • references/multi-tab-reentry.md1004 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…