Skip to content

Conversation

@DavertMik
Copy link
Contributor

@DavertMik DavertMik commented Dec 16, 2025

This PR adds support for using JSON strings as locators in CodeceptJS. When a string starts with { and ends with }, it will be parsed as JSON and transformed into a locator object.

Changes Made

  1. Enhanced Locator Class (lib/locator.js)
  • Added parsedJsonAsString() method to handle JSON string parsing
  • Supports simple key-value pairs as requested
  • Falls back gracefully to normal string processing for invalid JSON
  • Marks parsed locators as strict
  1. Comprehensive Test Coverage (test/unit/locator_test.js)
  • Added 12 test cases for JSON string parsing
  • Tests cover various locator types: CSS, XPath, ID, custom locators
  • Includes edge cases: whitespace, invalid JSON, aria-style locators
  • Verifies equivalence between object and JSON string formats

Usage Examples

  // These are now equivalent:
  I.seeElement({ css: '#button' })
  I.seeElement('{"css": "#button"}')

  // Aria-style locators 
  I.seeElement('{"role": "button", "text": "Save"}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants