javascript - 如何一个接一个地多次运行柏树测试?
问题描述
我正在使用反应创建垄断(用骰子玩的棋盘游戏)。我已经为游戏制作了滚动系统。现在我想测试一下。
我的游戏中有两个按钮
- 滚动按钮:
- 它最初启用
- 当用户单击它时,骰子就会滚动。玩家动作片段
- 现在有两种情况
- 如果掷出双打,则玩家将获得另一轮掷骰,并且此按钮保持启用状态
- 如果双打没有滚动,这将被禁用,而另一个则被启用。
- 结束转弯按钮:
- 最初它被禁用。
- 如果掷骰子而未掷骰子,则启用该骰子。
- 当我们点击这个回合改变并且对于新的回合这将被禁用并且滚动按钮再次被启用。
现在我正在使用柏树来测试这个。我已经编写了测试,它运行良好,但只运行了 1 次。当我使用循环多次运行测试时,它失败了
describe("Rolling System", function () {
//The required test
it("disables button correctly", function () {
//Visits the page
cy.visit("localhost:3000").then(() => {
//A variable which tell if doubles were rolled at last roll or not
let isRollDisabled = false;
for (let i = 0; i < 10; i++) {
//If roll is over then end the turn
if (isRollDisabled) {
cy.get(".btn-end-turn").click();
}
//If roll button is enabled then click it.
else {
console.log(isRollDisabled);
//Get and click button
cy.get(".btn-roll")
.click()
.then((x) => {
//Get the dice elements
cy.get(".dice").then((dices) => {
//Get the rolls of both die
let roll1 = dices[0].children.length;
let roll2 = dices[1].children.length;
//If not doubles
if (roll1 !== roll2) {
cy.get(".btn-roll").should("be.disabled");
console.log("roll disabled changed");
isRollDisabled = true;
}
//If doubles are rolled
else {
cy.get(".btn-roll").should("not.be.disabled");
isRollDisabled = false;
}
});
});
}
}
});
});
});
注意上面代码中的两个日志console.log(isRollDisabled);
和console.log("roll disabled changed");
在日志中,我看到false
记录的10
时间,然后"roll disabled change"
记录。
我想我已经编写了代码,使得一个测试一个接一个地运行,但我无法修复它。
解决方案
从测试体内删除循环并从命令行使用cypress-repeat代替。
推荐阅读
- android-viewpager - 切换到首选项后,芯片导航栏无法使用
- reactjs - 为什么应用程序可以在本地主机上运行,但不能在 github 页面上运行?
- python - python-如何在函数中传递字典作为输入而不重复字典中的元素
- c# - 如何解压缩使用 DotNetZip 库创建的多部分 zip 文件?
- r - 在 dplyr 的过滤器中同时使用空和字符串过滤器
- applescript - 如何在不同位置创建两个新的 Safari 窗口?
- node.js - 我的 https:443 服务器也如何为 http:80 提供服务?
- asp.net-core - 如何在 asp.net 核心中创建基于模型的 REST API 端点?
- c++ - 用户界面编译器 Qt
- c# - 如何使用 C# 制作 3D 相机缩放