Search code examples
javascriptxpathautomated-testscypresscypress-xpath

Cannot find type definition file for 'cypress-xpath'.ts(2688)


I am using cypress installed via npm on Visual Studio Code. I recently installed a dependency to use x-paths in my testing suite via npm, as well as included the necessary code in my support file (e2e.js). When including the reference in my file that would allow me to use 'cy.xpath' commands, I am unsure if the build path is being built correctly. Cypress itself is working, but the xpath command seems to be the issue.

Upon visting npm's website it was listed as deprecated, however I tried running the command npm i -D @types/cypress@latest, which installed correctly but this did not solve the issue. In my e2e.js config file this is what I have written:

require('@cypress/xpath');
import './commands'

On the file that I am trying to reference cypress-xpath this is what I have:

/// <reference types="cypress" />
/// <reference types="cypress-xpath" />

describe("Test Contact Us form via Automation Test Store", () => {
    it("Should be able to submit a successful submission via contact us form", () => {
      cy.visit("https://www.automationteststore.com/");
      //cy.get('.info_links_footer > :nth-child(5) > a').click();
      cy.get('#ContactUsFrm_first_name').type("Joe");
      cy.get('#ContactUsFrm_email').type("[email protected]");
      cy.get('#ContactUsFrm_enquiry').type("Test");
      cy.get('.col-md-6 > .btn').click();
    })
})

VS Code recognizes cy.xpath however it does not resolve the dependency issue above.

Below is the cypress.config.js file:

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
    specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx,feature}"
  },
});

I have tried some of the answers on here and tried various terminal commands that would potentially solve the problem, but nothing has worked. I am not sure how to move forward with this issue, and any help would be greatly appreciated.


Solution

  • The type reference line /// <reference types="cypress-xpath" /> looks like the old (deprecated) package.

    The integrated package includes a type definition file index.d.ts which should be accessible using

    /// <reference types="@cypress/xpath" />
    

    since the package.json has key "types": "src" and the index.d.ts is in that folder.