node.js - 使用 cypress.io 在 chrome 中测试 Node 应用程序

标签 node.js testing cypress

我正在尝试测试 this 的克隆带有柏树的 Node 应用程序。我对柏树只有非常基本的经验。

不幸的是, Node 应用程序的测试(通过 webpack 或通过 Node --inspect 启动)不起作用。我有

describe("Most basic test of adding a comments 2", function () {
  it("Adding one comment 2", function () {
    cy.pause();
    cy.visit("http://localhost:8080");
    cy.pause();
    cy.get(".comment").click();
    cy.pause();
    cy.get("div#viewer.pdfViewer").click(50, 300);

    cy.get("input#pdf-annotate-point-input").type("Testkommentar{enter}");
    cy.get("input#pdf-annotate-point-input").debug();
    expect(localStorage.getItem("example.pdf/pen/color")).to.be.not.null;
    expect(localStorage.getItem("exaxmple.pdf/annotations")).to.be.not.null;
  });
});

不幸的是,cypress 似乎无法控制 Chrome 浏览器。浏览器已启动并调用了 URL,但没有进一步的操作,特别是 pause() 命令不起作用。

有谁知道我是否必须设置一些特定的设置,因为这是一个 Node 应用程序?

最佳答案

在您的测试用例中,除非您在 cypress 命令之后添加它,否则您的“期望”代码将被更早执行,或者您可以像这样使用 promise 函数,

describe("Most basic test of adding a comments 2", function () {
    it("Adding one comment 2", function () {
      cy.pause();
      cy.visit("http://localhost:8080");
      cy.pause();
      cy.get(".comment").click();
      cy.pause();
      cy.get("div#viewer.pdfViewer").click(50, 300);

      cy.get("input#pdf-annotate-point-input").type("Testkommentar{enter}");
      cy.get("input#pdf-annotate-point-input").debug();
      //add following code after cypress command
      cy.wait(500).then(()=>{
        expect(localStorage.getItem("example.pdf/pen/color")).to.be.not.null;
        expect(localStorage.getItem("exaxmple.pdf/annotations")).to.be.not.null; 
      })
    });
  });

关于node.js - 使用 cypress.io 在 chrome 中测试 Node 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58032861/

相关文章:

javascript - NodeJS 和 ExpressJS Router.use() 错误

javascript - Node 中的请求模块的 POST 请求不起作用

javascript - 使用 Cheerio Node 查找选项中的特定值

javascript - Node.js 从带有参数的 Node CMD 调用函数

url - Cypress :如何检查按钮网址?

Cypress ,如何获得计数

使用测试工具调试 Forth

java - JUnit : When do I declare a TemporaryFolder object?

apache-flex - Flex UI 测试自动化

cypress - 根据 Cypress 请求设置 cookie 并返回用户