{"id":26415184,"url":"https://github.com/rafalsep/testcafe-global-network-request-logger","last_synced_at":"2025-03-18T00:17:47.983Z","repository":{"id":57689605,"uuid":"475868334","full_name":"rafalsep/testcafe-global-network-request-logger","owner":"rafalsep","description":"Global hook for testcafe that will intercept, record and save network communication to a JSON file","archived":false,"fork":false,"pushed_at":"2022-09-21T08:28:02.000Z","size":1262,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T11:53:24.619Z","etag":null,"topics":["global","hooks","record","request","testcafe"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafalsep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-30T12:27:59.000Z","updated_at":"2022-05-26T18:06:17.000Z","dependencies_parsed_at":"2022-09-26T20:53:40.573Z","dependency_job_id":null,"html_url":"https://github.com/rafalsep/testcafe-global-network-request-logger","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafalsep%2Ftestcafe-global-network-request-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafalsep%2Ftestcafe-global-network-request-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafalsep%2Ftestcafe-global-network-request-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafalsep%2Ftestcafe-global-network-request-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafalsep","download_url":"https://codeload.github.com/rafalsep/testcafe-global-network-request-logger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130311,"owners_count":20402756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["global","hooks","record","request","testcafe"],"created_at":"2025-03-18T00:17:47.767Z","updated_at":"2025-03-18T00:17:47.955Z","avatar_url":"https://github.com/rafalsep.png","language":"JavaScript","readme":"# Global Network Request Logger for Testcafe\n\n###### Global Hook for testcafe that will record and save network communication (request/response) with external services to JSON file\n\n[![Build Status](https://travis-ci.org/rafalsep/testcafe-global-network-request-logger.svg)](https://travis-ci.org/rafalsep/testcafe-global-network-request-logger)\n\nUses TestCafe [global hooks](https://testcafe.io/documentation/403435/guides/advanced-guides/hooks#global-hooks) to record network calls executed in browser and saves them into file using same format as screenshots/videos.\nIt is meant to be used in CI, together with screenshot \u0026 video recording for better troubleshooting capability of failed tests\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.github.com/rafalsep/testcafe-global-network-request-logger/master/media/content.png\" alt=\"content\" /\u003e\n\u003c/p\u003e\n\n## Features\n\n- zero dependencies\n- supports gzipped or JSON responses\n- once attached will execute for all tests\n- uses similar config as [testcafe screenshot and video](https://testcafe.io/documentation/402840/guides/advanced-guides/screenshots-and-videos#screenshot-and-video-directories) for path and recording customization\n- adds additional param that can be used to limit number of logged requests (usually only last few requests matter)\n- supports quarantine mode and parallel test execution\n\n### Note\n\nOnly intercepts cross domain requests to avoid recording locally requested resources like HTML, CSS or JS.\n\n## Prerequisite\n\nIn order to use global hooks, [TestCafe Javascript configuration file](https://testcafe.io/documentation/402638/reference/configuration-file#javascript) must be used.\n\n## Install\n\n```\nnpm install testcafe-global-network-request-logger\n```\n\n## Configuration\n\nOnce installed add `network` configuration in `.testcaferc.js` file\n\n```js\nmodule.exports = {\n  // some other config\n  network: {\n    path: 'tmp',\n    takeOnFails: true,\n    pathPattern: '${DATE}/${FIXTURE}/network/${TEST}_${TIME}_${QUARANTINE_ATTEMPT}.json',\n    requestLimit: 0,\n  },\n};\n```\n\n| Required | Argument             | Description                                                                                                                                                                                                                                           | Example              |\n| -------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |\n| Yes      | network.path         | The base directory where screenshots are saved                                                                                                                                                                                                        | tmp                  |\n| Yes      | network.takeOnFails  | `true` to take a screenshot whenever a test fails.                                                                                                                                                                                                    | true                 |\n| Yes      | network.pathPattern  | A pattern that defines how TestCafe composes the relative path to a screenshot file. See [Screenshot and Video Directories](https://testcafe.io/documentation/402840/guides/advanced-guides/screenshots-and-videos#screenshot-and-video-directories). | ${DATE}/${TEST}.json |\n| Yes      | network.requestLimit | defines number of requests that should be logged, `0` means all                                                                                                                                                                                       | 3                    |\n\n## Enable request logging\n\nOnce configured last step is to attach hook in `.testcaferc.js` file\n\n```js\nconst networkRequestLogger = require('testcafe-global-network-request-logger')(/* FILTER */);\n\nmodule.exports = {\n  // some other config\n  network: {\n    // network config\n  },\n  hooks: {\n    test: {\n      before: async t =\u003e {\n        await networkRequestLogger.onBeforeHook(t);\n      },\n      after: async t =\u003e {\n        await networkRequestLogger.onAfterHook(t);\n      },\n    },\n  },\n};\n```\n\n### FILTER\n\nLeave undefined for default (records all HTTP non OPTION, JSON requests) or define custom filter as described in [testcafe docs](https://testcafe.io/documentation/402769/reference/test-api/requestlogger/constructor#select-requests-to-be-handled-by-the-hook)\n\n## Examples\n\nSee working examples in examples folder\n\n## Author\n\nRafal Szczepankiewicz\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafalsep%2Ftestcafe-global-network-request-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafalsep%2Ftestcafe-global-network-request-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafalsep%2Ftestcafe-global-network-request-logger/lists"}