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

Refactored the performAction method to use async/await. #4366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rahulptl165
Copy link

@rahulptl165 rahulptl165 commented Feb 2, 2025

Fixes: #4365

Refactor performAction and command methods to use async/await.

This PR refactors the performAction and command methods in enablePerformanceMetrics.js to use async/await properly.

Changes Made:

Before :

performAction(callback) {

    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);

      return callback(error);
    }

    const {enable = true} = this;

    this.transportActions.enablePerformanceMetrics(enable, callback);
  }

  command(enable, callback) {
    this.enable = enable;

    return super.command(callback);
  }

After :

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){
          reject(err);
        } else {
          resolve(result);
        }
      });
    });
  }

  async command(enable) {
    this.enable = enable;

    return super.command();
  }

@CLAassistant
Copy link

CLAassistant commented Feb 2, 2025

CLA assistant check
All committers have signed the CLA.

@rahulptl165 rahulptl165 marked this pull request as ready for review February 2, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

command’s error handling and asynchronous flow rely on callbacks.
2 participants