So i have written a function that in short clicks an FAQs button and validate that the new tab is open on the same browser Context. the issue i have when running my test is i get:
TypeError: Cannot read property 'title' of undefined
Heres my function - PATH src/tests/rms/logoutAndFaqs.spec.ts:
async shouldSeeFaqsInNewTab() {
const browserName = await chromium.launch();
const context = await browserName.newContext();
const pages = await context.pages();
await this.click(HomeScreen.faqButton);
await this.page.waitForTimeout(1000);
expect(await pages[1].title())?.toBe("Title");
}
and heres is the function getting called - PATH src/pages/rms/rmsHome.page.ts:
import test from "../../helpers/base.page";
test.describe("Ensure you land on the home page when logged in", () => {
test.beforeEach(async ({ rmsHome }) => {
await rmsHome.gotoRmsHomePage();
});
test.only("Validate that FAQs opens in a new tab", async ({ rmsHome }) => {
await rmsHome.shouldSeeFaqsInNewTab();
});
});
i know that this line expect(await pages[1].title())?.toBe("Title") specifically is accessing the tab opened within the window and within the browserContext its validating the title expecting a string to equal "Title".
specifically title() is causing an error due to being an unassign value. im trying to understand why this error? and how to fix it. thanks