From b26eaa8ccc108e69faccc50d2111765b49ac7f63 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 5 Apr 2024 16:06:11 -0500 Subject: [PATCH] Move Playwright tests to top level of XFD repo, make changes needed for Github Actions. --- .github/workflows/playwright.yml | 36 +++++++++++++++++++ .../.github/workflows/playwright.yml | 21 ----------- .../xfd_playwright => playwright}/.gitignore | 0 .../e2e/global-admin/home.spec.ts | 0 .../e2e/global-admin/inventory.spec.ts | 0 .../e2e/global-admin/vulnerabilities.spec.ts | 0 .../global-setup.ts | 10 +++--- .../package-lock.json | 0 .../package.json | 0 .../playwright.config.ts | 2 +- .../tests-examples/demo-todo-app.spec.ts | 0 .../tests/example.spec.ts | 0 12 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/playwright.yml delete mode 100644 frontend/xfd_playwright/.github/workflows/playwright.yml rename {frontend/xfd_playwright => playwright}/.gitignore (100%) rename {frontend/xfd_playwright => playwright}/e2e/global-admin/home.spec.ts (100%) rename {frontend/xfd_playwright => playwright}/e2e/global-admin/inventory.spec.ts (100%) rename {frontend/xfd_playwright => playwright}/e2e/global-admin/vulnerabilities.spec.ts (100%) rename {frontend/xfd_playwright => playwright}/global-setup.ts (81%) rename {frontend/xfd_playwright => playwright}/package-lock.json (100%) rename {frontend/xfd_playwright => playwright}/package.json (100%) rename {frontend/xfd_playwright => playwright}/playwright.config.ts (97%) rename {frontend/xfd_playwright => playwright}/tests-examples/demo-todo-app.spec.ts (100%) rename {frontend/xfd_playwright => playwright}/tests/example.spec.ts (100%) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 00000000..8962bc42 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,36 @@ +--- +name: Playwright Tests +on: + deployment_status: + paths: + - 'playwright/**' + - '.github/workflows/playwright.yml' +defaults: + run: + working-directory: ./playwright +env: + PW_XFD_URL: ${{ vars.PW_XFD_URL }} + PW_XFD_USERNAME: ${{ secrets.PW_XFD_USERNAME }} + PW_XFD_PASSWORD: ${{ secrets.PW_XFD_PASSWORD }} + PW_XFD_2FA_ISSUER: ${{ secrets._PW_XFD_2FA_ISSUER }} + PW_XFD_2FA_SECRET: ${{ secrets.PW_XFD_2FA_SECRET }} + PW_XFD_USER_ROLE: ${{ vars.PW_XFD_USER_ROLE }} + +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/playwright:v1.41.2-jammy + if: github.event.deployment_status.state == 'success' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: cd ../playwright && npm ci + - name: Run your tests + run: npx playwright test + env: + HOME: /root diff --git a/frontend/xfd_playwright/.github/workflows/playwright.yml b/frontend/xfd_playwright/.github/workflows/playwright.yml deleted file mode 100644 index 6c23b4d8..00000000 --- a/frontend/xfd_playwright/.github/workflows/playwright.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: Playwright Tests -on: - deployment_status: -jobs: - test: - timeout-minutes: 60 - runs-on: ubuntu-latest - container: - image: mcr.microsoft.com/playwright:v1.41.2-jammy - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Install dependencies - run: npm ci - - name: Run your tests - run: npx playwright test - env: - HOME: /root diff --git a/frontend/xfd_playwright/.gitignore b/playwright/.gitignore similarity index 100% rename from frontend/xfd_playwright/.gitignore rename to playwright/.gitignore diff --git a/frontend/xfd_playwright/e2e/global-admin/home.spec.ts b/playwright/e2e/global-admin/home.spec.ts similarity index 100% rename from frontend/xfd_playwright/e2e/global-admin/home.spec.ts rename to playwright/e2e/global-admin/home.spec.ts diff --git a/frontend/xfd_playwright/e2e/global-admin/inventory.spec.ts b/playwright/e2e/global-admin/inventory.spec.ts similarity index 100% rename from frontend/xfd_playwright/e2e/global-admin/inventory.spec.ts rename to playwright/e2e/global-admin/inventory.spec.ts diff --git a/frontend/xfd_playwright/e2e/global-admin/vulnerabilities.spec.ts b/playwright/e2e/global-admin/vulnerabilities.spec.ts similarity index 100% rename from frontend/xfd_playwright/e2e/global-admin/vulnerabilities.spec.ts rename to playwright/e2e/global-admin/vulnerabilities.spec.ts diff --git a/frontend/xfd_playwright/global-setup.ts b/playwright/global-setup.ts similarity index 81% rename from frontend/xfd_playwright/global-setup.ts rename to playwright/global-setup.ts index 7130526f..410d250a 100644 --- a/frontend/xfd_playwright/global-setup.ts +++ b/playwright/global-setup.ts @@ -7,12 +7,12 @@ dotenv.config(); const authFile = './storageState.json'; let totp = new OTPAuth.TOTP({ - issuer: process.env.CROSSFEED_2FA_ISSUER, + issuer: process.env.PW_XFD_2FA_ISSUER, label: 'Crossfeed', algorithm: 'SHA1', digits: 6, period: 30, - secret: process.env.CROSSFEED_2FA_SECRET + secret: process.env.PW_XFD_2FA_SECRET }); async function globalSetup(config: FullConfig) { @@ -21,13 +21,13 @@ async function globalSetup(config: FullConfig) { const page = await browser.newPage(); //Log in with credentials. - await page.goto(String(process.env.CROSSFEED_URL)); + await page.goto(String(process.env.PW_XFD_URL)); await page .getByPlaceholder('Enter your email address') - .fill(String(process.env.CROSSFEED_USERNAME)); + .fill(String(process.env.PW_XFD_USERNAME)); await page .getByPlaceholder('Enter your password') - .fill(String(process.env.CROSSFEED_PASSWORD)); + .fill(String(process.env.PW_XFD_PASSWORD)); await page.getByRole('button', { name: 'Sign in' }).click(); await page .getByPlaceholder('Enter code from your authenticator app') diff --git a/frontend/xfd_playwright/package-lock.json b/playwright/package-lock.json similarity index 100% rename from frontend/xfd_playwright/package-lock.json rename to playwright/package-lock.json diff --git a/frontend/xfd_playwright/package.json b/playwright/package.json similarity index 100% rename from frontend/xfd_playwright/package.json rename to playwright/package.json diff --git a/frontend/xfd_playwright/playwright.config.ts b/playwright/playwright.config.ts similarity index 97% rename from frontend/xfd_playwright/playwright.config.ts rename to playwright/playwright.config.ts index d8bc1e26..2781f82f 100644 --- a/frontend/xfd_playwright/playwright.config.ts +++ b/playwright/playwright.config.ts @@ -33,7 +33,7 @@ export default defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.CROSSFEED_URL, + baseURL: process.env.PW_XFD_URL, storageState: 'storageState.json', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ diff --git a/frontend/xfd_playwright/tests-examples/demo-todo-app.spec.ts b/playwright/tests-examples/demo-todo-app.spec.ts similarity index 100% rename from frontend/xfd_playwright/tests-examples/demo-todo-app.spec.ts rename to playwright/tests-examples/demo-todo-app.spec.ts diff --git a/frontend/xfd_playwright/tests/example.spec.ts b/playwright/tests/example.spec.ts similarity index 100% rename from frontend/xfd_playwright/tests/example.spec.ts rename to playwright/tests/example.spec.ts