diff --git a/.github/workflows/playwright-google.yml b/.github/workflows/playwright-google.yml new file mode 100644 index 0000000..d643e6b --- /dev/null +++ b/.github/workflows/playwright-google.yml @@ -0,0 +1,39 @@ +name: Playwright Google search + +on: + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: e2e-playwright + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + cache-dependency-path: e2e-playwright/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Install Chromium + run: npx playwright install --with-deps chromium + + - name: Run Google search spec + run: npx playwright test tests/google-search.spec.ts + + - name: Upload Playwright report + if: failure() + uses: actions/upload-artifact@v4 + with: + name: playwright-report + path: e2e-playwright/playwright-report + if-no-files-found: ignore diff --git a/e2e-playwright/.gitignore b/e2e-playwright/.gitignore new file mode 100644 index 0000000..dbd64df --- /dev/null +++ b/e2e-playwright/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +test-results/ +playwright-report/ diff --git a/e2e-playwright/package-lock.json b/e2e-playwright/package-lock.json new file mode 100644 index 0000000..1d6ed95 --- /dev/null +++ b/e2e-playwright/package-lock.json @@ -0,0 +1,76 @@ +{ + "name": "ts-java-selenium-testng-playwright", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ts-java-selenium-testng-playwright", + "devDependencies": { + "@playwright/test": "1.62.1" + } + }, + "node_modules/@playwright/test": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.62.1.tgz", + "integrity": "sha512-DTcUc8qii+cpHvtOwggMtBRMjKZHXYWdw8syRYu2vtzuq4Wxphqq4NfCs5Zt44L6mA8rfDfj+PHnxFc/FeK6mQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.62.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.62.1.tgz", + "integrity": "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.62.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.62.1.tgz", + "integrity": "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/e2e-playwright/package.json b/e2e-playwright/package.json new file mode 100644 index 0000000..a3499a4 --- /dev/null +++ b/e2e-playwright/package.json @@ -0,0 +1,10 @@ +{ + "name": "ts-java-selenium-testng-playwright", + "private": true, + "scripts": { + "test": "playwright test" + }, + "devDependencies": { + "@playwright/test": "1.62.1" + } +} diff --git a/e2e-playwright/playwright.config.ts b/e2e-playwright/playwright.config.ts new file mode 100644 index 0000000..9c51e2d --- /dev/null +++ b/e2e-playwright/playwright.config.ts @@ -0,0 +1,26 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './tests', + timeout: 30_000, + expect: { + timeout: 10_000, + }, + fullyParallel: true, + forbidOnly: Boolean(process.env.CI), + retries: process.env.CI ? 2 : 0, + reporter: [['html', { outputFolder: 'playwright-report', open: 'never' }]], + use: { + headless: true, + actionTimeout: 10_000, + navigationTimeout: 30_000, + screenshot: 'only-on-failure', + trace: 'retain-on-failure', + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +}); diff --git a/e2e-playwright/tests/google-search.spec.ts b/e2e-playwright/tests/google-search.spec.ts new file mode 100644 index 0000000..31e4087 --- /dev/null +++ b/e2e-playwright/tests/google-search.spec.ts @@ -0,0 +1,18 @@ +import { expect, test } from '@playwright/test'; + +test('Google search title contains the query', async ({ page }) => { + await page.goto('https://www.google.co.in/?hl=en'); + + const consentButton = page + .getByRole('button', { name: /accept all|i agree/i }) + .first(); + if (await consentButton.isVisible().catch(() => false)) { + await consentButton.click(); + } + + const searchInput = page.locator('[name="q"]'); + await searchInput.fill('abc'); + await searchInput.press('Enter'); + + await expect(page).toHaveTitle(/abc/i); +});