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

时间:2020-01-20 23:23:08

标签: testing automation automated-tests e2e-testing testcafe

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

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

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

2 个答案:

答案 0 :(得分:2)

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

const label = Selector('label');

答案 1 :(得分:1)

在您的示例中,没有看到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

更新

现在我看到我的列表实际上甚至还没有建立,并且出现此错误“ 1)TypeError:programOptionsSubscriptionRulesPage.eligibleAccountTypeList不可迭代”

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

for (const eligibleAccountType of programOptionsSubscriptionRulesPage.eligibleAccountTypeList) {

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