1.2.2 • Published 2 months ago

@talend/cypress-api-mock-plugin v1.2.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

@talend/cypress-api-mock-plugin

This Cypress plugin allows to mock any http request via HAR files.

It has 2 modes:

  • record http requests into HAR (HTTP Archive) files
  • mock http requests from HAR files

Installation

npm install --save-dev @talend/cypress-api-mock-plugin

// or

yarn add -D @talend/cypress-api-mock-plugin

Edit your cypress/plugins/index.js

const { installApiMock, ensureBrowserFlags } = require('@talend/cypress-api-mock-plugin');

module.exports = async (on, config) => {
    installApiMock(on, config);

	on('before:browser:launch', (browser = {}, launchOptions) => {
		ensureBrowserFlags(browser, launchOptions);
		return launchOptions;
	});
}

Edit your cypress/support/commands.js

import { installApiMockCommands } from '@talend/cypress-api-mock-plugin/commands';

installApiMockCommands();

Usage

In each spec files you want to record/mock the hhtp requests, add a before/after call.

describe('my spec', () => {
    before(() => {
		cy.beforeApiMock();
	});

	after(() => {
		cy.afterApiMock();
	});
});

Run

To record the requests, you can pass a record-api environment variable.
Under the hood, the plugin uses @neuralegion/cypress-har-generator that needs to run on chrome.

cypress run --browser chrome --headless --env record-api=true

Once you have the api mock har files, to run the tests with the api mock:

cypress run
1.2.2

2 months ago

1.2.1

5 months ago

1.2.0

6 months ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago