Skip to content

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

Open
rahulptl165 wants to merge 1 commit into
nightwatchjs:mainfrom
rahulptl165:fixes/#4365
Open

rahulptl165 wants to merge 1 commit into
nightwatchjs:mainfrom
rahulptl165:fixes/#4365

Conversation

@rahulptl165

@rahulptl165 rahulptl165 commented Feb 2, 2025

Copy link
Copy Markdown

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

CLAassistant commented Feb 2, 2025

Copy link
Copy Markdown

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