Skip to content

Locator build is failing on hyphen in css class names eg locate('a').find('.n-a') #3563

Closed
@nikocanvacom

Description

@nikocanvacom

What are you trying to achieve?

Use CodecepJS locate builder for managing of hierarchical elements as PageObject in a web testing framework for application with obfuscated(hashed) frontend class names where simplified code of subelement locator building could look like following:

locate('a').find('.n-a')

What do you get instead?

Exception on locate('a').find('.n-a')

-- FAILURES:

  1) Web test playground
       simple web test:
     Error: Parse error on line 1:
.n-a
--^
Expecting 'EOF', ',', 'S', '>', '.', '#', '[', ']', '=', 'CONTAINS', 'DOES_NOT_CONTAIN', 'CONTAINS_WORD', 'CONTAINS_PREFIX', 'STARTS_WITH', 'ENDS_WITH', '~', '+', ':', 'ODD_ARGUMENT', 'EVEN_ARGUMENT', '(', ')', got '-'
      at Parser.parseError (node_modules/bo-selector/parser.js:204:15)
      at Parser.parse (node_modules/bo-selector/parser.js:262:22)
      at parse (node_modules/css-to-xpath/js/css_to_xpath.js:12:23)
      at convertToXpath (node_modules/css-to-xpath/js/css_to_xpath.js:15:16)
      at Locator.toXPath (node_modules/codeceptjs/lib/locator.js:165:30)
      at convertToSubSelector (node_modules/codeceptjs/lib/locator.js:509:47)
      at Locator.find (node_modules/codeceptjs/lib/locator.js:188:53)
      at Test.<anonymous> (tests/example-web-test.ts:11:17)
      at Context.test.fn (node_modules/codeceptjs/lib/scenario.js:78:14)

or on locate('a').find('.n-6a')

-- FAILURES:

  1) Web test playground
       simple web test:
     Error: Parse error on line 1:
.n-6a
--^
Expecting 'EOF', ',', 'S', '>', '.', '#', '[', ']', '=', 'CONTAINS', 'DOES_NOT_CONTAIN', 'CONTAINS_WORD', 'CONTAINS_PREFIX', 'STARTS_WITH', 'ENDS_WITH', '~', '+', ':', 'ODD_ARGUMENT', 'EVEN_ARGUMENT', '(', ')', got 'NEGATIVE_INTEGER'
      at Parser.parseError (node_modules/bo-selector/parser.js:204:15)
      at Parser.parse (node_modules/bo-selector/parser.js:262:22)
      at parse (node_modules/css-to-xpath/js/css_to_xpath.js:12:23)
      at convertToXpath (node_modules/css-to-xpath/js/css_to_xpath.js:15:16)
      at Locator.toXPath (node_modules/codeceptjs/lib/locator.js:165:30)
      at convertToSubSelector (node_modules/codeceptjs/lib/locator.js:509:47)
      at Locator.find (node_modules/codeceptjs/lib/locator.js:188:53)
      at Test.<anonymous> (tests/example-web-test.ts:11:17)
      at Context.test.fn (node_modules/codeceptjs/lib/scenario.js:78:14)

Provide test source code if related

Feature('Web test playground');

Scenario('simple web test', async ({ I }) => {
    locate('a').find('.n-6a');
});

Details

  • CodeceptJS version: 3.3.7
  • NodeJS Version: 14.21.2
  • Operating System:
  • puppeteer || webdriverio || testcafe version (if related)
  • Configuration file:
require('ts-node/register')
const { setHeadlessWhen } = require('@codeceptjs/configure');
const { bootstrap } = require('./presettings.ts');

exports.config = {
  tests: './tests/**-web-test.ts',
  output: './output',
  helpers: {
    Playwright: {
      url: "http://localhost:9090/",
      restart: false,
      waitForNavigation: "networkidle0",
      waitForAction: 500
    }
  },
  bootstrap,
  name: 'c-csjs',
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions