https://cypress.io logo
Cypress.require used with cy.origin gives node err...
# i-need-help
r
How are you all ? Cypress version used - 12.9.0 I'm trying to do this in my cy.origin code of my CRM and getting below error - Can someone here suggest right usage? cy.origin('https://xxx-dynamics.com/', () => { const contactPage1 = Cypress.require('./ContactPage.js'); CypressError cy.origin() failed to run the callback function due to the following error: Processing the origin callback errored: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at new NodeError (node:internal/errors:399:5) at validateString (node:internal/validators:163:11) at Object.dirname (node:path:1276:5) Cypress documentation advises me to use like this - https://docs.cypress.io/api/commands/origin const utils = Cypress.require('../support/utils')
m
did you enable the following setting. experimentalOriginDependencies
b
Hey @red-jordan-59778 were you able to get this problem resolved? 😀
r
Hi Xavier, thanks for the response, yes i enabled this as far as i remember, i would check again and reply
these are my settings in cypress.config file - module.exports = defineConfig({ e2e: { setupNodeEvents, reporter: 'cypress-mochawesome-reporter', specPattern: "cypress/e2e/features/*", // chromeWebSecurity: false, video: true, defaultCommandTimeout: 10000, pageLoadTimeout: 90000, experimentalSessionAndOrigin: true, failOnStatusCode: false, storeAuthStateInCookie: true, experimentalModifyObstructiveThirdPartyCode: true, experimentalOriginDependencies: true, defaultCommandTimeout: 10000, env: { CRM: 'https://xxx.com' } }
So i think the above was covered 'experimentalOriginDependencies: true'
m
is your ./ContactPage.js' in the same folder as your test?
r
yes correct in same step_definitions folder, i will put snapshot of that too, but is your code working .. did you try, on 12.9.0 cypress
trying to use within cy.origin
anyways will try in 12.10.0 as well, latest
m
Yeah i have it working in 12.10.0 This is my class file.
Copy code
js
/// <reference types="cypress" />

export default class Heroku {

    fillDetails(){
        cy.get("#username").type("xavier")
        cy.get("#password").type("password")
    }

}
This is my cypress test
Copy code
js
/// <reference types="cypress" />

describe('template spec', () => {
  it('passes', () => {
    cy.visit('https://example.cypress.io')
    cy.origin("https://the-internet.herokuapp.com/login", ()=>{
      const MyPage = Cypress.require('./Heroku.js')
      const myPage = new MyPage();
      cy.visit('https://the-internet.herokuapp.com/login')
      myPage.fillDetails()
    })
  })
})
And this is my settings file
Copy code
js
const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    experimentalOriginDependencies: true,
    experimentalModifyObstructiveThirdPartyCode: true,
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
});

https://cdn.discordapp.com/attachments/1097773609730187374/1098899557393383474/image.pngâ–¾

@red-jordan-59778 please check if its similiar for you
Also it works on 12.9.0
r
Ok thank you very much for confirming, i would try this sure !
This is a node error by the way, can you please give me the node verion too, thanks
m
v16.16.0
r
Hi Xavier, I copied and pasted the above code, un-fortunately it didn't work to me and got same error , By the way i'm using LATEST node, could you upgrade Node JS to latest and try, maybe ther's a dependency You can see the below is Node error and i'm not sure if i missed any dependency in package.json I would be happy to jump into a call for 5-10 mins to replicate issue when ther's time-zone overlap with you The node in my MAC laptop is - "arun.balasubramanian@P9NPQGQQGX NCH-Dynamics-AutomationTest % node -v v18.15.0" visithttps://example.cypress.io 2 originhttps://the-internet.herokuapp.com/login CypressError cy.origin() failed to run the callback function due to the following error: Processing the origin callback errored: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at new NodeError (node:internal/errors:399:5) at validateString (node:internal/validators:163:11) at Object.dirname (node:path:1276:5) at Object.processCallback [as handler] (/Users/arun.balasubramanian/Library/Caches/Cypress/12.9.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/cross_origin.js:19:25)
my package.json file - { "name": "cypress-cucumber-TestProject", "version": "1.0", "description": "This project Cypress Test with Cucumber.", "main": "index.js", "scripts": { "cypress:runner": "cypress open --e2e --browser chrome", "cypress:execution": "cypress run --headed --browser chrome --spec cypress/e2e/firstTest.js", "test": "cypress run --headed --browser chrome --env tags=@sanity" }, "keywords": [ "cypress" ], "author": "cucumber", "license": "ISC", "devDependencies": { "@badeball/cypress-cucumber-preprocessor": "^16.0.3", "@bahmutov/cypress-esbuild-preprocessor": "^2.2.0", "cypress": "^12.9.0", "cypress-mochawesome-reporter": "^3.3.0" } }
It gave me same error in my personal Windows laptop as well, where node version is - C:\Users\arunb>node -v v18.14.2
m
I will try upgrading my nodejs
r
Let me know, thanks
m
Still working for me on lts v18.16.0
i will create a github repo so you can clone it
r
thanks a lot for this effort, i will clone and run it ..
9 Views