Reputation: 947
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?
Upvotes: 0
Views: 868
Reputation: 344
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!
Upvotes: 1