Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redundant popup log #4830

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions lib/helper/extras/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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