From 484792b8ac25d4838daa61b206564ac8453da40a Mon Sep 17 00:00:00 2001 From: Ryan Andrews Date: Tue, 24 Sep 2024 12:02:43 +0100 Subject: [PATCH] ATO-1063: Adds fetching env var for test context We're now setting up the basic auth details in the ssm and pulling them in as environment variables. This adds the values to the test context and also throws if the values are not defined. This should hopefully avoid a long feedback loop if these are not set correctly --- ui-automation-tests/support/test-setup.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ui-automation-tests/support/test-setup.ts b/ui-automation-tests/support/test-setup.ts index 184d26377..4a5a11b12 100644 --- a/ui-automation-tests/support/test-setup.ts +++ b/ui-automation-tests/support/test-setup.ts @@ -33,9 +33,13 @@ export class TestContext extends World { private _otp_code: string = sms_otp_code; private _email_code: string = email_otp_code; private _servicename: string = servicename; + public basicAuthUsername: string; + public basicAuthPassword: string; constructor(options: IWorldOptions) { super(options); + this.basicAuthUsername = getEnvOrThrow("BASIC_AUTH_USERNAME"); + this.basicAuthPassword = getEnvOrThrow("BASIC_AUTH_PASSWORD"); } async goToPath(path: string) { @@ -180,3 +184,10 @@ AfterAll(async function () { }); setWorldConstructor(TestContext); + +const getEnvOrThrow = (key: string): string => { + if (!process.env[key]) { + throw new Error(`Test environment variable is not defined: "${key}"`); + } + return process.env[key]; +};