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

问题描述 投票:0回答:1

正在对此进行一些检查,以使我知道这是否是检查禁用复选框的正确方法。

这里是我的页面模型的一部分:

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
testing automation automated-tests e2e-testing testcafe
1个回答
0
投票

我在您的示例中看不到label定义。您可以尝试使用eligibleAccountType重写Selector构造函数:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.