Skip to content

Conversation

@ScharfViktor
Copy link
Contributor

@ScharfViktor ScharfViktor commented Jul 25, 2025

Problem

The E2E tests for media viewer download and file closing were experiencing flakiness due to race conditions in Promise.all usage.

Solution

Applied Playwright's recommended "prepare promise first" pattern:

How to reproduce

HEADLESS=false pnpm test:e2e:cucumber:chromium tests/e2e/cucumber/features/shares/share.feature:79

✔ And "Alice" opens the following file in mediaviewer                                    # file:/woodpecker/src/github.com/opencloud-eu/opencloud/webTestRunner/tests/e2e/cucumber/steps/ui/resources.ts:378
       | resource       |
       | test_video.mp4 |
   ✔ Then "Alice" is in a media-viewer                                                      # file:/woodpecker/src/github.com/opencloud-eu/opencloud/webTestRunner/tests/e2e/cucumber/steps/ui/public.ts:43
   ✔ When "Alice" downloads the following resource using the preview topbar                 # file:/woodpecker/src/github.com/opencloud-eu/opencloud/webTestRunner/tests/e2e/cucumber/steps/ui/resources.ts:73
       | resource       | type |
       | test_video.mp4 | file |
   ✘ And "Alice" closes the file viewer                                                     # file:/woodpecker/src/github.com/opencloud-eu/opencloud/webTestRunner/tests/e2e/cucumber/steps/ui/public.ts:35
         at Module.close (/woodpecker/src/github.com/opencloud-eu/opencloud/webTestRunner/tests/e2e/support/objects/app-files/utils/editor.ts:8:14)
             at World.<anonymous> (/woodpecker/src/github.com/opencloud-eu/opencloud/webTestRunner/tests/e2e/cucumber/steps/ui/public.ts:37:18)

cc @dragonchaser

Copilot AI review requested due to automatic review settings July 25, 2025 07:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes flaky test behavior by refactoring asynchronous operations to use sequential awaits instead of Promise.all() for improved reliability in end-to-end tests.

  • Replaced Promise.all() with sequential awaits in the editor close function to ensure proper timing
  • Updated download resource functionality to use sequential awaits for better control over async operations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/e2e/support/objects/app-files/utils/editor.ts Refactored close function to use sequential async/await pattern instead of Promise.all()
tests/e2e/support/objects/app-files/resource/actions.ts Updated download functionality to use sequential awaits for better reliability

Comment on lines +815 to +817
const downloadButtonPromise = page.locator(appBarDownloadFileButton).waitFor()
await page.locator(appBarContextMenu).click()
await downloadButtonPromise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the difference to?

Suggested change
const downloadButtonPromise = page.locator(appBarDownloadFileButton).waitFor()
await page.locator(appBarContextMenu).click()
await downloadButtonPromise
await page.locator(appBarContextMenu).click()
await page.locator(appBarDownloadFileButton).waitFor()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are looking for the button BEFORE the menu opens.
following docs
https://playwright.dev/docs/downloads#introduction

better do it like:

  1. Preparation
  2. Action
  3. Wait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let see how it works. I couldn't think of anything more interesting 😆

@prashant-gurung899
Copy link
Contributor

🤔 Hmmm, this is same test that fails when tracing is enabled.
Fails with a Browser credential dialog pop-up.

@ScharfViktor
Copy link
Contributor Author

🤔 Hmmm, this is same test that fails when tracing is enabled. Fails with a Browser credential dialog pop-up.

where? in the opencloud CI?
if yes, let merge it and update webcommitId in opencloud to see what happens. It certainly will not be worse.

@ScharfViktor ScharfViktor changed the title fix flaky close viewer fix flaky close viewer after download Jul 25, 2025
@prashant-gurung899
Copy link
Contributor

where? in the opencloud CI? if yes, let merge it and update webcommitId in opencloud to see what happens. It certainly will not be worse.

Yes, in Opencloud CI, SEE PR: But, currently facing some problems with playwright not being found in the CI.
Download related tests are failing due to a dialog box popping up when tracing is enabled.
Check this issue in playwright as well.

@ScharfViktor
Copy link
Contributor Author

Yes, in Opencloud CI, SEE PR: But, currently facing some problems with playwright not being found in the CI. Download related tests are failing due to a dialog box popping up when tracing is enabled. Check this issue in playwright as well.

Thanks, I couldn't reproduce it using chrome. Maybe it's same issue, maybe not (I don't see auth popup in the trace)

@prashant-gurung899
Copy link
Contributor

prashant-gurung899 commented Jul 25, 2025

Thanks, I couldn't reproduce it using chrome. Maybe it's same issue, maybe not (I don't see auth popup in the trace)

Try running it with tracing enabled.
REPORT_TRACING=true HEADLESS=false pnpm test:e2e:cucumber:chromium tests/e2e/cucumber/features/shares/share.feature:79
With your changes in browser script, it is now passing in web CI as well with tracing enabled because it's running chromium now.

if yes, let merge it and update webcommitId in opencloud to see what happens. It certainly will not be worse.

Let's see 😄

@ScharfViktor ScharfViktor merged commit 534ae9e into main Jul 25, 2025
28 checks passed
@ScharfViktor ScharfViktor deleted the fixFlakyCloseViewer branch July 25, 2025 12:09
@openclouders openclouders mentioned this pull request Jul 25, 2025
1 task
@ScharfViktor
Copy link
Contributor Author

Try running it with tracing enabled. REPORT_TRACING=true HEADLESS=false pnpm test:e2e:cucumber:chromium

yes, I can confirm, now I got auth popup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants