testcafe-mock-recorder
v1.0.7
Published
Library dedicated to auto-generate mock data for testcafe e2e tests
Downloads
12
Maintainers
Readme
MockDataRecorder
A simple JS library that allow us to automatically record the JSON data from API calls when running E2E tests via testcafe.
Installation
npm install testcafe-mock-recorder
Usage
import { Selector, RequestLogger } from 'testcafe'
import Recorder from 'testcafe-mock-recorder'
fixture `Getting Started`
.page `https://github.com`
test('My first test', async t => {
const testcafeRecorder = new Recorder({
RequestLogger,
predicate: request => {
const captureRegExp = /.*/
const excludeRegExp = /exclude_this_pattern/
return captureRegExp.test(request.url) && !excludeRegExp.test(request.url)
},
record: true,
baseDir: __dirname
})
await testcafeRecorder.startRecording(t)
await t
.wait(5000)
testcafeRecorder.writeMockData('testFile.js')
})
Import mock data file
import { Selector, RequestLogger } from 'testcafe'
import Recorder from 'testcafe-mock-recorder'
// import autogenerated file
import testFileData from './testFile'
fixture `Getting Started`
.page `https://github.com`
test('My first test', async t => {
const testcafeRecorder = new Recorder({
RequestLogger,
predicate: request => {
const captureRegExp = /.*/
const excludeRegExp = /exclude_this_pattern/
return captureRegExp.test(request.url) && !excludeRegExp.test(request.url)
},
record: false, // set record option to false (we don't want to re-write the file)
baseDir: __dirname
})
await testcafeRecorder.startRecording(t, testFileData.all) // we set the mocks here to detach them if we want to update the data when {record: true}
await t
.wait(5000)
testcafeRecorder.writeMockData('testFile.js')
}).requestHooks(testFileData.all) // attach the mocks to the test
Want to contribute, feedback, questions?
Github: https://github.com/gralmurdok/testcafeMockRecorder