raptatinha / tau-advanced-playwright

Course Advanced Playwright by Renata Andrade for Test Automation University
https://testautomationu.applitools.com/
MIT License
67 stars 192 forks source link

storageState coming empty when authenticating via API #4

Open arturotg-r opened 11 months ago

arturotg-r commented 11 months ago

🐞 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