SShortSingh.
Back to feed

Fixing Playwright 401 Errors on Protected Routes with storageState

0
·4 views

A developer found that Playwright E2E tests accessing protected pages returned 401 Unauthorized errors even though the same flow worked in a regular browser. The cause is that Playwright runs each test in a fresh browser context, so cookies, localStorage, and tokens from a login test are not carried over to later tests. The suggested fix is to save the authenticated session after login using page.context().storageState({ path: 'auth.json' }), which writes cookies and localStorage to a file. This saved state can then be reused so that tests on protected routes start already signed in. The article illustrates the approach with a sign-in test and an example of the resulting auth.json contents.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Software Project Risk Register: Template and 15 Example Risks

A risk register lists potential problems along with their likelihood, severity, owner, planned response, and status. For software projects, the author recommends six core columns: risk, probability, impact, owner, response, and status. The guide distinguishes risks from blockers and open questions, which can all sit in one list if each item is typed. Risks should be phrased as conditional statements so they cannot be mistaken for tasks. A 1-to-5 scale for probability and impact, multiplied into a score, is suggested, with scores of 15 or more typically requiring action before work begins. The article includes an invented example project with 15 typical risks to adapt.

0
ProgrammingDEV Community ·

Requirements Traceability Matrix: What It Is and How to Build One

A requirements traceability matrix is a table linking each requirement to its goals, design, tasks, and tests, showing whether promised features are built and verified. It helps teams evaluate proposed changes, spot coverage gaps when features are cut, identify untested requirements, and justify why a feature exists. The article distinguishes forward, backward, and bidirectional traceability, with bidirectional being the most common approach for teams. It recommends a single table with stable requirement IDs and only the columns teams will actually maintain, and includes an invented example for a customer order portal. The matrix is presented as an index across requirements documents rather than a replacement for them.

0
ProgrammingDEV Community ·

Business Requirements Document Template and Example for Project Planning

A business requirements document records why a project exists and what the business needs before any decisions about how to build it. It is aimed at the people who fund and approve the work, and it serves as a reference for later questions about why a feature exists. The document answers four core questions: the business problem, the desired outcome, what is in and out of scope, and what must hold for success. It is distinct from a product requirements document and a software requirements specification, which cover product behaviour and technical detail respectively. The guide provides a copyable template covering sections such as objectives, scope, stakeholders, risks, and approval, and advises writing the executive summary last since some approvers only read that part.

0
ProgrammingDEV Community ·

Decade-Long Drupal Maintenance Keeps AgeGuess Citizen Science Platform Running

AgeGuess.org presents itself as a simple guessing game in which players estimate how old people look in photographs. Behind it is an open scientific database of perceived age, a biomarker used to study human ageing, built from more than 220,000 guesses submitted by citizen scientists in over 120 countries since 2012. The article is written by an independent French developer who maintained the platform on Drupal from 2014 to 2024, after taking over web development from earlier contributors. It describes how the platform's architecture serves both the public game and the research dataset, which has been published in Nature's Scientific Data. The piece also reflects on what sustaining a citizen science project over a decade requires in practice.