Skip to content

feat: include the recorded request in grabRecordedNetworkTraffics - #5801

Draft
landon-medme wants to merge 4 commits into
codeceptjs:4.xfrom
landon-medme:feat/grab-traffic-request-headers
Draft

landon-medme wants to merge 4 commits into
codeceptjs:4.xfrom
landon-medme:feat/grab-traffic-request-headers

Conversation

@landon-medme

Copy link
Copy Markdown

Motivation/Description of the PR

  • grabRecordedNetworkTraffics returned only url and response, so a test could not assert on what was sent: a request header (e.g. a correlation id), the method or the body. Every traffic-recording helper already stores this on each recorded request; it was dropped when building the result, so tests had to reach into this.helpers.Playwright.requests to get it.

  • Each entry now also has a request object alongside response:

    { url, request: { url, method, headers, postData }, response: { status, statusText, body } }
  • request.postData is JSON-parsed when it is a JSON string. Playwright and Puppeteer record the raw string (their typeof === 'object' guard never matches a string) while CDPBrowser records parsed JSON, so without this the type would differ by helper. Non-JSON bodies are returned unchanged.

  • Additive only: existing url and response fields are untouched.

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium
  • TestCafe

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

CDPBrowser also uses the shared grabRecordedNetworkTraffics and is covered by the same change.

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

Testing

Ran the traffic tests in test/helper/Playwright_test.js locally:

  • The two new tests (should grab the request of recorded traffics, should grab JSON post data of recorded traffics as an object) pass, and fail on 4.x without this change.
  • should see recording traffics fails both with and without this change: codecept.io no longer serves img/companies/BC_LogoScreen_C.jpg.
  • Puppeteer and CDPBrowser were not run locally. The traffic tests are skipped in CI because they hit external URLs.

Only the docs/webapi partial was edited; docs/helpers/ is left for the docs autogeneration.

Every helper that records traffic (Playwright, Puppeteer, CDPBrowser) already
stores requestHeaders on each recorded request, but grabRecordedNetworkTraffics
dropped them, so tests had to reach into helper internals to assert on a
request header.
Expose url, method, headers and postData as a request object alongside
response, instead of only the headers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant