Waiting for a value, then acting on it

Read progress from ARIA, not from styles

The bar has role="progressbar" and reports its value in aria-valuenow. That attribute is made for assistive technology, which makes it a stable thing to test. The bar's width in pixels is not.

const bar = page.getByRole('progressbar', { name: 'Upload progress' });

await page.getByRole('button', { name: 'Start progress' }).click();
await expect(bar).toHaveAttribute('aria-valuenow', '100');

Act once a threshold is reached

To stop the bar at 70% or more, wait until the value is high enough, then click. expect.poll() retries any function until its result passes the matcher, which is useful for numbers:

await expect
  .poll(async () => Number(await bar.getAttribute('aria-valuenow')), {
    intervals: [50],
  })
  .toBeGreaterThanOrEqual(70);

await page.getByRole('button', { name: 'Stop' }).click();
await expect(page.getByTestId('progress-result')).toHaveText(/Stopped at (7\d|8\d|9\d)%/);

intervals sets how often it checks. The default starts slowly, at 100 ms, then 250 ms, then 500 ms, so the bar could reach 100% between two checks.

The bar moves on while your test runs, so you cannot hit an exact value such as 75%. Assert a range instead.

Upload

Moves 5% every 200 ms. Stop it at 70% or more.

0%