Skip to content

Commit

Permalink
fix: "Phishing Detection Via Iframe should redirect users ..." flaky …
Browse files Browse the repository at this point in the history
…test (#26779)

<!--
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**

Fix for flaky test "Phishing Detection Via Iframe should redirect users
..."
I am unable to reproduce the issue on my mac machine. However, based on
the logs and screenshot, it appears that the Dapp was taking time to
load after clicking the "Continue to the site" button on the phishing
page.

- ~~I added a delay to allow the Dapp sufficient time to load completely
before proceeding with further actions.~~
- To prevent any race conditions from getting the header element and
followed by getting the corresponding text from the element. I removed
that code.
- After Howard's suggestion, I updated the `switchToWindowWithTitle`
method with a conditional wait provided by Selenium. This approach works
effectively and provides logs in case of failure when the title is not
loaded.

<!--
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/26779?quickstart=1)

## **Related issues**

Fixes:
#26505

## **Manual testing steps**

Run the below commands locally or in codespaces:
yarn
ENABLE_MV3=false yarn start:test
ENABLE_MV3=false yarn test:e2e:single
test/e2e/tests/phishing-controller/phishing-detection.spec.js
--browser=firefox

The test was executed x5 times against all the builds. Below is the link
for the Firefox browser as reported in the flaky test failure:

https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/98030/workflows/344ccffd-8671-46a9-83ab-5dce7a0b9cdd/jobs/3649076

## **Pre-merge author checklist**

- [ ] 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
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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 Aug 30, 2024
1 parent b82f5b4 commit 9d668dd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/e2e/tests/phishing-controller/phishing-detection.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { strict: assert } = require('assert');
const { createServer } = require('node:http');
const { createDeferredPromise } = require('@metamask/utils');
const { until } = require('selenium-webdriver');

const {
defaultGanacheOptions,
withFixtures,
openDapp,
unlockWallet,
WINDOW_TITLES,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');
const {
Expand Down Expand Up @@ -59,8 +61,7 @@ describe('Phishing Detection', function () {
await driver.clickElement({
text: 'continue to the site.',
});
const header = await driver.findElement('h1');
assert.equal(await header.getText(), 'E2E Test Dapp');
await driver.wait(until.titleIs(WINDOW_TITLES.TestDApp), 10000);
},
);
});
Expand Down Expand Up @@ -105,8 +106,8 @@ describe('Phishing Detection', function () {
await driver.clickElement({
text: 'continue to the site.',
});
const header = await driver.findElement('h1');
assert.equal(await header.getText(), 'E2E Test Dapp');

await driver.wait(until.titleIs(WINDOW_TITLES.TestDApp), 10000);
};
}

Expand Down

0 comments on commit 9d668dd

Please sign in to comment.