Enhancing Playwright Helper to Grab Headers #3216
ryust-ax
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I had a need to retrieve and evaluate header information during landing (
amOnPage()
) and subsequent transitions or navigations. I took some inspiration fromgrabBrowserLogs()
and came up with the following.Summary
Wrap the existing Playwright class with an enhancement to register a
page.on('response')
event listener.Inspired by an answer by microsoft/playwright#5761 (comment)
Definitions
require("codeceptjs")
headerStore
akin to thebrowserLogStore
inhelper/Playwright.js
helpers/playwright-extras/Header.js
helpers/playwright.js
codecept.conf.js
To Use
Note: My automation relies largely on BDD feature files and page or page-fragment definitions to more dynamically build relevant testing code.
Note: In my case, I'm looking for CSP headers in some transitions.
step_definitions/headers.steps.js
pages/CspHeader.js
codecept.conf.js
Note: Helper.findSteps() is another class built to explore the step_definitions and compile all contained
*.step.js
files into an array as expected for thesteps
property.Conclusion
I wasn't ready to try contributing to the project in a formal PR but wanted to get this out there in case it was helpful to anyone else.
If anyone has a tip on how to do something like
const { Playwright } = require("codeceptjs");
, please let me know.Beta Was this translation helpful? Give feedback.
All reactions