From 81008f63bedc22b9d9f0ded93eabe474813eaa84 Mon Sep 17 00:00:00 2001 From: Harika <153644847+hjetpoluru@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:20:55 -0500 Subject: [PATCH] fix: `Test Snap Cronjob can trigger a cronjob to open a di...` flaky tests (#28363) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **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 b97dbbea9d67a708b078a69d64d832d9badd16bd. 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. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28363?quickstart=1) ## **Related issues** Fixes: https://github.com/MetaMask/metamask-extension/issues/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. --- test/e2e/snaps/test-snap-cronjob.spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/snaps/test-snap-cronjob.spec.js b/test/e2e/snaps/test-snap-cronjob.spec.js index 6f4e05883943..5fbc22d7ad71 100644 --- a/test/e2e/snaps/test-snap-cronjob.spec.js +++ b/test/e2e/snaps/test-snap-cronjob.spec.js @@ -3,6 +3,7 @@ const { withFixtures, unlockWallet, WINDOW_TITLES, + largeDelayMs, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); const { TEST_SNAPS_WEBSITE_URL } = require('./enums'); @@ -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