That is because both the page have same button. we can change the code to something like this but it will still not execute the lines after 1st check.
try {
await page.goto(‘My messages’);
page.locator('input[name="login"]').type('admin');
page.locator('input[name="password"]').type('123');
const submitButton = page.locator('input[type="submit"]');
await Promise.all([page.waitForNavigation(), submitButton.click()]);
check(page, {
'header': p => p.locator('h2').textContent() == 'Welcome, admin!',
});
const logoutbuttonlocator = page.locator("//input[@value='Logout']");
await page.locator(logoutbuttonlocator).click()
check(page, {
'header1': p => p.locator('h2').textContent() == 'Unauthorized',
});
await page.waitForTimeout(5000);
} finally {
page.close();
}