What is @codeceptjs/helper?
@codeceptjs/helper is a helper class for CodeceptJS, a popular end-to-end testing framework. This package provides various methods to interact with web applications, APIs, and mobile applications, making it easier to write and manage tests.
What are @codeceptjs/helper's main functionalities?
Web Interaction
This feature allows you to interact with web pages by navigating to URLs, filling out forms, clicking buttons, and verifying text on the page.
const { I } = inject();
I.amOnPage('https://example.com');
I.fillField('Username', 'user');
I.fillField('Password', 'password');
I.click('Login');
I.see('Welcome, user!');
API Testing
This feature allows you to send HTTP requests and validate the responses, making it useful for API testing.
const { I } = inject();
I.sendGetRequest('/api/users').then(response => {
I.assertEqual(response.status, 200);
I.assertEqual(response.data.length, 10);
});
Mobile Interaction
This feature allows you to interact with mobile applications, including installing apps, clicking buttons, and filling out forms.
const { I } = inject();
I.runOnAndroid({
device: 'emulator-5554',
app: 'path/to/app.apk'
}, () => {
I.seeAppIsInstalled('com.example.app');
I.click('Login');
I.fillField('Username', 'user');
I.fillField('Password', 'password');
I.click('Submit');
I.see('Welcome, user!');
});
Other packages similar to @codeceptjs/helper
selenium-webdriver
Selenium WebDriver is a popular tool for automating web applications for testing purposes. It provides a more low-level API compared to @codeceptjs/helper, which can be more flexible but also more complex to use.
cypress
Cypress is a modern end-to-end testing framework that provides a rich set of features for web testing. It offers a more integrated and user-friendly experience compared to @codeceptjs/helper, but it is primarily focused on web applications.
webdriverio
WebdriverIO is a testing utility for Node.js that provides a high-level API for interacting with web applications. It is similar to @codeceptjs/helper in terms of functionality but offers more flexibility and customization options.
CodeceptJS Helper
Base class for all CodeceptJS helpers. This class has been moved into a separate package to allow other helpers to be extended from it, without requiring main codeceptjs package.
Installation
npm i @codeceptjs/helper --save
Usage
Create CodeceptJS helper as described in documentation.
const Helper = require('@codeceptjs/helper');
class MyHelper extends Helper {
}
API
Table of Contents
Helper
Abstract class.
Helpers abstracts test execution backends.
Methods of Helper class will be available in tests in I
object.
They provide user-friendly abstracted actions over NodeJS libraries.
Hooks (methods starting with _
) can be used to setup/teardown,
or handle execution flow.
Methods are expected to return a value in order to be wrapped in promise.
Parameters
_validateConfig
Abstract method to validate config
Parameters
Returns any
_setConfig
Sets config for current test
Parameters
_init
Hook executed before all tests
_before
Hook executed before each test.
Parameters
_after
Hook executed after each test
_test
Hook provides a test details
Executed in the very beginning of a test
Parameters
_passed
Hook executed after each passed test
Parameters
_failed
Hook executed after each failed test
Parameters
_beforeStep
Hook executed before each step
Parameters
_afterStep
Hook executed after each step
Parameters
_beforeSuite
Hook executed before each suite
Parameters
_afterSuite
Hook executed after each suite
Parameters
_finishTest
Hook executed after all tests are executed
Parameters
_useTo
Abstract method to provide common interface to accessing helpers internals inside a test.
Parameters
helpers
Access another configured helper: this.helpers['AnotherHelper']
Type: any
debug
Print debug message to console (outputs only in debug mode)
Parameters
debugSection
Parameters
_config
Abstract method to provide required config options
Returns any