使用复选框 - 无法检查复选框是否被禁用

Working with checkboxes - unable to check if checkboxes are disabled

正在寻找对此的评论,让我知道这是否是检查禁用复选框的正确方法。

我的部分页面模型在这里:

class eligibleAccountType {
  constructor (text) {
      this.label    = label.withText(text);
      this.checkbox = this.label.find('input[type=checkbox]');
  }
}

class ProgramOptionsSubscriptionRulesPage{
    constructor(){
        this.contractsatAccountLevel = Selector("#program_option_allow_participant_account_contracts")
        this.eligibleAccountTypesList = [
          new eligibleAccountType("Residential"),
          new eligibleAccountType("Commercial"),
          new eligibleAccountType("Industrial")
      ];

这里是我测试的一部分

if (userdata.userrole == "Read Only") {
 
 for (const eligibleAccountType of programOptionsSubscriptionRulesPage.eligibleAccountTypeList) {
            await t.expect(eligibleAccountType.hasAttribute('disabled')).ok()
          }
        }

出现如下错误:

ReferenceError: label is not defined

我在您的示例中没有看到 label 定义。您可以尝试使用 Selector:

重写 eligibleAccountType 构造函数
class eligibleAccountType {
  constructor (text) {
      this.label    = Selector(...).withText(text);
      this.checkbox = Selector(...).find('input[type=checkbox]');
  }
}

在这种情况下,检查所需元素的标记可能会很有用。请参考 "TestCafe Examples" 存储库:https://github.com/DevExpress/testcafe-examples/blob/master/examples/element-properties/check-element-markup.js

更新:

and now I see that my list is actually not even building and I get this error " 1) TypeError: programOptionsSubscriptionRulesPage.eligibleAccountTypeList is not iterable"

您的循环中似乎有命名错误:

for (const eligibleAccountType of programOptionsSubscriptionRulesPage.eligibleAccountTypeList) {

根据您的 ProgramOptionsSubscriptionRulesPage class 定义,列表名称应为 eligibleAccountTypesList(带有 "s" 字符)。

我想我发现了问题,我没有定义

const label = Selector('label');