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
maybe adding a wait for domcontentloaded before getting a page title will help
I tested you code and it works
If you want to use consol.log you must think about using ConsoleMessage. There is an issue mentioned right here