Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

codeceptjs

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codeceptjs

Supercharged End 2 End Testing Framework for NodeJS


Version published
Weekly downloads
132K
decreased by-21.78%
Maintainers
2
Weekly downloads
 
Created

What is codeceptjs?

CodeceptJS is an end-to-end testing framework for Node.js that simplifies the process of writing and running tests for web applications. It supports various testing engines like WebDriver, Puppeteer, TestCafe, and more, allowing for flexible and powerful test automation.

What are codeceptjs's main functionalities?

End-to-End Testing

CodeceptJS allows you to write end-to-end tests in a simple and readable format. This example demonstrates a basic login test where the user navigates to the login page, fills in the username and password, clicks the login button, and verifies that the welcome message is displayed.

const { I } = inject();

Feature('Login');

Scenario('test login', (I) => {
  I.amOnPage('/login');
  I.fillField('Username', 'user');
  I.fillField('Password', 'password');
  I.click('Login');
  I.see('Welcome, user');
});

Page Object Model

CodeceptJS supports the Page Object Model (POM) design pattern, which helps in organizing and maintaining test code. This example shows a LoginPage class that encapsulates the elements and actions related to the login page, making the test code more modular and reusable.

class LoginPage {
  constructor() {
    this.fields = {
      username: 'input[name="username"]',
      password: 'input[name="password"]'
    };
    this.buttons = {
      login: 'button[type="submit"]'
    };
  }

  login(username, password) {
    I.fillField(this.fields.username, username);
    I.fillField(this.fields.password, password);
    I.click(this.buttons.login);
  }
}

module.exports = new LoginPage();

Data-Driven Testing

CodeceptJS supports data-driven testing, allowing you to run the same test with different sets of data. This example demonstrates how to create a data table with multiple user credentials and run the login test for each set of credentials.

const { I } = inject();

Feature('Login');

const users = new DataTable(['username', 'password']);
users.add(['user1', 'password1']);
users.add(['user2', 'password2']);

Data(users).Scenario('test login with multiple users', (I, current) => {
  I.amOnPage('/login');
  I.fillField('Username', current.username);
  I.fillField('Password', current.password);
  I.click('Login');
  I.see('Welcome, ' + current.username);
});

Other packages similar to codeceptjs

FAQs

Package last updated on 21 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts