【发布时间】:2023-02-24 04:23:53
【问题描述】:
我在 Visual Studio Code 上使用通过 npm 安装的 cypress。我最近通过 npm 安装了一个依赖项以在我的测试套件中使用 x-paths,并在我的支持文件 (e2e.js) 中包含了必要的代码。当在我的文件中包含允许我使用“cy.xpath”命令的引用时,我不确定构建路径是否正确构建。赛普拉斯本身正在运行,但 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}"
},
});
我在这里尝试了一些答案,并尝试了可能解决问题的各种终端命令,但没有任何效果。我不确定如何解决这个问题,如有任何帮助,我们将不胜感激。
【问题讨论】:
标签: javascript xpath automated-tests cypress