I am developing E2E tests with Playwright for angular app. I have to ensure that needed conditional selector exists in order to proceed, otherwise skip further tests.
In other words I need to skip all tests in a group if await page.isVisible('button[id=container]')
condition is not satisfied in beforeAll
hook.
The problem is that only the first test is being skipped and the second one is being passed(which is wrong). Please check screenshot below.
Here is the code:
test.describe.serial('Products ', () => {
let page: Page;
test.beforeAll(async ({ browser, baseURL }) => {
page = await browser.newPage();
await page.goto(baseURL as string, opt);
if (await page.isVisible('button[id=container]')) {
await page.locator('button[id=container]').click();
} else {
console.log('Error: Container tab is not loaded...');
test.skip();
}
});
test.only('Check if "Menu" tab is available', async () => {
... test goes here ...
});
test.only('Check if Orders page is available', async () => {
... test goes here ...
});
});
The interesting thing is that playwright skips all tests when beforeEach
hook is used instead, but I would like to achieve this result within beforeAll
hook.