小编Pau*_*ips的帖子

处理多个确认窗口 cypress

我的测试包含两个确认弹出窗口。第一个处理如下:

cy.on("window:confirm", str => {
    expect(str).to.equal(
    "Please confirm you would like to leave this space. You will no longer be a member of this space."
    );
    return true;
});
Run Code Online (Sandbox Code Playgroud)

因此,我正在测试确认对话框的文本,并通过返回 true 来单击确认。然后,我尝试对包含不同文本的第二个确认弹出窗口执行相同的操作,如下所示:

cy.on("window:confirm", str => {
    expect(str).to.equal(
    "This will archive the space and any content posted within it. Are you sure you wish to continue?"
    );
});
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,第一个弹出断言正确通过。第二个断言失败,因为它仍在寻找第一个断言中的字符串。所以看起来第一个 window:confirm 函数仍然被调用,尽管第二个应该被调用。

javascript confirm reactjs cypress

0
推荐指数
1
解决办法
201
查看次数

标签 统计

confirm ×1

cypress ×1

javascript ×1

reactjs ×1