Skip to content

Playwright Multiple user authentication" Screen is launching a blank page.Β #619

@InduKrish

Description

@InduKrish

We are using Playwright testing library for our test framework, and it is really helpful, now we are trying to do authentication once then reuse session storage, storage state (cookies) for the rest of the tests instead of manually logging in every time.

here is the link for reference.
https://playwright.dev/docs/auth

I am able to capture session storage and reuse it for logging in and perform only playwright page queries , not able to execute screen queries(eg: queryByTestId())..

i see the test opens a blank page and the other page with the actual URL.
looks like the issue is that the screen fixture opens up a blank page, and it is searching for the locator on the blank page.
if i remove screen fixture from the code below, it works ok, but adding a screen fixture opens up a blank page, and queryByTestId() is looking to search for the element on the blank page, instead of searching the element on the other window that opens the actual URL.

Can you please advise how to get rid of the blank page or how to make screen point to the actual page instead of the blank page? Can you please assist?

const base = require("@playwright/test");
import {locatorFixtures as fixtures} from '@playwright-testing-library/test/fixture';
const it = base.test.extend(fixtures);
const {expect} = it;

import {UseBidAndAwardActor} from '../web/actors/BidAndAwardActors';
import Env from "../web/utils/Env"

export const test = it.extend({

crewIFPlannerActor: async ({browser, context, screen},use) => {
       context = await browser.newContext({ storageState: './storage-state2.json' });
    
        const sessionStorage = process.env.SESSION_STORAGE;
        await context.addInitScript(storage => {
            const entries = JSON.parse(storage);
            Object.keys(entries).forEach(key => {
                window.sessionStorage.setItem(key, entries[key]);
            });
        }, sessionStorage);

      //adding session storage to the context and creating a page using that context, to avoid manual login.
       const page = await context.newPage({ignoreHTTPSErrors: true});

// this initializes screen in the constructor,
        const crewIFPlannerActor = UseBidAndAwardActor(page, page, 'IF Planner Actor', `${Env.IF_PLANNER_USERNAME}`, `${Env.IF_PLANNER_PASSWORD}`,  screen, page);
        crewIFPlannerActor.with('page', page);
        crewIFPlannerActor.with('screen', screen);
        crewIFPlannerActor.with('within', page);

        await use(crewIFPlannerActor);
   
    },
});

export {expect} from '@playwright/test';

Test:

test.only('user test fixture', async ({ crewIFPlannerActor, isMobile }) => {

    const page = crewIFPlannerActor.states('page');
     await crewIFPlannerActor.attemptsTo(Navigate.to(Env.CREW_PLANNER_BASE_URL));
});
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions