Skip to content

Commit c7d6cba

Browse files
fix: use RedirectWebsite page object and remove 'should' from test names (MMQA-1721)
Move WebView runScript redirect logic into RedirectWebsite.navigateToTargetUrl() page object method. Rename all test names to drop prohibited 'should' prefix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 94c8e83 commit c7d6cba

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

tests/page-objects/Browser/ExternalWebsites/RedirectWebsite.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ class RedirectWebsite {
1717
);
1818
await redirectButton.tap(); // Click button to redirect to portfolio.metamask.io website
1919
}
20+
21+
/**
22+
* Navigate to a target URL via JavaScript injection in the WebView.
23+
* Use this instead of tapRedirectButton when Detox WebView tap causes
24+
* ReactContext crashes during cross-origin navigations.
25+
*/
26+
async navigateToTargetUrl(targetUrl: string): Promise<void> {
27+
const body = web(by.id(BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID)).element(
28+
by.web.cssSelector('body'),
29+
);
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31+
await (body as any).runScript(
32+
`(el) => { window.location.href = '${targetUrl}'; }`,
33+
);
34+
}
2035
}
2136

2237
export default new RedirectWebsite();

tests/smoke/wallet/browser/browser-navigation.spec.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { DappVariants } from '../../../framework/Constants';
1313
import Browser from '../../../page-objects/Browser/BrowserView';
1414
import EnsWebsite from '../../../page-objects/Browser/ExternalWebsites/EnsWebsite';
15+
import RedirectWebsite from '../../../page-objects/Browser/ExternalWebsites/RedirectWebsite';
1516
import { Assertions, Utilities } from '../../../framework';
1617
import { TestSpecificMock } from '../../../framework/types';
1718
import { setupMockRequest } from '../../../api-mocking/helpers/mockHelpers';
@@ -63,7 +64,7 @@ describe(SmokeWalletPlatform('Browser Navigation'), () => {
6364
jest.setTimeout(150000);
6465
});
6566

66-
it('should navigate back home after visiting an invalid URL', async () => {
67+
it('navigates back home after visiting an invalid URL', async () => {
6768
await withFixtures(
6869
{
6970
fixture: new FixtureBuilder().build(),
@@ -81,7 +82,7 @@ describe(SmokeWalletPlatform('Browser Navigation'), () => {
8182
);
8283
});
8384

84-
it('should resolve and display ENS website (vitalik.eth)', async () => {
85+
it('resolves and displays ENS website (vitalik.eth)', async () => {
8586
const ensTestMock: TestSpecificMock = async (mockServer) => {
8687
await ensResolutionMock(mockServer);
8788
await setupMockRequest(mockServer, {
@@ -125,7 +126,7 @@ describe(SmokeWalletPlatform('Browser Navigation'), () => {
125126
);
126127
});
127128

128-
it('should display redirected URL after cross-origin redirect', async () => {
129+
it('displays redirected URL after cross-origin redirect', async () => {
129130
await withFixtures(
130131
{
131132
dapps: [
@@ -162,16 +163,8 @@ describe(SmokeWalletPlatform('Browser Navigation'), () => {
162163
},
163164
);
164165

165-
// Navigate via runScript — Detox's WebView tap() does not
166-
// reliably fire JavaScript handlers on <button> elements.
167166
const targetUrl = `${getDappUrl(1)}/redirect-target.html`;
168-
const body = web(by.id('browser-webview')).element(
169-
by.web.cssSelector('body'),
170-
);
171-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
172-
await (body as any).runScript(
173-
`(el) => { window.location.href = '${targetUrl}'; }`,
174-
);
167+
await RedirectWebsite.navigateToTargetUrl(targetUrl);
175168
await Assertions.expectElementToHaveText(
176169
Browser.urlInputBoxID,
177170
getOriginFromURL(getDappUrl(1)),

0 commit comments

Comments
 (0)