Class TagSelector

java.lang.Object
io.karatelabs.core.TagSelector

public class TagSelector extends Object
Advanced tag selector supporting V1-compatible expressions.

Supports:

  • anyOf('@foo', '@bar') - match if any tag present
  • allOf('@foo', '@bar') - match if all tags present
  • not('@tag') - exclude tag
  • valuesFor('@tag').isPresent - check if tag has values
  • valuesFor('@tag').isAnyOf(1, 2) - check if any value matches
  • valuesFor('@tag').isAllOf(1, 2) - check if all values present
  • valuesFor('@tag').isOnly(1, 2) - exact value match
  • valuesFor('@tag').isEach(fn) - predicate on values
  • Compound expressions: anyOf('@foo') invalid input: '&'invalid input: '&' !anyOf('@ignore')
  • Constructor Details

  • Method Details

    • evaluate

      public boolean evaluate(String tagSelector, String karateEnv)
      Evaluate a tag selector expression against this set of tags.
      Parameters:
      tagSelector - the selector expression (e.g., "anyOf('@foo') invalid input: '&'invalid input: '&' not('@ignore')")
      karateEnv - the current karate.env value (may be null)
      Returns:
      true if the tags match the selector
    • anyOf

      public boolean anyOf(Object... values)
    • allOf

      public boolean allOf(Object... values)
    • not

      public boolean not(Object... values)
    • valuesFor

      public TagSelector.Values valuesFor(String name)
    • contains

      public boolean contains(String tagText)
    • getTagTexts

      public List<String> getTagTexts()
    • getTagValues

      public Map<String,List<String>> getTagValues()
    • fromKarateOptionsTags

      public static String fromKarateOptionsTags(List<String> tags)
      Convert Karate/Cucumber-style tag expressions to JS-style tag selector.

      Examples:

      • "@foo" → "anyOf('@foo')"
      • "@foo, @bar" → "anyOf('@foo','@bar')"
      • "@foo", "@bar" (multiple args) → "anyOf('@foo') invalid input: '&'invalid input: '&' anyOf('@bar')"
      • "~@ignore" → "not('@ignore')"
      • "anyOf('@foo')" (already JS-style) → "anyOf('@foo')"
      Parameters:
      tags - the tag expressions
      Returns:
      the JS-style tag selector, or null if no tags
    • fromKarateOptionsTags

      public static String fromKarateOptionsTags(String... tags)
      Convert Karate/Cucumber-style tag expressions to JS-style tag selector.
      Parameters:
      tags - the tag expressions
      Returns:
      the JS-style tag selector, or null if no tags
    • toString

      public String toString()
      Overrides:
      toString in class Object