CodeceptJS – Handling Checkboxes

CodeceptJS – Handling Checkboxes

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

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 Checkboxes in Web Pages using CodeceptJS: –

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


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

2. Scroll down to checkbox named as Blue (As shown below):-

3. Make a checkbox from unchecked to checked.

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

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

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

Trigger the below command in Terminal :

npm init -y

The above command will create a default package.json file in the ‘CodeceptJS_Handling_Checkboxes’ 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

In any case, we get an error like cannot find the module ‘cross-spawn’ while running the above command. Then please run the below command to get it resolved

npm i cross-spawn

Then Re-run the first command that is “npx codeceptjs init” to generate the codecept.conf.js file. 

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 a blue unchecked box could be checked (PS: can be done in multiple ways but I am presenting one of the ways). Use this code and paste it into your test file created during the generation of the config file in Step 3

Feature('check the blue checkbox');

Scenario('User should be able to check the unchecked blue checkbox', ({ I }) => {
    const blueCheckbox =  "//input[@id='checkbox2']" //Storing Xpath for the required checkbox element 

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 *

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp