Class StepUtils

java.lang.Object
io.karatelabs.core.StepUtils

public class StepUtils extends Object
Static utility methods for step execution.
  • Method Details

    • parseFeaturePath

      public static StepUtils.ParsedFeaturePath parseFeaturePath(String rawPath)
      Parse a feature path into path and tag selector components. Supports: - file.feature@tag - call specific scenario by tag - @tag - call scenario in same file by tag - file.feature - normal call without tag
      Parameters:
      rawPath - the raw path string (may contain @tag suffix)
      Returns:
      ParsedFeaturePath with separated path and tag components
    • isValidVariableName

      public static boolean isValidVariableName(String name)
      Check if a string is a valid Karate variable name. Must start with letter or underscore, followed by letters, digits, or underscores.
    • findCallArgSeparator

      public static int findCallArgSeparator(String text)
      Find the separator between call target and arguments in a call expression. Handles quoted strings in read() calls, e.g., read('foo bar.js') arg
      Returns:
      index of separator space, or -1 if not found
    • isLiteralFeatureRead

      public static boolean isLiteralFeatureRead(String text)
      Check if text is a literal feature file read like read('file.feature').
    • deepCopy

      public static Object deepCopy(Object value)
      Deep copy a value (Map, List, or primitive).
    • getOrCreatePath

      public static Object getOrCreatePath(Map<String,Object> target, String path)
      Navigate to or create a nested path in a map structure. Creates intermediate maps as needed.
    • setValueAtPath

      public static void setValueAtPath(Object target, String path, Object value)
      Set a value at a nested path, handling both dot notation and array brackets.
    • removeAtPath

      public static void removeAtPath(Map<String,Object> map, String path)
      Remove a value at a nested path in a map.
    • findAssignmentOperator

      public static int findAssignmentOperator(String text)
      Find the first '=' that's an assignment operator (not ==, !=, invalid input: '<'=, >=).
      Parameters:
      text - the text to search
      Returns:
      index of '=' or -1 if not found
    • hasPunctuation

      public static boolean hasPunctuation(String s)
      Check if string contains JS expression punctuation like . ( [ ] ' "
      Parameters:
      s - the string to check
      Returns:
      true if contains punctuation
    • stringify

      public static String stringify(Object value)
      Convert a value to its string representation. - null -> "null" - String -> as-is - Map/List -> JSON - Node -> XML - Other -> toString()
      Parameters:
      value - the value to stringify
      Returns:
      string representation