Article Overview:
This article will cover how you can achieve the following:
Verify the state of a Radio button, toggle switch or checkbox and enable it only if it is disabled.
Problem Statement:
A customer needs to ensure that Radio button, toggle switch or checkbox remain enabled during a test. However, the state of these toggles may vary due to previous tests or manual changes. The requirement is:
- If the toggle is Enabled, do nothing.
- If the toggle is Disabled, enable it.
- Avoid clicking a Radio button, toggle switch or checkbox that is already Enabled to prevent switching it to disable state mistakenly.
Solution:
To manage Radio button, toggle switch or checkbox, follow these steps:
-
Store the Element Details:
- Capture the element details of the input element and store them in a variable.
-
Assert the Toggle State:
- Check the checked property of the input element to determine whether it is True (Enabled) or False (Disabled).
- Check the checked property of the input element to determine whether it is True (Enabled) or False (Disabled).
-
Conditionally Click the Toggle:
- If the checked property is
false
(Disabled), perform a click action to enable it. - If the checked property is
true
(Enabled), leave it unchanged.
- If the checked property is
Implementation Example in Virtuoso:
store element details of "Test Toggle" in $toggle
assert $toggle.checked equals "false"
click "Waste Tire Toggle" -> (When to run this step) if $toggle.checked equals "false"
Reference Screenshot:
Here we have a breakdown of the suggested approach
To test for any alternation in Toggle status, we observed that the step is skipped as expected, which confirms the solution works as designed.
Examples:
- Scenario: A user logs in and finds that some toggles are Disabled due to a previous test.
- Solution: The toggle switch can be assessed using the JSON parameter of the input element once we know if it’s disabled, and clicks only if necessary using the if condition.
Comments
0 comments
Please sign in to leave a comment.