0

I understand that we can initiate keypress events like Backspace or ENTER in protractor with the help of protractor.Key.BACK_SPACE or ENTER. But , how do i do this action multiple times? Is it just adding another line of it or any good approach towards it?

Coolbreeze
  • 906
  • 2
  • 15
  • 34
  • 1
    Please check this answers: https://stackoverflow.com/questions/41393237/how-to-click-the-same-button-more-than-50-times-in-protractor – Yuriy Gerasimovich Dec 19 '19 at 13:13
  • 1
    Does this answer your question? [How to click the same button more than 50 times in protractor?](https://stackoverflow.com/questions/41393237/how-to-click-the-same-button-more-than-50-times-in-protractor) – Uladz Kha Dec 19 '19 at 13:28

1 Answers1

1

We have written a common functions to do the same.

exports.commonfunc = {
      pressKey: function(key) {
        switch (key) {
          case 'Enter':
            browser.actions().sendKeys(protractor.Key.ENTER).perform();
            break;
          case 'Backspace':
            browser.actions().sendKeys(protractor.Key.BACK_SPACE).perform();
            break;
        }
      },
      pressKeyNtimes: function(key, n) {
        for (i = 1; i <= n; i++) {
          this.pressKey(key);
        }
      }
}

Now we using commonfunc in another class as below :

exports.Login = {
 commonfunc: Object.create(require('../common/commonfunctions.js').commonfunc),

 iClickEnterTwice: function(){
  this.commonfunc.pressKeyNtimes('Enter',2);
 }
}

Hope this helps!

dheeraj
  • 324
  • 1
  • 9