Rayrun
← Back to Discord Forum

save on goto, just load page once and run tests on that page

Consider the following code. when i run this it errors "no tests found"

the only option to run tests is to have a new page goto for each test. I would like to group multiple tests in one page load.

why doesn't this work?

(async () => {
  const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
  const page = await browser.newPage();
  await page.setViewportSize({
    width: 640,
    height: 480,
  });

  await page.goto("https://www.test.com/");
  // other actions...


  const dataLayerArray = await page.evaluate(() => window.dataLayer);

  test("data layer is setup", async () => {
    expect(dataLayerArray).toBeDefined();
  });

  test("page_view event is fired", async () => {
    const pageViewEvent = dataLayerArray.find((event: { event: string; }) => event.event === "page_view");
    expect(pageViewEvent).toBeDefined();
  });
})();

any suggestions on how to group tests the correct way and save on a page setup / test

This thread is trying to answer question "Why doesn't the code work when trying to group multiple tests in one page load and how can it be corrected?"

0 replies

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].