Skip to content

Commit

Permalink
test: bypass sign in step, faster
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed May 22, 2024
1 parent 4f56ce0 commit 3de9da6
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions tests/page-object-models/onboarding.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { OnboardingSelectors } from '@tests/selectors/onboarding.selectors';
import type { SupportedBlockchains } from '@shared/constants';
import { RouteUrls } from '@shared/route-urls';

import { test } from '../fixtures/fixtures';

const TEST_ACCOUNT_SECRET_KEY = process.env.TEST_ACCOUNT_SECRET_KEY ?? '';

// If default wallet state changes, we'll need to update this
Expand Down Expand Up @@ -281,21 +279,32 @@ export class OnboardingPage {
* account
*/
async signInWithTestAccount(id: string) {
const isUnlockPage = async () => await this.page.getByText('Enter your password').isVisible();
while (!(await isUnlockPage())) {
const testAccountDerivedKey =
'd904f412b8d116540017c302f3f7033813c95902af5a067c7befcc34fa5e5290709f157f80548603a1e4f8edc2c0d5d7';

const isSignedIn = async () => {
const { encryptionKey } = await this.page.evaluate(async () =>
chrome.storage.session.get(['encryptionKey'])
);
const hasKeySessionKey = encryptionKey === testAccountDerivedKey;
const hasAssetsTab = this.page.getByText('Assets');
const hasActivityTab = this.page.getByText('Activity');
return hasKeySessionKey && hasAssetsTab && hasActivityTab;
};

do {
await this.page.evaluate(
async walletState => await chrome.storage.local.set({ 'persist:root': walletState }),
async walletState => chrome.storage.local.set({ 'persist:root': walletState }),
testSoftwareAccountDefaultWalletState
);
await this.page.goto(`chrome-extension://${id}/index.html`, {
waitUntil: 'networkidle',
});
}
await test.expect(this.page.getByText('Enter your password')).toBeVisible();
await this.page.getByRole('textbox').fill(TEST_PASSWORD);
await this.page.getByRole('button', { name: 'Continue' }).click();
await this.page.waitForURL('**' + RouteUrls.Home);
await this.page.locator('text="Account 1"').waitFor();

await this.page.evaluate(
async encryptionKey => chrome.storage.session.set({ encryptionKey }),
testAccountDerivedKey
);

await this.page.goto(`chrome-extension://${id}/index.html`, { waitUntil: 'networkidle' });
} while (!(await isSignedIn()));
}

/**
Expand Down

0 comments on commit 3de9da6

Please sign in to comment.