From 0139b9913b762adf448d81f48d265a8fbc0abfd3 Mon Sep 17 00:00:00 2001 From: chloeYue <105063779+chloeYue@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:32:06 +0200 Subject: [PATCH] Stabilize e2e tests for phishing detection (#21152) ## **Description** Several e2e testcases about phishing detection are flaky. ## **Why they are flaky?** After investigation, i think because when we open a malicious website, selenium fetch very quickly all the DOM elements and consider they are complete. When the page redirects to phishing detection page, it dose not re-fetch elements so selenium cannot find buttons to click. ## **How i resolve it?** I explicitly force selenium to switch to the phishing detection page each time after redirection so it will re-fetch all elements on this page. ## **Why do i think the fix works** For each testcase, I ran locally 20 times and they all passed. Fixes #21150 --- test/e2e/tests/phishing-controller/phishing-detection.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/e2e/tests/phishing-controller/phishing-detection.spec.js b/test/e2e/tests/phishing-controller/phishing-detection.spec.js index 2e29a2411ac3..823432c35015 100644 --- a/test/e2e/tests/phishing-controller/phishing-detection.spec.js +++ b/test/e2e/tests/phishing-controller/phishing-detection.spec.js @@ -58,6 +58,7 @@ describe('Phishing Detection', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); await openDapp(driver); + await driver.switchToWindowWithTitle('MetaMask Phishing Detection'); await driver.clickElement({ text: 'continue to the site.', }); @@ -177,6 +178,7 @@ describe('Phishing Detection', function () { await driver.press('#password', driver.Key.ENTER); await openDapp(driver); + await driver.switchToWindowWithTitle('MetaMask Phishing Detection'); await driver.clickElement({ text: 'report a detection problem.' }); // wait for page to load before checking URL. @@ -215,6 +217,7 @@ describe('Phishing Detection', function () { await driver.press('#password', driver.Key.ENTER); await driver.openNewPage(phishingSite.href); + await driver.switchToWindowWithTitle('MetaMask Phishing Detection'); await driver.clickElement({ text: 'report a detection problem.' }); // wait for page to load before checking URL. @@ -252,6 +255,7 @@ describe('Phishing Detection', function () { await driver.press('#password', driver.Key.ENTER); await driver.openNewPage('http://127.0.0.1:8080'); + await driver.switchToWindowWithTitle('MetaMask Phishing Detection'); await driver.clickElement({ text: 'report a detection problem.' }); // wait for page to load before checking URL.