skip to Main Content

The below code is my Playwright test function

    test("@Login @Testing Sign In Page Test", async ({ page }) => {
        console.log("Sign In Page Test");
 
        const pageManager = new pageObjectManager(page);
        const homePage = pageManager.getHomePage();
        const loginPage = pageManager.getLoginPage();
        const signInPage = pageManager.getSignInPage();

        // await homePage.goToHomePage();
        await page.goto("https://magento.softwaretestingboard.com/");

        // await loginPage.goToSignInPage();
        console.log(await page.title());
        await page.locator("//li[@class='authorization-link']").first().click();

        // await signInPage.validateLandingOnSignInPage();
        console.log(await page.title());
        await expect(page).toHaveTitle("Customer Login");
    });

This worked for me a few months ago but now, when I am trying to rerun the test case, I run into the below error

Error: page.title: Target page, context or browser has been closed

      34 |
      35 |      // await signInPage.validateLandingOnSignInPage();
    > 36 |      console.log(await page.title());
         |                             ^
      37 |      await expect(page).toHaveTitle("Customer Login");
      38 | });
      39 |

Even when I place the code in functions mentioned in comments just above them, I see the issue.

I am not sure what is causing this fresh issue. Please help me. Thanks in advance.

2

Answers


  1. maybe adding a wait for domcontentloaded before getting a page title will help

     await this.page.waitForLoadState('domcontentloaded');
    
    Login or Signup to reply.
  2. I tested you code and it works

    import { test, expect } from '@playwright/test';
    
    test('test', async ({ page }) => {
      await page.goto('https://magento.softwaretestingboard.com/');
      await expect(page).toHaveTitle("Home Page");
      await page.getByRole('link', { name: 'Sign In' }).click();
      await expect(page).toHaveTitle("Customer Login");
    });
    

    If you want to use consol.log you must think about using ConsoleMessage. There is an issue mentioned right here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search