HomeCodeceptJS

CodeceptJS – Handling Radio Button

CodeceptJS – Handling Radio Button

<<Previous Post               <<Complete CodeceptJS Tutorial>>               Next Post>>

CodeceptJS – Handling Radio Button

checkOption

Selects a checkbox or radio button. Element is located by label or name or CSS or XPath.

Pre-requisite: Have ‘Visual Studio Code’ IDE installed in your machine (Click here to install if not installed in your machine)

Here is the small Exercise to Handle Radio Button in Web pages using CodeceptJS: –

First, I will demonstrate the exercise we need to perform to automate handling  Radio Button using CodeceptJS, followed by practically demonstrating the CodeceptJS Automation code for achieving it.

Exercise:-

1. Navigate to http://omayo.blogspot.com/

2. Look for the radio button on which you want to click

3. Click on the required radio button.

Practical Demonstration:

Following are the Steps to Perform the above Exercise (i.e. Handling Radio Button) using CodeceptJS Automation code in ‘Visual Studio Code’ IDE:

Step 1:- Create a Folder named as CodeceptJS_Handling_RadioButton(You can create a folder with any name)

Open the Git Bash from the above-created folder (In our case ‘CodeceptJS_Handling_RadioButton’ folder)

Trigger the below command in Terminal :

npm init -y

The above command will create a default package.json file in the ‘CodeceptJS_Handling_RadioButton’ folder.

Attached Screenshot for Reference:-

Step 2:- Install codeceptjs with webdriverio as a helper. 

Run the below command in Terminal:

npm install codeceptjs webdriverio --save-dev

Step 3:- Generate Configuration File. Since we haven’t created one yet, codeceptJS is smart enough to figure that out and help us through the process.

Run the below command in Terminal:

 npx codeceptjs init

Here are the answers I chose: (Move your arrow buttons on the keyboard to select the options and enter)

  • Where are your tests located ./*_test.js
  • What helpers do you want to use? WebDriver
  • Where should logs, screenshots, and reports to be stored? ./output
  • Do you want localization for tests? (See https://codecept.io/translation/) English (no localization)
  • [WebDriver] Base URL of the site to be tested http://www.omayo.blogspot.com
  • [WebDriver] Browser in which testing will be performed chrome

These were the main points I have selected rest you can go through the screenshot given below :-

Verify codecept.conf.js file gets created successfully.

Step 4:- Now Install Selenium standalone service

Run the below command in Terminal:

npm install @wdio/selenium-standalone-service --save-dev

Step 5:- As generated config file doesn’t auto-configure selenium-standalone in its codecept.conf.js file. Open the file in the respective IDE you use, we are using Visual Studio Code as IDE.

wdio: {
    enabled: true,
    services: [“selenium-standalone”]
}

Step 6:- Write code in the test file. I have written a sample code through which the Male Radio Button will be checked (PS: can be done in multiple ways but I am presenting one of the ways). Use this code and paste it in your test file created during the generation of the config file in Step 3

Feature('Check Radio Button Male');
Scenario('User should be able to check radio button Male', ({ I }) => {
   I.amOnPage("/");
   I.scrollIntoView("#radio1");
   const  radio_button = 'input[id="radio1"]'; //storing Xpath for the required Radio Button
   I.checkOption(radio_button);
});

Step 7:- Run your test file to perform the test.

Run the below command in Visual Studio Code Terminal:

npx codeceptjs run

Download the Project from here (Click here to Download) and Unzip it.

Hopefully, your test completed and passed.
Comment ‘Success’ in this post if you are able to practically achieve this exercise.

Next Steps:

> To learn more about CodeceptJS, continue to the next post (Click on Next Post link below)

> Check complete CodeceptJS Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Ajay Lunia 

Connect to me on LinkedIn (Click here)

On a mission to help the Software Testing Community in all possible ways.

<<Previous Post               <<Complete CodeceptJS Tutorial>>               Next Post>>

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Open chat
Contact Us on Whatsapp