使用 Webship-js 测试单选按钮
Source: Dev.to

单选按钮在网站中常用于一次只能选择一个选项的场景,例如账户注册设置、用户权限或可见性规则。由于这些选择直接影响系统的行为,确保所选选项能够正确保存并在保存后重新加载页面时保持不变至关重要。
本文演示如何在 Drupal CMS 网站中使用 Webship‑JS 自动验证单选按钮的行为,确保选择能够完全按预期工作。
选择单选按钮
Webship‑JS 提供了一个步骤定义,可通过标签文本、值或 CSS 选择器来选择单选按钮。
When (I | we) select radio button "([^"]*)?"
示例
| 步骤 | 描述 |
|---|---|
When I select radio button "Male" | 选择标签为 Male 的单选按钮 |
When I select radio button "female" | 选择标签为 female 的单选按钮 |
When I select radio button "#gender-male" | 使用 CSS 选择器 #gender-male 选择单选按钮 |
When we select radio button "option1" | 选择标签为 option1 的单选按钮 |
实际测试场景
下面是一个在 Drupal CMS 系统中测试单选按钮的实际示例。该测试会选择一个单选按钮选项,保存配置,然后验证正确的设置是否被保留。
Feature: Radio Button Validation for Account Registration Settings in Drupal CMS
Performed as an administrator.
Scenario: Validate radio button selection
Given I am on the homepage
When I click "Log in"
And I fill in "#edit-name" with "info@webship.co" by attr
And I fill in "#edit-pass" with "d" by attr
And I press "#edit-submit" by attr
And I go to "/admin/config/people/accounts"
And I scroll down 500
And I select radio button "Visitors, but administrator approval is required"
And I press "Save configuration"
And I scroll down 500
Then the radio button "Visitors, but administrator approval is required" should be selected
And the radio button "Administrators only" should not be selected
为什么重要
想象一下,你选择了 “Youth” 年龄段,结果系统却把你归类为 “Old Age”。这种意外的变化表明单选按钮的处理存在问题,因为 UI 应始终只显示单一、明确的选择。

进一步阅读
了解 Webship‑JS 中步骤定义的更多信息:
- 文档站点:
See the full article: