Repository: oppia/oppia
File: core/tests/puppeteer-acceptance-tests/utilities/user/release-coordinator.ts (TypeScript)

Code before:
    });

    // OverridePermissions is used to allow clipboard access.
    const context = await this.browserObject.defaultBrowserContext();
    await context.overridePermissions('http://localhost:8181', [
      'clipboard-read',
      'clipboard-write',
    ]);
    const pages = await this.browserObject.pages();
    this.page = pages[pages.length - 1];

    // Getting the output text directly from the element.
    const output = await this.page.$eval(
      beamJobRunOutputSelector,
      el => el.textContent
    );

    await this.clickOnElementWithSelector(copyOutputButton);

    // Reading the clipboard data.
    const clipboardData = await this.page.evaluate(async () => {
      return await navigator.clipboard.readText();
    });

    if (clipboardData !== output) {
      throw new Error('Data was not copied correctly');
    }
    showMessage('Data was copied correctly');

    return output;
  }

  /**
   * Expects the output of a job to be a certain value.
   * @param {string} expectedOutput - The expected output of the job.
   */
  async expectJobOutputToBe(expectedOutput: string): Promise<void> {
    await this.expectTextContentToContain(
      beamJobRunOutputSelector,
      expectedOutput
    );
  }

  /**
   * Closes the output modal by clicking on "Close" button.
   */
  async closeOutputModal(): Promise<void> {
    await this.expectElementToBeVisible(beamJobCloseOuputButtonSelector);
    await this.page.click(beamJobCloseOuputButtonSelector);
    await this.expectElementToBeVisible(beamJobCloseOuputButtonSelector, false);
    showMessage('Output modal closed');

Review comment (bug):
Maybe here you can put the expected vs observed data in the error, so it's easier to debug in the future.

Code after:
    });

    // OverridePermissions is used to allow clipboard access.
    const context = await this.browserObject.defaultBrowserContext();
    await context.overridePermissions('http://localhost:8181', [
      'clipboard-read',
      'clipboard-write',
    ]);
    const pages = await this.browserObject.pages();
    this.page = pages[pages.length - 1];

    // Get the output text directly from the element.
    const output = await this.page.$eval(
      beamJobRunOutputSelector,
      el => el.textContent
    );

    await this.clickOnElementWithSelector(copyOutputButton);

    // Read the clipboard data.
    const clipboardData = await this.page.evaluate(async () => {
      return await navigator.clipboard.readText();
    });

    if (clipboardData !== output) {
      throw new Error(
        'Data was not copied correctly\n' +
          `Expected: "${output}"\n` +
          `Actual: "${clipboardData}"`
      );
    }
    showMessage('Data was copied correctly');

    return output;
  }

  /**
   * Expects the output of a job to be a certain value.
   * @param {string} expectedOutput - The expected output of the job.
   */
  async expectJobOutputToBe(expectedOutput: string): Promise<void> {
    await this.expectTextContentToContain(
      beamJobRunOutputSelector,
      expectedOutput
    );
  }

  /**
   * Closes the output modal by clicking on "Close" button.
   */
  async closeOutputModal(): Promise<void> {