From 1279dc866cff0e3a73f98c0f407bfb8e67597e81 Mon Sep 17 00:00:00 2001 From: Javier Briones <1674192+jvbriones@users.noreply.github.com> Date: Wed, 22 May 2024 11:18:03 +0200 Subject: [PATCH] chore: initial setup (#1) --- .env_example | 3 ++ .github/CODEOWNERS | 1 + .github/workflows/validate_changes.yml | 27 +++++++++++++++ .gitignore | 8 +++++ README.md | 11 +++++- package.json | 15 +++++++++ playwright.config.ts | 34 +++++++++++++++++++ tests/feature1.spec.ts | 14 ++++++++ yarn.lock | 46 ++++++++++++++++++++++++++ 9 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 .env_example create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/validate_changes.yml create mode 100644 .gitignore create mode 100644 package.json create mode 100644 playwright.config.ts create mode 100644 tests/feature1.spec.ts create mode 100644 yarn.lock diff --git a/.env_example b/.env_example new file mode 100644 index 0000000..b1fee3b --- /dev/null +++ b/.env_example @@ -0,0 +1,3 @@ +# E2E PLAYWRIGHT VALUES +# PWDEBUG=1 +E2E_BASE_URL= diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..102e6fb --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @jvbriones \ No newline at end of file diff --git a/.github/workflows/validate_changes.yml b/.github/workflows/validate_changes.yml new file mode 100644 index 0000000..12c6676 --- /dev/null +++ b/.github/workflows/validate_changes.yml @@ -0,0 +1,27 @@ +name: Validate changes +on: + push: + branches: main + pull_request: + +jobs: + E2E-scenarios: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Install dependencies + run: npm install -g yarn && yarn + - name: Install Playwright Browsers + run: yarn playwright install --with-deps chromium + - name: 🧪 Run Playwright tests + run: E2E_BASE_URL=https://portfolio.metamask.io/ yarn test:e2e + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-tests-report + path: test-results/ + retention-days: 15 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df2cf5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/node_modules +.env +.DS_Store +.vscode/* +.idea +/test-results/ +/playwright-report/ + diff --git a/README.md b/README.md index 95f6f50..bb79460 100644 --- a/README.md +++ b/README.md @@ -1 +1,10 @@ -# tmpqachallenge1 \ No newline at end of file +# E2E demo project + +## Setup +> yarn + +## Run tests in local +> npx playwright test --grep '@tag' + +## CI pipeline +Github workflow under /.github/workflows/validate_changes.yml diff --git a/package.json b/package.json new file mode 100644 index 0000000..52b4595 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "e2e-demo-project", + "version": "0.0.1", + "license": "UNDEFINED", + "devDependencies": { + "@playwright/test": "^1.44.0", + "@types/node": "^20.12.12" + }, + "scripts": { + "test:e2e-smoke": "xvfb-run yarn playwright test -g @e2e" + }, + "dependencies": { + "dotenv": "^16.4.5" + } +} diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..b1825bc --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,34 @@ +import { defineConfig, devices } from '@playwright/test'; +require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + fullyParallel: false, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 1 : 0, + workers: process.env.CI ? 2 : 1, + reporter: [ + ['list'], + ['html', { outputFolder: 'test-results/e2e-html-report', open: 'never' }], + ['junit', { outputFile: 'test-results/e2e-junit.xml' }], + ], + outputDir: 'test-results/e2e-test-artifacts', + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: process.env.E2E_BASE_URL + '/', + screenshot: 'on', + video: 'on-first-retry', + trace: 'on-first-retry', + userAgent: 'Playwright E2E Tests', + }, + + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + } + ], +}); diff --git a/tests/feature1.spec.ts b/tests/feature1.spec.ts new file mode 100644 index 0000000..0da61d7 --- /dev/null +++ b/tests/feature1.spec.ts @@ -0,0 +1,14 @@ +import { test, expect } from '@playwright/test'; + +test('has title', async ({ page }) => { + await page.goto('https://playwright.dev/'); + await expect(page).toHaveTitle(/Playwright/); +}); + +test('Watch account @smoke', async ({ page }) => { + await page.goto('.'); + await page.getByPlaceholder('Wallet address or ENS name').fill('vitalik.eth'); + await page.getByRole('button', { name: 'Watch address' }).click(); + await page.locator('#sidebar-item-Dashboard').click(); + await page.locator('tr').filter({ hasText: 'Ethereum' }).first().click() +}); diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..73a9b8c --- /dev/null +++ b/yarn.lock @@ -0,0 +1,46 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@playwright/test@^1.44.0": + version "1.44.0" + resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.44.0.tgz#ac7a764b5ee6a80558bdc0fcbc525fcb81f83465" + integrity sha512-rNX5lbNidamSUorBhB4XZ9SQTjAqfe5M+p37Z8ic0jPFBMo5iCtQz1kRWkEMg+rYOKSlVycpQmpqjSFq7LXOfg== + dependencies: + playwright "1.44.0" + +"@types/node@^20.12.12": + version "20.12.12" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.12.12.tgz#7cbecdf902085cec634fdb362172dfe12b8f2050" + integrity sha512-eWLDGF/FOSPtAvEqeRAQ4C8LSA7M1I7i0ky1I8U7kD1J5ITyW3AsRhQrKVoWf5pFKZ2kILsEGJhsI9r93PYnOw== + dependencies: + undici-types "~5.26.4" + +dotenv@^16.4.5: + version "16.4.5" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" + integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== + +fsevents@2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + +playwright-core@1.44.0: + version "1.44.0" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.44.0.tgz#316c4f0bca0551ffb88b6eb1c97bc0d2d861b0d5" + integrity sha512-ZTbkNpFfYcGWohvTTl+xewITm7EOuqIqex0c7dNZ+aXsbrLj0qI8XlGKfPpipjm0Wny/4Lt4CJsWJk1stVS5qQ== + +playwright@1.44.0: + version "1.44.0" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.44.0.tgz#22894e9b69087f6beb639249323d80fe2b5087ff" + integrity sha512-F9b3GUCLQ3Nffrfb6dunPOkE5Mh68tR7zN32L4jCk4FjQamgesGay7/dAAe1WaMEGV04DkdJfcJzjoCKygUaRQ== + dependencies: + playwright-core "1.44.0" + optionalDependencies: + fsevents "2.3.2" + +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==