You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the command’s error handling and asynchronous flow rely on callbacks. Refactoring the performAction method to use async/await can simplify the logic and provide more consistent promise-based error handling. This update would both improve readability and make it easier to maintain.
Suggested solution
// Wrap the callback-based transport action in a promise
class EnablePerformanceMetrics extends ClientCommand {
async performAction() {
if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('The command .enablePerformanceMetrics() is only supported in Chrome and Edge drivers');
Logger.error(error);
throw error;
}
const { enable = true } = this;
return new Promise((resolve, reject) => {
this.transportActions.enablePerformanceMetrics(enable, (err, result) => {
if (err) {
return reject(err);
}
resolve(result);
});
});
}
async command(enable) {
this.enable = enable;
// Assuming super.command now returns a promise
return await super.command();
}
}
module.exports = EnablePerformanceMetrics;
Alternatives / Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered:
Hey @imramkrishna,
I think this should be implemented across the entire repository rather than just for lib/api/client-commands/enablePerformanceMetrics.js
Description
File: lib/api/client-commands/enablePerformanceMetrics.js
Currently, the command’s error handling and asynchronous flow rely on callbacks. Refactoring the performAction method to use async/await can simplify the logic and provide more consistent promise-based error handling. This update would both improve readability and make it easier to maintain.
Suggested solution
class EnablePerformanceMetrics extends ClientCommand {
async performAction() {
if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('The command .enablePerformanceMetrics() is only supported in Chrome and Edge drivers');
Logger.error(error);
throw error;
}
const { enable = true } = this;
return new Promise((resolve, reject) => {
this.transportActions.enablePerformanceMetrics(enable, (err, result) => {
if (err) {
return reject(err);
}
resolve(result);
});
});
}
async command(enable) {
this.enable = enable;
// Assuming super.command now returns a promise
return await super.command();
}
}
module.exports = EnablePerformanceMetrics;
Alternatives / Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: