无法找到 ‘cypress-xpath’ 的类型定义文件。ts(2688)

huangapple go评论57阅读模式
英文:

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(&#39;@cypress/xpath&#39;);
import &#39;./commands&#39;

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

/// &lt;reference types=&quot;cypress&quot; /&gt;
/// &lt;reference types=&quot;cypress-xpath&quot; /&gt;

describe(&quot;Test Contact Us form via Automation Test Store&quot;, () =&gt; {
    it(&quot;Should be able to submit a successful submission via contact us form&quot;, () =&gt; {
      cy.visit(&quot;https://www.automationteststore.com/&quot;);
      //cy.get(&#39;.info_links_footer &gt; :nth-child(5) &gt; a&#39;).click();
      cy.get(&#39;#ContactUsFrm_first_name&#39;).type(&quot;Joe&quot;);
      cy.get(&#39;#ContactUsFrm_email&#39;).type(&quot;test@gmail.com&quot;);
      cy.get(&#39;#ContactUsFrm_enquiry&#39;).type(&quot;Test&quot;);
      cy.get(&#39;.col-md-6 &gt; .btn&#39;).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(&quot;cypress&quot;);

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

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

以下是翻译好的内容:

类型引用行 /// &lt;reference types=&quot;cypress-xpath&quot; /&gt; 看起来像是旧的(已弃用)包。

集成的包包括一个类型定义文件 index.d.ts,应该可以通过以下方式访问:

/// &lt;reference types=&quot;@cypress/xpath&quot; /&gt;

因为 package.json 中有键 &quot;types&quot;: &quot;src&quot;,而 index.d.ts 就在该文件夹中。

英文:

The type reference line /// &lt;reference types=&quot;cypress-xpath&quot; /&gt; looks like the old (deprecated) package.

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

/// &lt;reference types=&quot;@cypress/xpath&quot; /&gt;

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

huangapple
  • 本文由 发表于 2023年2月23日 23:02:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定