Fix variable expansion in runFlow when conditions#10
Conversation
|
@gdealmeida1885, thank you for this! Really appreciate you taking the time to dig into the root cause, write proper tests, and verify on a real device. That's not a small effort. The three-layer fix makes a lot of sense — I'll review the diff carefully and get back to you soon. Great first contribution to the project 🙌 |
|
Thank you @omnarayan ! |
|
@gdealmeida1885 Hey, thanks for the PR — the bug is real and really appreciate you tracking it down. Had a few thoughts while going through the changes: 1.
We can't take these changes as-is — keeping that separation clean is important to us. One place expands, the other evaluates. 2. Test output in the description looks a bit different from ours The before/after output you shared — the nested steps are missing durations and there are inline comments like The actual raw output from your test run would be needed here — what's in the description right now doesn't match what we'd expect to see. 3. A thought on the selector pattern This one's just an observation, no action needed. Using A simpler pattern would be something like: - runFlow:
when:
visible:
id: "profile-button"
file: already-auth.yaml
Just something to keep in mind for your test flows. As things stand, points 1 and 2 are blockers for this PR. Thanks again for digging into this! |
|
Hey! Regarding n3, that was just a example of how I've come across this bug while using the maestro-runner and I wanted to explain how I saw it happening. :) |
That console output has nothing to do with maestro-runner. Do you actually have a test case designed that way, or is this just a hypothetical scenario? |
|
Hey @omnarayan, pushed changes addressing both blockers:
All tests pass with go test -race ./.... |
Before we move forward — is there an existing test case that follows this pattern, or is this more of a theoretical scenario? I ask because the approach seems closer to Appium's Page Object pattern than idiomatic Maestro. |
|
@omnarayan I think we're confusing things here a bit, perhaps because english is not my primary language. If that's the case I'm sorry, but I'll try to explain. :) The usage of What the PR fixes is the issue with As for the POO, this page object pattern I used here is something that is documented on Maestro docs and it's how I've decided to approach POO on my project as its supported by the framework. |
|
@gdealmeida1885 Thank you, There is conflict, if you can resolve it great else I ll do |
CheckCondition() was passing when condition selectors (visible/notVisible)
directly to the driver without expanding variables. Expressions like
${output.homeScreen.buttons.profile} were sent as literal strings,
causing conditions to always evaluate as false and silently skip
conditional blocks.
Three changes:
- CheckCondition(): expand variables in visible/notVisible selectors
and platform field before evaluating against the driver
- ExpandStep(): add RunFlowStep case to expand variables in File,
When condition fields, and Env values
- executeNestedStep(): call ExpandStep before executeRunFlow for
nested RunFlowStep execution
- TestExpandStep_RunFlowStep: verifies ExpandStep expands variables in File, When.Visible, When.NotVisible, When.Script, When.Platform, and Env map values - TestExpandStep_RunFlowStep_NilWhen: verifies nil When doesn't panic - TestCheckCondition_ExpandsVisibleSelectorVariables: verifies expanded selector ID reaches the driver - TestCheckCondition_ExpandsNotVisibleSelectorVariables: same for NotVisible text selector - TestCheckCondition_ExpandsPlatformVariable: verifies platform string expansion before comparison
Address PR review feedback: CheckCondition() should only evaluate conditions, not expand variables. ExpandStep() already handles all variable expansion before CheckCondition() is called, so the expansion in CheckCondition() was a redundant second pass. - Revert CheckCondition() to use condition fields directly - Remove CheckCondition expansion tests and mockConditionDriver - Keep ExpandStep RunFlowStep case (the actual fix)
16c6d17 to
20549b2
Compare
|
@omnarayan I've rebased this onto the latest main and fixed the changelog conflict. Should be good to merge now! |
omnarayan
left a comment
There was a problem hiding this comment.
Thank you for the PR! Good fix — correct root cause, clean implementation, solid tests.
Summary
runFlowsteps withwhenconditions that use variable expressions (e.g.,${BUTTON_ID}) were silently skipped because the variables were never expanded before evaluation. This caused conditional flows to behave as if no elements were found, effectively ignoring allwhenconditions.Problem
When a flow uses conditional
runFlowblocks with variable references inwhenconditions:The
${...}expressions were passed as literal strings to the driver, which could never find elements with those IDs. Both blocks were always skipped withSuccess: true/ "Skipped (when condition not met)" — so no test failure was reported.Root Cause
Two gaps in the variable expansion pipeline:
ExpandStep()inpkg/executor/scripting.go— Had no case for*flow.RunFlowStep, so the pre-execution expansion did nothing for RunFlowStep'sWhencondition selectors,Filepath, orEnvvalues.executeNestedStep()inpkg/executor/flow_runner.go— Did not callExpandStep()beforeexecuteRunFlow()for nested RunFlowStep execution (unlike other step types that get expanded).By the time
CheckCondition()evaluated theWhencondition, it received unexpanded${...}literals instead of resolved values.Fix
1. Add
RunFlowStepcase toExpandStep()Expand variables in
File,Whencondition fields (Visible,NotVisible,Script,Platform), andEnvmap values — consistent with how other step types are handled.2. Call
ExpandStep()for RunFlowStep inexecuteNestedStep()Ensures variables are expanded before
executeRunFlow()is called, soCheckCondition()receives already-expanded values. This maintains the clean separation:ExpandStep()expands,CheckCondition()evaluates.Files Changed
pkg/executor/scripting.goRunFlowStepcase toExpandStep()pkg/executor/flow_runner.goExpandStep()beforeexecuteRunFlow()in nested contextpkg/executor/scripting_test.goCHANGELOG.mdTests Added
TestScriptEngine_ExpandStep_RunFlowStep— verifies all RunFlowStep fields are expanded (File, When.Visible, When.NotVisible, When.Script, When.Platform, Env)TestScriptEngine_ExpandStep_RunFlowStep_NilWhen— nil When condition doesn't panicVerification
All tests pass (
go test -race ./...— 15 packages, 0 failures).