From ff330bd83bf22ef9344ac9be0bef63b02f2c3e2e Mon Sep 17 00:00:00 2001 From: Dan Caseley Date: Thu, 5 Dec 2024 23:40:36 +0000 Subject: [PATCH] Fix environment variables for multi-flow runs (#2163) * Add e2e-test for environment variables * Apply environment variables to test suite runs (fixes #2101) --- .github/workflows/test-e2e.yaml | 1 + e2e/workspaces/no-app/README.md | 5 +++++ e2e/workspaces/no-app/environment-variables.yaml | 6 ++++++ .../src/main/java/maestro/cli/runner/TestSuiteInteractor.kt | 6 +++++- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 e2e/workspaces/no-app/README.md create mode 100644 e2e/workspaces/no-app/environment-variables.yaml diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index c6675563d0..bff56c597d 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -56,6 +56,7 @@ jobs: ANDROID_HOME: /home/runner/androidsdk ANDROID_SDK_ROOT: /home/runner/androidsdk ANDROID_OS_IMAGE: system-images;android-28;google_apis;x86_64 + MAESTRO_EXAMPLE: test-value steps: - name: Enable KVM group perms diff --git a/e2e/workspaces/no-app/README.md b/e2e/workspaces/no-app/README.md new file mode 100644 index 0000000000..11acb76261 --- /dev/null +++ b/e2e/workspaces/no-app/README.md @@ -0,0 +1,5 @@ +# No App + +For tests that don't require an app to be launched. + +Tests of JavaScript or environment variables can be run here. \ No newline at end of file diff --git a/e2e/workspaces/no-app/environment-variables.yaml b/e2e/workspaces/no-app/environment-variables.yaml new file mode 100644 index 0000000000..1dc9821c97 --- /dev/null +++ b/e2e/workspaces/no-app/environment-variables.yaml @@ -0,0 +1,6 @@ +appId: com.example.notused +tags: + - passing +--- +# Relies on MAESTRO_EXAMPLE being set in the environment +- assertTrue: ${MAESTRO_EXAMPLE == 'test-value'} \ No newline at end of file diff --git a/maestro-cli/src/main/java/maestro/cli/runner/TestSuiteInteractor.kt b/maestro-cli/src/main/java/maestro/cli/runner/TestSuiteInteractor.kt index 4592e12bba..b2c8f8fce1 100644 --- a/maestro-cli/src/main/java/maestro/cli/runner/TestSuiteInteractor.kt +++ b/maestro-cli/src/main/java/maestro/cli/runner/TestSuiteInteractor.kt @@ -88,7 +88,11 @@ class TestSuiteInteractor( // proceed to run all other Flows executionPlan.flowsToRun.forEach { flow -> - val (result, aiOutput) = runFlow(flow.toFile(), env, maestro, debugOutputPath) + val flowFile = flow.toFile() + val updatedEnv = env + .withInjectedShellEnvVars() + .withDefaultEnvVars(flowFile) + val (result, aiOutput) = runFlow(flowFile, updatedEnv, maestro, debugOutputPath) aiOutputs.add(aiOutput) if (result.status == FlowStatus.ERROR) {