question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to make test() use the same browser instance as the beforeAll. (Ignore test isolation)

See original GitHub issue

~~UPDATE: Check my comment https://github.com/microsoft/playwright/issues/14508#issuecomment-1143274596~~ UPDATE 2: Check my comment https://github.com/microsoft/playwright/issues/14508#issuecomment-1144617999

I am trying to reuse the authentication example provided at the documentation for multiple .spec files (I know that is not recommended but it is necessary for my case)

Is there any recommendation of POM with fixture that I can do to solve that issue?

I want to avoid rewrite this part multiple times:

test.beforeAll(async ({ browser }) => {
  // Create page once and sign in.
  page = await browser.newPage();
  await page.goto('https://github.com/login');
  await page.fill('input[name="user"]', 'user');
  await page.fill('input[name="password"]', 'password');
  await page.click('text=Sign in');
});

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
aslushnikovcommented, Jun 2, 2022

Should I not use the custom fixture and just do every time a instance of each PO per test set file?

@gegoncalves Yeah, I’d do it without fixtures! It should work reliably in case of single-page re-use.

1reaction
gegoncalvescommented, Jun 2, 2022

I don’t know if I understood your question @aslushnikov correctly

So you are asking to use a global variable instead of the custom fixtures? I was thinking to use the custom fixtures due to the fact of being easier to just call the related pages through fixtures per test case than create an instance of each used POM

The generalActions class will be only the basic method we have. Ex:

async clickElement(locator: string): Promise<void> {
        await this.page.locator(locator).waitFor();
        await this.page.locator(locator).click();
    }

this method we use inside of each PO we have. Ex:

// process-page.ts

  ...
  async addProcess(): Promise<Locator> {
        await generalActions.clickElement(list_locator);
        await generalActions.clickElement(process_locator);
        return this.getModal();
    };
   ...

    async getModal(): Promise<Locator> {
        await generalActions.waitForElementAttached(tab_locator);
        return generalActions.page.locator(MODAL_DIV);
    };

And after we have the fixture creation for each page that I shown here

Should I not use the custom fixture and just do every time a instance of each PO per test set file?

Probably I am doing something stupid without noticing 😅

For real, thanks for giving your time to help me with that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using same browser instance how to run the test suite
I'm having a testsuite(4 classes) which have common login for all classes. When I run the test suite, with first class alone having...
Read more >
Unit testing fundamentals - Visual Studio (Windows)
Learn how Visual Studio Test Explorer provides a flexible and efficient way to run your unit tests and view their results.
Read more >
Testing - Spring
This chapter covers Spring's support for integration testing and best practices for unit testing. The Spring team advocates test-driven ...
Read more >
React end-to-end testing with Jest and Puppeteer
End-to-end tests simulate actual user actions and are designed to test how a real user would likely use the application. In React, E2E...
Read more >
Write a synthetic test | Observability Guide [8.5] - Elastic
If there are any actions that should be done before or after journeys, you can use before , beforeAll , after , or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found