Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dry-run mode: Using of custom locator with "$" prefix in page object may cause Error: Lexical error on line 1. Unrecognized text #3657

Closed
mirao opened this issue May 10, 2023 · 4 comments · Fixed by #3940

Comments

@mirao
Copy link
Contributor

mirao commented May 10, 2023

What are you trying to achieve?

dry-run mode should pass

What do you get instead?

Provide console output if related. Use --verbose mode for more details.

$ npx codeceptjs dry-run
Tests from /home/mirao/tmp:

Error: Could not include object coursePage from module '/home/mirao/tmp/pages/Course.ts'
Lexical error on line 1. Unrecognized text.
$COURSE
^
Error: Lexical error on line 1. Unrecognized text.
$COURSE
^
    at Parser.parseError (/home/mirao/tmp/node_modules/bo-selector/parser.js:204:15)
    at Object.parseError (/home/mirao/tmp/node_modules/bo-selector/parser.js:345:28)
    at Object.next (/home/mirao/tmp/node_modules/bo-selector/parser.js:599:25)
    at Object.lex (/home/mirao/tmp/node_modules/bo-selector/parser.js:609:22)
    at lex (/home/mirao/tmp/node_modules/bo-selector/parser.js:232:28)
    at Parser.parse (/home/mirao/tmp/node_modules/bo-selector/parser.js:245:26)
    at parse (/home/mirao/tmp/node_modules/css-to-xpath/js/css_to_xpath.js:12:23)
    at convertToXpath (/home/mirao/tmp/node_modules/css-to-xpath/js/css_to_xpath.js:15:16)
    at Locator.toXPath (/home/mirao/tmp/node_modules/codeceptjs/lib/locator.js:165:30)
    at Locator.find (/home/mirao/tmp/node_modules/codeceptjs/lib/locator.js:188:42)
    at loadSupportObject (/home/mirao/tmp/node_modules/codeceptjs/lib/container.js:385:11)
    at getSupportObject (/home/mirao/tmp/node_modules/codeceptjs/lib/container.js:302:12)
    at lazyLoad (/home/mirao/tmp/node_modules/codeceptjs/lib/container.js:212:18)
    at Object.get (/home/mirao/tmp/node_modules/codeceptjs/lib/container.js:260:24)
    at Object.<anonymous> (/home/mirao/tmp/My_test.ts:3:11)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (/home/mirao/tmp/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (/home/mirao/tmp/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1117:32)

Note that run mode works as expected (no lexical error)

Provide test source code if related

My_test.ts:

Feature('My');

const {I, coursePage} = inject();

Scenario('test something',  () => {
    I.seeElement(coursePage.schoolCourse);
});

Course.ts:

export = {
    schoolCourse: locate("$COURSE").find("a"),
}

Details

  • CodeceptJS version: 3.4.1
  • NodeJS Version: 18.15
  • Operating System: Ubuntu 22.04
  • Playwright 1.33
  • Configuration file:
import { setHeadlessWhen, setCommonPlugins } from "@codeceptjs/configure";
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

export const config: CodeceptJS.MainConfig = {
  tests: "./*_test.ts",
  output: "./output",
  helpers: {
    Playwright: {
      url: "http://localhost",
      show: true,
      browser: "chromium",
    },
  },
  include: {
    coursePage: "./pages/Course.ts",
  },
  plugins: {
    customLocator: {
      enabled: true,
      prefix: "$",
      attribute: "data-testid",
    },
  },
  name: "tmp",
};
@mirao
Copy link
Contributor Author

mirao commented May 10, 2023

1st workaround

Use another prefix instead of "$", e.g. "#"

Course.ts:

export = {
    schoolCourse: locate("#COURSE").find("a"),
}

config:

  plugins: {
    customLocator: {
      enabled: true,
      prefix: "#",
      attribute: "data-testid",
    },
  },

2nd workaround

Pass coursePage as a parameter into a callback in a scenario instead of global injection:
My_test.ts:

Feature('My');

const {I} = inject();

Scenario('test something',  ({coursePage}) => {
    I.seeElement(coursePage.schoolCourse);
});

In both cases dry-run mode works as expected:

$ npx codeceptjs dry-run
Tests from /home/mirao/tmp:

My -- /home/mirao/tmp/My_test.ts
  ☐ test something

  Total: 1 suites | 1 tests  

--- DRY MODE: No tests were executed ---

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Aug 21, 2023
@kobenguyent kobenguyent linked a pull request Oct 20, 2023 that will close this issue
5 tasks
@kobenguyent
Copy link
Collaborator

By default, all plugins are disabled when running dry-run command, https://codecept.io/commands/#dry-run
so that's why you got this error.

You could try to enable the plugin like this:
npx codeceptjs dry-run --verbose -p customLocator

@mirao
Copy link
Contributor Author

mirao commented Oct 20, 2023

You could try to enable the plugin like this:
npx codeceptjs dry-run --verbose -p customLocator

Yes, it works. Tested with CodeceptJS 3.5.3

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 a pull request may close this issue.

2 participants