CodeceptJS – Run your first automation script

CodeceptJS  – Run your first automation script

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

CodeceptJS – Run your first automation script

As we know  CodeceptJS is also known as a framework of frameworks. So we will be creating our tests using Webdriver as a helper. 

The following are the steps you need to follow for executing your first Test Automation Script using CodeceptJS:-

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

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

Trigger the below command in Terminal :

npm init -y

The above command will create a default package.json file in the ‘codeceptJSWithWDIO’ 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 https://www.google.com
  • [WebDriver] Browser in which testing will be performed chrome

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 to print the title of the page. Use this code and paste it into your test file created during the generation of the config file in Step 3

Feature('findTitle'); //What Feature we are going to test ?
Scenario('print title of the page in console', async ({ I }) => {
   let title = await I.grabTitle();
   console.log('Title was:' + title);

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