google-date.spec.ts
1 import { test, expect } from '@playwright/test'; 2 3 const expectedWeekday = new Intl.DateTimeFormat('en-US', { 4 weekday: 'long', 5 }).format(new Date()); 6 const allowGoogleExperiment = process.env.ALLOW_GOOGLE_EXPERIMENT === '1'; 7 8 test.describe('Google practice example', () => { 9 test.skip( 10 !process.env.PLAYWRIGHT_BASE_URL?.includes('google.'), 11 'Set PLAYWRIGHT_BASE_URL to https://www.google.com to run this example.' 12 ); 13 14 test.fixme( 15 !allowGoogleExperiment, 16 'Set ALLOW_GOOGLE_EXPERIMENT=1 to run this learning-only Google example.' 17 ); 18 19 test.use({ locale: 'en-US' }); 20 21 test('searching for today date shows the current weekday', async ({ page }) => { 22 await page.goto('/?hl=en'); 23 24 const consentButton = page 25 .locator('button, [role="button"]') 26 .filter({ hasText: /accept all|i agree/i }) 27 .first(); 28 29 if (await consentButton.isVisible({ timeout: 3000 }).catch(() => false)) { 30 await consentButton.click(); 31 } 32 33 const searchBox = page.locator('textarea[name="q"], input[name="q"]').first(); 34 35 await expect(searchBox).toBeVisible(); 36 await searchBox.fill("today's date"); 37 await searchBox.press('Enter'); 38 39 await expect(page).toHaveURL(/\/search/); 40 await expect(page.locator('body')).toContainText(expectedWeekday); 41 }); 42 });