Testing Radio Buttons with Webship-js

Published: (December 23, 2025 at 06:47 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Cover image for Testing Radio Buttons with Webship-js

Radio buttons are commonly used in websites when only one option must be selected at a time, such as account registration settings, user permissions, or visibility rules. Because these choices directly affect how a system behaves, it’s essential to ensure that the selected option is saved correctly and remains unchanged after saving and reloading the page.

In this article we demonstrate how to automatically verify radio button behavior in a Drupal CMS website using Webship‑JS, ensuring the selection works exactly as expected.

Selecting a Radio Button

Webship‑JS provides a step definition that selects a radio button by its label text, value, or CSS selector.

When (I | we) select radio button "([^"]*)?"

Examples

StepDescription
When I select radio button "Male"Selects the radio button with label Male
When I select radio button "female"Selects the radio button with label female
When I select radio button "#gender-male"Selects the radio button using the CSS selector #gender-male
When we select radio button "option1"Selects the radio button with label option1

Real Testing Context

Below is a practical example of testing a radio button in a Drupal CMS system. The test selects a radio button option, saves the configuration, and then verifies that the correct setting is retained.

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

Why It Matters

Imagine selecting the “Youth” age range and later finding the system classifies you as “Old Age”. Such unexpected changes indicate a problem with the radio button handling, as the UI should always reflect a single, clear choice.

Unexpected change illustration

Further Reading

Learn more about step definitions in Webship‑JS:

  • Documentation site:

See the full article:

Back to Blog

Related posts

Read more »

Compiling JavaScript

How JavaScript is Recognized? Engine Browser‑க்கு உள்ள ஒரு Engine இருக்கும் Example: Chrome‑ல இருக்குற V8 Engine. இது ஒரு Translator மாதிரி வேலை செய்யும். Toke...

ReactJS Hook Pattern ~Deriving State~

!Cover image for ReactJS Hook Pattern ~Deriving State~https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2...