英文:
Cannot find type definition file for 'cypress-xpath'.ts(2688)
问题
我使用通过npm在Visual Studio Code上安装的Cypress。最近,我通过npm安装了一个依赖项,以在我的测试套件中使用x-path,并在支持文件(e2e.js)中包含了必要的代码。在包含允许我使用'cy.xpath'命令的引用时,我不确定构建路径是否被正确构建。Cypress本身可以正常工作,但xpath命令似乎存在问题。
访问npm的网站时,它被列为不推荐使用,但我尝试运行npm i -D @types/cypress@latest
命令,安装成功,但这并没有解决问题。在我的e2e.js配置文件中,我写了以下内容:
require('@cypress/xpath');
import './commands';
在我尝试引用cypress-xpath的文件中,我有以下内容:
/// <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("test@gmail.com");
cy.get('#ContactUsFrm_enquiry').type("Test");
cy.get('.col-md-6 > .btn').click();
})
})
VS Code可以识别cy.xpath,但无法解决上面的依赖问题。
以下是cypress.config.js文件:
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 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("test@gmail.com");
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.
答案1
得分: 5
以下是翻译好的内容:
类型引用行 /// <reference types="cypress-xpath" />
看起来像是旧的(已弃用)包。
集成的包包括一个类型定义文件 index.d.ts
,应该可以通过以下方式访问:
/// <reference types="@cypress/xpath" />
因为 package.json
中有键 "types": "src"
,而 index.d.ts
就在该文件夹中。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论