Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: Cannot read property 'keyPad' of undefined

I am having issue with this undefined error message: TypeError: Cannot read property 'keyPad' of undefined

I’m not sure how to resolve this error. What am I doing incorrect that it’s unable to read the property? Error is in the method below

class logout extends BasePage {

  constructor() {
    super();
    this.inputField = Selector(
      '.form-input-field'
    );
  }
        

   async logoutProcess() {
      await t
      .click(this.inputField)
      .expect(this.numberKeypad.keyPad.visible)
      .ok({ timeout: 2000 });
        
        await this.numberKeypad.type('100');
        
        ...
    
      }
    
    }

I have the basePage:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export class BasePage {
  numberKeyPad: NumberKeypadModel;
  constructor() {
    this.numberKeyPad = new NumberKeypadModel();
  }
}

Finally I have the NumberKeypadModel page with the type method I’m trying to call on:

export class NumberKeypadModel {
  keyPad: Selector;
  constructor() {
    this.keyPad = Selector('.keypad').with({ timeout: 500 });
  }

  async type(num: string) {
    for (const char of [...num]) {
      await t.click(
        XPathSelector(
          `//div[@data-testid="keypad"]/button[.='${char}']`
        )
      );
      console.log(char);
    }
  }
}

>Solution :

Capitalization difference:

In your class it’s numberKeyPad:

this.numberKeyPad = new NumberKeypadModel();

But then you attempt to access numberKeypad:

.expect(this.numberKeypad.keyPad.visible)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading