Skip to content

Compare Strings

Summary

  • Internal name: CompareStrings
  • Category: Tools
  • Purpose: Compare two string values using a configurable comparison operator and return a boolean result.
  • Task type: Conditional

Compatibility

  • Minimum AndroMate version: 1.1.0

  • Maximum AndroMate version: 1.1.0

  • Minimum Android: Android 13 (API 33)

  • Maximum Android tested: Android 16 (API 36)

  • Supported manufacturers:

    • ✅ Samsung (One UI 6.x / 7.x / 8.x)
    • ✅ Google Pixel (Android Stock)
    • ⚠️ Other manufacturers — not tested
  • Required permissions:

    • None

Detailed description

The Compare Strings task compares two string values (var_x and var_y) using a specified comparison operator. It returns true or false and routes execution to the corresponding branch in the workflow graph.

Both var_x and var_y support $workflow_variable references — they are resolved at runtime before the comparison is performed.


Comparison operators

The compare_type field determines how var_x is compared against var_y.

compare_type value Operator Description
"Equal" == var_x is exactly equal to var_y (case-sensitive)
"Equal ignore case" == (case-insensitive) var_x equals var_y, ignoring letter case
"Contains" contains var_x contains the substring var_y
"Start with" startsWith var_x starts with the prefix var_y

Input parameters

Parameter Type Required Possible values Android Compatibility AndroMate Compatibility Default
var_x String Yes Any string — supports $variable references Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 ""
var_y String Yes Any string — supports $variable references Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 ""
compare_type String Yes "Equal" / "Equal ignore case" / "Contains" / "Start with" Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 ""

Output parameters

This task is a conditional task — it produces no output variables. The boolean result controls the execution branch:

Result Condition Branch taken
true Comparison condition is satisfied "true" link
false Comparison condition is not satisfied "false" link

Exceptions

Code Exception Name Description
COMPARE-VAR-001 Unsupported Compare Type The value provided in compare_type does not match any supported operator. Accepted values: "Equal", "Equal ignore case", "Contains", "Start with".

Execution flowchart

The following diagram illustrates the actual implementation based on the Android code:

flowchart TD
    Start([Start CompareStrings]) --> ResolveX[🔄 Resolve var_x\nfrom workflow context]
    ResolveX --> ResolveY[🔄 Resolve var_y\nfrom workflow context]
    ResolveY --> ParseType{Parse compare_type}

    ParseType -->|"Equal"| EqualOp["var_x.equals(var_y)"]
    ParseType -->|"Equal ignore case"| IgnoreCaseOp["var_x.equalsIgnoreCase(var_y)"]
    ParseType -->|"Contains"| ContainsOp["var_x.contains(var_y)"]
    ParseType -->|"Start with"| StartWithOp["var_x.startsWith(var_y)"]
    ParseType -->|Unknown| E1[❌ COMPARE-VAR-001]

    EqualOp --> Result{boolean result}
    IgnoreCaseOp --> Result
    ContainsOp --> Result
    StartWithOp --> Result

    Result -->|true| True([✅ true → follow true branch])
    Result -->|false| False([✅ false → follow false branch])

    E1 --> Error([❌ Exception])

    style Start fill:#e3f2fd
    style True fill:#c8e6c9
    style False fill:#ffe0e0
    style Error fill:#ffcdd2
    style E1 fill:#ffcdd2
    style ResolveX fill:#fff9c4
    style ResolveY fill:#fff9c4
    style EqualOp fill:#f3e5f5
    style IgnoreCaseOp fill:#f3e5f5
    style ContainsOp fill:#f3e5f5
    style StartWithOp fill:#f3e5f5

How it works:

  1. Resolve operands: var_x and var_y are resolved from the workflow context (replacing $variable references)
  2. Parse operator: compare_type is matched against the supported string values
  3. Execute comparison: the appropriate Java String method is called
  4. Return result: true or false — the workflow engine routes to the corresponding branch

Code examples

Example 1 — Exact equality check

{
  "CompareStrings": [
    {
      "id": "1",
      "title": "Check status",
      "var_x": "$http_status",
      "var_y": "200",
      "compare_type": "Equal"
    }
  ]
}

Returns true if $http_status is exactly "200".


Example 2 — Case-insensitive check

{
  "CompareStrings": [
    {
      "id": "2",
      "title": "Check keyword (case-insensitive)",
      "var_x": "$response_body",
      "var_y": "success",
      "compare_type": "Equal ignore case"
    }
  ]
}

Returns true if $response_body equals "success" regardless of letter case.


Example 3 — Substring check

{
  "CompareStrings": [
    {
      "id": "3",
      "title": "Check for error keyword",
      "var_x": "$cmd_output",
      "var_y": "unreachable",
      "compare_type": "Contains"
    }
  ]
}

Returns true if $cmd_output contains the word "unreachable".


Example 4 — Prefix check

{
  "CompareStrings": [
    {
      "id": "4",
      "title": "Check prefix",
      "var_x": "$device_model",
      "var_y": "Samsung",
      "compare_type": "Start with"
    }
  ]
}

Returns true if $device_model starts with "Samsung".


Input parameter details

1. Input parameter: var_x

The left-hand string operand of the comparison. Supports $workflow_variable references — resolved at runtime before the comparison.

  • Default: "" (empty string)
  • Supports variables: Yes

2. Input parameter: var_y

The right-hand string operand of the comparison. Supports $workflow_variable references — resolved at runtime before the comparison.

  • Default: "" (empty string)
  • Supports variables: Yes

3. Input parameter: compare_type

Determines which string comparison method is applied. Must match one of the supported string values exactly (case-insensitive).

Value Java method Behaviour
"Equal" var_x.equals(var_y) Exact case-sensitive equality
"Equal ignore case" var_x.equalsIgnoreCase(var_y) Case-insensitive equality
"Contains" var_x.contains(var_y) var_x contains var_y as a substring
"Start with" var_x.startsWith(var_y) var_x starts with var_y
  • Default: "" — triggers COMPARE-VAR-001 if not set

Complete JSON example

{
  "CompareStrings": [
    {
      "id": "1",
      "title": "Check if response contains success",
      "var_x": "$response_body",
      "var_y": "success",
      "compare_type": "Contains"
    }
  ]
}