我试图用它cy.log来帮助我理解测试失败的原因。不幸的是,我似乎无法让它记录我想要的消息。经过一番摆弄后,我进行了这个测试:
describe.only("In what order are these messages printed?", () => {
it("I would expect the LOG to be printed before the EXPECT", () => {
cy.log("Hello from cy.log");
expect(1 + 1).to.equal(2);
});
});
Run Code Online (Sandbox Code Playgroud)
我希望“Hello”首先出现,但我得到的是:
此外,在一次失败的测试中,cy.log似乎根本没有出现,这对我来说是不幸的。同样,这是一个简单但极端的例子。
describe.only("Here is my real problem", () => {
it("I would expect the LOG to be printed before the test fails", () => {
cy.log("Hello from cy.log");
expect(2 + 2).to.equal(42);
});
});
Run Code Online (Sandbox Code Playgroud)
这会产生这样的结果:
如果是这样,我可以求助于console.log. 尽管遗憾的是我们无法在 Cypress 主窗口本身中整齐地报告日志。
或者我是否不小心设置了一个扰乱时间的设置cy.log …
下面是一个递减的循环。我该如何重写以计1为100:
for (var i =100; i > 0; i--) {
console.log(from 1 to 100);
}
Run Code Online (Sandbox Code Playgroud)