我正在尝试测试 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/