dimanche 17 mai 2020

sendKeys function sends undefined before string

I am trying to test some features in my ionic app using protractor one of my test cases trying to simulate input from an external barcode reader which actually sends the serial and enter key after it and this how I handle the event in my code :

      private _turnExternalBarcodeScannerOn (): Promise<string> {
    return new  Promise((resolve, reject) => {
      let _serial:string;
      this._externalBarcodeSubscriber = fromEvent(document, 'keypress').subscribe((event: any) => {
        console.log('#DEBUG EVENT FROM ADD EVENT', event)
        event.preventDefault();
        if (event.key !== 'Enter') _serial += event.key;
        else {
          resolve(_serial);
          console.log('#DEBUG Serial from external reader', _serial)
          this._unsubKeyboardEntry();
        }
      }, e => reject(e));
    });

It works fine with the actual reader. but in my test case, I am trying to send the serial using browser.actions().sendKeys() function.

      await browser.actions().sendKeys('049AC45A816580').perform();
      await browser.actions().sendKeys(protractor.Key.ENTER).perform();

Expected

What I expect here is this log returns the serial that I had been sent in the test case

console.log('#DEBUG Serial from external reader', _serial)

behavior

The output of this log becomes like this:

#DEBUG Serial from external reader undefined049AC45A816580

That means sendKeys actually adding undefined to my string very weird !!!!

Aucun commentaire:

Enregistrer un commentaire