From eb56fce393734f5d961f99d0db7f35cf3f78cf9e Mon Sep 17 00:00:00 2001 From: Daniel Bennett Date: Mon, 27 Nov 2023 12:26:19 -0600 Subject: [PATCH] e2e: fix ui tests (#19138) --- e2e/ui/global-setup.js | 5 +-- e2e/ui/input/proxy.nomad | 11 ++++++ e2e/ui/playwright.config.js | 12 +++++-- e2e/ui/run.sh | 66 +++++++++++++++++++++++++++++------- e2e/ui/tests/example.spec.js | 2 +- 5 files changed, 79 insertions(+), 17 deletions(-) diff --git a/e2e/ui/global-setup.js b/e2e/ui/global-setup.js index e1a8362f3..e14e56d16 100644 --- a/e2e/ui/global-setup.js +++ b/e2e/ui/global-setup.js @@ -22,8 +22,9 @@ module.exports = async config => { const page = await context.newPage(); await page.goto(NOMAD_ADDR+'/ui/settings/tokens'); await page.fill('input[id="token-input"]', NOMAD_TOKEN); - await page.click('button:has-text("Set Token")', {strict: true}); + await page.click('button:has-text("Sign in")', {strict: true}); - await page.context().storageState({ path: 'storageState.json' }); + const { storageState } = config.projects[0].use; + await page.context().storageState({ path: storageState }); await browser.close(); }; diff --git a/e2e/ui/input/proxy.nomad b/e2e/ui/input/proxy.nomad index d883e7707..b665a8d37 100644 --- a/e2e/ui/input/proxy.nomad +++ b/e2e/ui/input/proxy.nomad @@ -19,6 +19,17 @@ job "nomad-proxy" { } } + service { + name = "nomad-proxy" + port = "www" + provider = "nomad" + check { + type = "tcp" + interval = "1s" + timeout = "2s" + } + } + task "nginx" { driver = "docker" diff --git a/e2e/ui/playwright.config.js b/e2e/ui/playwright.config.js index 9fadf93d9..5fa1156f6 100644 --- a/e2e/ui/playwright.config.js +++ b/e2e/ui/playwright.config.js @@ -7,6 +7,8 @@ // @ts-check const { devices } = require('@playwright/test'); +export const STORAGE_STATE = 'storageState.json'; + /** @type {import('@playwright/test').PlaywrightTestConfig} */ const config = { forbidOnly: !!process.env.CI, @@ -19,7 +21,10 @@ const config = { projects: [ { name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + use: { + ...devices['Desktop Chrome'], + storageState: STORAGE_STATE, + }, }, // disabling firefox temporarily because the container doesn't // include it and so it tries to automatically install it and @@ -31,7 +36,10 @@ const config = { // }, { name: 'webkit', - use: { ...devices['Desktop Safari'] }, + use: { + ...devices['Desktop Safari'], + storageState: STORAGE_STATE, + }, }, ], }; diff --git a/e2e/ui/run.sh b/e2e/ui/run.sh index 31257eb41..48cf2711d 100755 --- a/e2e/ui/run.sh +++ b/e2e/ui/run.sh @@ -2,7 +2,7 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: BUSL-1.1 -set -e +set -eu help() { cat <&2 echo 'unable to get an IP for nomad proxy...' + exit 1 # bad form to exit from a function, but this is essential (and eval'd) + } + echo "export NOMAD_ADDR=https://$IP:6464" +} + +_get_aws_ip(){ + aws_metadata_url="http://169.254.169.254/latest/meta-data" + nomad exec -namespace=proxy -job nomad-proxy \ + curl -s "$aws_metadata_url/public-ipv4" +} + +_get_svc_ip() { + nomad service info -namespace=proxy \ + -t '{{ range . }}{{ .Address }}{{ end }}' \ + nomad-proxy +} + +stop_proxy() { + # make sure addr isn't still pointed at the proxy + export NOMAD_ADDR="${NOMAD_ADDR/6464/4646}" + nomad job stop -namespace=proxy nomad-proxy + nomad namespace delete proxy +} + +run_ci() { + set -x + run_proxy > /tmp/proxy_addr.env + source /tmp/proxy_addr.env + run_tests + rc=$? + stop_proxy + exit $rc } opt="$1" @@ -69,8 +111,8 @@ case $opt in help|--help|-h) help ;; proxy|--proxy) run_proxy ;; test|--test) shift ; run_tests "$@" ;; - shell) shift ; run_shell ;; + stop|--stop) stop_proxy ;; + ci|--ci) run_ci ;; + shell) shift ; run_shell "$@" ;; *) run_tests "$@" ;; esac - -run_tests diff --git a/e2e/ui/tests/example.spec.js b/e2e/ui/tests/example.spec.js index 04ec9bb5b..81c10771e 100644 --- a/e2e/ui/tests/example.spec.js +++ b/e2e/ui/tests/example.spec.js @@ -19,6 +19,6 @@ test('authenticated users can see their policies', async ({ page }) => { await expect(logo).toBeVisible(); - const policies = page.locator('text=Policies') + const policies = page.getByText('Policies'); await expect(policies).toBeVisible(); });