diff --git a/lib/helper/extras/Popup.js b/lib/helper/extras/Popup.js index 1253189db..1cf5f5986 100644 --- a/lib/helper/extras/Popup.js +++ b/lib/helper/extras/Popup.js @@ -2,66 +2,66 @@ * Class to handle the interaction with the Dialog (Popup) Class from Puppeteer */ class Popup { - constructor(popup, defaultAction) { - this._popup = popup || null; - this._actionType = ''; - this._defaultAction = defaultAction || ''; + constructor(popup = null, defaultAction = '') { + this._popup = popup + this._actionType = '' + this._defaultAction = defaultAction } _assertValidActionType(action) { if (['accept', 'cancel'].indexOf(action) === -1) { - throw new Error('Invalid Popup action type. Only "accept" or "cancel" actions are accepted'); + throw new Error('Invalid Popup action type. Only "accept" or "cancel" actions are accepted') } } set defaultAction(action) { - this._assertValidActionType(action); - this._defaultAction = action; + this._assertValidActionType(action) + this._defaultAction = action } get defaultAction() { - return this._defaultAction; + return this._defaultAction } get popup() { - return this._popup; + return this._popup } set popup(popup) { if (this._popup) { - console.error('Popup already exists and was not closed. Popups must always be closed by calling either I.acceptPopup() or I.cancelPopup()'); + return } - this._popup = popup; + this._popup = popup } get actionType() { - return this._actionType; + return this._actionType } set actionType(action) { - this._assertValidActionType(action); - this._actionType = action; + this._assertValidActionType(action) + this._actionType = action } clear() { - this._popup = null; - this._actionType = ''; + this._popup = null + this._actionType = '' } assertPopupVisible() { if (!this._popup) { - throw new Error('There is no Popup visible'); + throw new Error('There is no Popup visible') } } assertPopupActionType(type) { - this.assertPopupVisible(); - const expectedAction = this._actionType || this._defaultAction; + this.assertPopupVisible() + const expectedAction = this._actionType || this._defaultAction if (expectedAction !== type) { - throw new Error(`Popup action does not fit the expected action type. Expected popup action to be '${expectedAction}' not '${type}`); + throw new Error(`Popup action does not fit the expected action type. Expected popup action to be '${expectedAction}' not '${type}`) } - this.clear(); + this.clear() } } -module.exports = Popup; +module.exports = Popup