Skip to content

Commit

Permalink
fix: Test Snap Cronjob can trigger a cronjob to open a di... flaky …
Browse files Browse the repository at this point in the history
…tests (#28363)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This flaky test is due to the dialog taking time to appear and
disappear, which is the expected behavior. I have attached a video
demonstrating the current behavior.


https://github.com/user-attachments/assets/66c68d05-a2dc-4bb5-8870-c967ea9d630a

To address this issue, I added retry logic and validation. However, I
noticed that when the dialog does not appear, `switchToWindowWithTitle`
method throws an exception and fails the test hence causing the retry
logic to be ineffective. Implementation is in the first commit in this
PR b97dbbe.

Fixing this issue within the framework would require significant effort
and could impact other tests. Therefore, I have implemented a wait
period before attempting to switch to the window. This approach ensures
that the dialog has enough time to appear, thereby reducing the
likelihood of test failures.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28363?quickstart=1)

## **Related issues**

Fixes:
#28154

## **Manual testing steps**

Run the test locally or in codespaces using below command
yarn
yarn build:test:webpack
ENABLE_MV3=false yarn test:e2e:single
test/e2e/snaps/test-snap-cronjob.spec.js --browser=chrome
--leave-running

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
hjetpoluru authored Nov 12, 2024
1 parent 2b7101d commit 81008f6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/e2e/snaps/test-snap-cronjob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
withFixtures,
unlockWallet,
WINDOW_TITLES,
largeDelayMs,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
const { TEST_SNAPS_WEBSITE_URL } = require('./enums');
Expand Down Expand Up @@ -74,7 +75,9 @@ describe('Test Snap Cronjob', function () {
text: 'Reconnect to Cronjobs Snap',
});

// switch to dialog popup, wait for a maximum of 65 seconds
// Switching to dialog popup takes time, hence this wait is needed
await driver.delay(largeDelayMs);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

// look for the dialog popup to verify cronjob fired
Expand Down

0 comments on commit 81008f6

Please sign in to comment.