Skip to content

storageState coming empty when authenticating via APIΒ #4

@arturotg-r

Description

@arturotg-r

🐞 Describe the question:

Hello! Hope you are doing well! I've been stuck with the API authentication exercise. I'm using the demoqa.com site so I might be ignoring something.

This is what I have:

import { test as setup, type Page, chromium } from '@playwright/test';

const authFile = '.auth/api-admin.json';

setup('authenticate', async ({ request }) => {
  
  // Send authentication request. Replace with your own.
  await request.post('https://demoqa.com/Account/v1/GenerateToken', {
    form: {
      "email":"tau-admin",
      "password":"TestingWithR3n@t@"}
    });
  
  await request.storageState({ path: authFile });
});

This will pass and I get a 200 response, but for some reason, there's no cookies info in the json file. This is the resulting json file

{ "cookies": [], "origins": [] }

Checking the tracing I don't see any cookies in the response.

I already tried with the different APIs that are available in the Swagger doc, but I'm getting the same result. The APIs I tried are:
https://demoqa.com/Account/v1/Authorized
https://demoqa.com/Account/v1/GenerateToken
https://demoqa.com/Account/v1/Login

My guess is that I have to use the generated token, but not sure how to accomplish this or if this is the right approach.

Hope that you can help πŸ˜… and thanks in advance!

🎑 A picture of your pet or a toy or something really cool:
image

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is neededpendingquestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions