|
| 1 | +--- |
| 2 | +description: Assert that two values are not equal in Maestro flows. |
| 3 | +--- |
| 4 | + |
| 5 | +# assertNotEqual |
| 6 | + |
| 7 | +Asserts that two values are not equal after JavaScript evaluation: |
| 8 | + |
| 9 | +```yaml |
| 10 | +- assertNotEqual: |
| 11 | + value1: "foo" |
| 12 | + value2: "bar" |
| 13 | +``` |
| 14 | +
|
| 15 | +This command compares `value1` and `value2` as strings after evaluating any JavaScript expressions. If the values are equal, the assertion fails. |
| 16 | + |
| 17 | +### Basic usage |
| 18 | + |
| 19 | +Ensure a value is not a specific string: |
| 20 | + |
| 21 | +```yaml |
| 22 | +- assertNotEqual: |
| 23 | + value1: ${output.status} |
| 24 | + value2: "error" |
| 25 | +``` |
| 26 | + |
| 27 | +Verify UI text has changed: |
| 28 | + |
| 29 | +```yaml |
| 30 | +- copyTextFrom: |
| 31 | + id: "counter" |
| 32 | +- evalScript: ${output.initialCount = maestro.copiedText} |
| 33 | +- tapOn: "Increment" |
| 34 | +- copyTextFrom: |
| 35 | + id: "counter" |
| 36 | +- assertNotEqual: |
| 37 | + value1: ${maestro.copiedText} |
| 38 | + value2: ${output.initialCount} |
| 39 | + label: "Counter should have changed" |
| 40 | +``` |
| 41 | + |
| 42 | +### With label and optional |
| 43 | + |
| 44 | +```yaml |
| 45 | +- assertNotEqual: |
| 46 | + value1: ${output.userId} |
| 47 | + value2: "" |
| 48 | + label: "User ID should not be empty" |
| 49 | + optional: true |
| 50 | +``` |
| 51 | + |
| 52 | +### Use in conditions |
| 53 | + |
| 54 | +`assertNotEqual` can be used in `runFlow` and `repeat` conditions: |
| 55 | + |
| 56 | +```yaml |
| 57 | +- runFlow: |
| 58 | + when: |
| 59 | + notEqual: |
| 60 | + value1: ${output.status} |
| 61 | + value2: "disabled" |
| 62 | + commands: |
| 63 | + - tapOn: "Submit" |
| 64 | +``` |
| 65 | + |
| 66 | +```yaml |
| 67 | +- repeat: |
| 68 | + while: |
| 69 | + notEqual: |
| 70 | + value1: ${output.loading} |
| 71 | + value2: "false" |
| 72 | + commands: |
| 73 | + - waitForAnimationToEnd |
| 74 | +``` |
| 75 | + |
| 76 | +### Considerations |
| 77 | + |
| 78 | +`assertNotEqual` compares values as strings after JavaScript evaluation: |
| 79 | + |
| 80 | +- **Numbers are normalized**: `${1}` and `${1.0}` both evaluate to `"1"` and will match |
| 81 | +- **Booleans become strings**: `${true}` evaluates to `"true"` |
| 82 | + |
| 83 | +This means `${true}` and `${1}` are not considered equal — they evaluate to `"true"` and `"1"` respectively. If you need JavaScript type coercion (where `1 == true`), use `assertTrue`: |
| 84 | + |
| 85 | +```yaml |
| 86 | +- assertTrue: ${1 == true} |
| 87 | +``` |
| 88 | + |
| 89 | +### Related commands |
| 90 | + |
| 91 | +{% content-ref url="assertequal.md" %} |
| 92 | +[assertequal.md](assertequal.md) |
| 93 | +{% endcontent-ref %} |
| 94 | + |
| 95 | +{% content-ref url="asserttrue.md" %} |
| 96 | +[asserttrue.md](asserttrue.md) |
| 97 | +{% endcontent-ref %} |
| 98 | + |
| 99 | +{% content-ref url="assertnotvisible.md" %} |
| 100 | +[assertnotvisible.md](assertnotvisible.md) |
| 101 | +{% endcontent-ref %} |
0 commit comments