首页 > 解决方案 > Testcafe - 单击按钮后如何获取更新状态值

问题描述

我是测试世界的新手。我正在使用 testcafe 进行自动化。我正在测试简单的计数器按钮。每当单击按钮时,计数器就会增加。现在我得到以前的值而不是更新值。

我将“超时”作为断言 api 中的选项传递

import { ReactSelector } from "testcafe-react-selectors";

export default class counterButton {
  constructor() {
    this.counterButton = ReactSelector("CardButton");
    this.button = this.counterButton.find("button");
  }

  async clickButton(t) {
    await t.click(this.button);
  }

  async checkingState(t) {
    const button = this.counterButton;
    const buttonReact = await button.getReact();
    await this.clickButton(t);
    await t.expect(buttonReact.state).eql(1,undefined,{timeout:50000});
  }
}

我没有以前的状态值,我想从状态中更新值。

标签: reactjstestingautomationui-automationtestcafe

解决方案


如果没有证明问题的工作示例,很难给出准确的答案。从代码中,我看到您首先获得了按钮状态,然后才单击按钮。我想您只需要在单击后获取按钮状态。


推荐阅读