cypress-io/cypress

Cypress.require() works only if give absolute path

neerajlad opened this issue · 1 comments

Current behavior

I have two app which open using Okta and then it navigate to actual url . What I am currently facing is that I am using Cypress.require() method with absolute path and it works well but when I change to relative then its shows error as

Cannot find module '../XXX/xxx/xx/pageObjects/XXXPage.js'

Desired behavior

cypress.require() should access relative path

Test code to reproduce

Not working code:

When("I see the XX button", () => {
  cy.origin(xUrl, () => {
    const LoginPage1 = Cypress.require("../XXX/xxx/xx/pageObjects/XXXPage.js");
    const xPageInstance = new XPage1();
    xPageInstance .isXButtonExists();
  });
});

Working code

When("I see the XX button", () => {
  cy.origin(xUrl, () => {
    const LoginPage1 = Cypress.require("C:/user/XXX/xxx/xx/pageObjects/XXXPage.js");
    const xPageInstance = new XPage1();
    xPageInstance .isXButtonExists();
  });
});
module.exports = defineConfig({
  video: false,
  viewportWidth: 1920,
  viewportHeight: 1080,
  e2e: {
    experimentalOriginDependencies: true,
    defaultCommandTimeout: 10000,
    baseUrl:
      "https://XXXXX.com",
    specPattern: "**/*.feature",
    excludeSpecPattern: "*.js",
    setupNodeEvents,
  },
});

Cypress Version

v13.6.6

Node version

Bundled Node version: 18.17.1 & npm version : 10.4.0

Operating System

Windows 10 Enterprise - build version 19045.4046

Debug Logs

at Context.eval (webpack://XXX.cypress-tests/./cypress/e2e/steps/loginSteps.js:27)
    at Registry.runStepDefininition (webpack://XXX.cypress-tests/./node_modules/@badeball/cypress-cucumber-preprocessor/dist/registry.js:160)
    at Object.fn (webpack://XXX.cypress-tests/./node_modules/@badeball/cypress-cucumber-preprocessor/dist/browser-runtime.js:442)
    at runStepWithLogGroup (webpack://XXX.cypress-tests/./node_modules/@badeball/cypress-cucumber-preprocessor/dist/helpers/cypress.js:51)
    at Context.eval (webpack://XXX.cypress-tests/./node_modules/@badeball/cypress-cucumber-preprocessor/dist/browser-runtime.js:438)
From previous event:
    at Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (https://XXX.okta.com/__cypress/runner/cypress_runner.js:3486:19)
    at Promise._then (https://XXX.okta.com/__cypress/runner/cypress_runner.js:1239:17)
    at Promise._passThrough (https://XXX.okta.com/__cypress/runner/cypress_runner.js:4110:17)
    at Promise.lastly.Promise.finally (https://XXX.okta.com/__cypress/runner/cypress_runner.js:4119:17)
    at Object.onRunnableRun (https://XXX.okta.com/__cypress/runner/cypress_runner.js:163045:53)
    at $Cypress.action (https://XXX.okta.com/__cypress/runner/cypress_runner.js:41042:28)
    at Runnable.run (https://XXX.okta.com/__cypress/runner/cypress_runner.js:145633:13)
    at next (https://XXX.okta.com/__cypress/runner/cypress_runner.js:155418:10)
    at <unknown> (https://XXX.okta.com/__cypress/runner/cypress_runner.js:155462:5)
    at timeslice (https://XXX.okta.com/__cypress/runner/cypress_runner.js:145973:27)

Other

Value seen as XXX or XX is replaced with actual value

We have examples in our tests of using a relative path, so this should work. We'll need some way to reproduce it since this is likely influenced by some other component in your test suite.

Screenshot 2024-03-12 at 3 36 09 PM

https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/e2e/e2e/origin/cookie_misc.cy.ts