-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7fb082
commit f9b211e
Showing
8 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import path from 'node:path' | ||
import { type Page, chromium } from '@playwright/test' | ||
|
||
import { test as base } from '@playwright/test' | ||
import { | ||
CACHE_DIR_NAME, | ||
createTempContextDir, | ||
defineWalletSetup, | ||
removeTempContextDir | ||
} from '@synthetixio/synpress-cache' | ||
import { prepareExtension } from '@synthetixio/synpress-cache' | ||
import fs from 'fs-extra' | ||
import { PhantomWallet } from '../PhantomWallet' | ||
import { getExtensionId } from '../fixtureActions' | ||
import { persistLocalStorage } from '../fixtureActions/persistLocalStorage' | ||
// import unlockForFixtures from '../fixtureActions/unlockForFixtures' | ||
import { PASSWORD } from '../utils' | ||
|
||
type PhantomFixtures = { | ||
_contextPath: string | ||
phantom: PhantomWallet | ||
phantomPage: Page | ||
extensionId: string | ||
} | ||
|
||
let _phantomPage: Page | ||
|
||
export const phantomFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>, slowMo = 0) => { | ||
return base.extend<PhantomFixtures>({ | ||
_contextPath: async ({ browserName }, use, testInfo) => { | ||
const contextDir = await createTempContextDir(browserName, testInfo.testId) | ||
|
||
await use(contextDir) | ||
|
||
const error = await removeTempContextDir(contextDir) | ||
if (error) { | ||
console.log('contextDir', error) | ||
} | ||
}, | ||
context: async ({ context: currentContext, _contextPath }, use) => { | ||
// @todo: This is some weird behaviour, if there is only 1 setup file the hash function will always produce a different hash than cache. | ||
const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash) | ||
if (!(await fs.exists(cacheDirPath))) { | ||
throw new Error(`Cache for ${cacheDirPath} does not exist. Create it first!`) | ||
} | ||
|
||
// Copying the cache to the temporary context directory. | ||
await fs.copy(cacheDirPath, _contextPath) | ||
|
||
const phantomPath = await prepareExtension('Phantom') | ||
// We don't need the `--load-extension` arg since the extension is already loaded in the cache. | ||
const browserArgs = [`--disable-extensions-except=${phantomPath}`, '--enable-features=SharedClipboardUI'] | ||
if (process.env.HEADLESS) { | ||
browserArgs.push('--headless=new') | ||
|
||
if (slowMo) { | ||
console.warn('[WARNING] Slow motion makes no sense in headless mode. It will be ignored!') | ||
} | ||
} | ||
|
||
const context = await chromium.launchPersistentContext(_contextPath, { | ||
headless: false, | ||
args: browserArgs, | ||
slowMo: process.env.HEADLESS ? 0 : slowMo | ||
}) | ||
|
||
const { cookies, origins } = await currentContext.storageState() | ||
|
||
if (cookies) { | ||
await context.addCookies(cookies) | ||
} | ||
if (origins && origins.length > 0) { | ||
await persistLocalStorage(origins, context) | ||
} | ||
|
||
const extensionId = await getExtensionId(context, 'Phantom') | ||
|
||
_phantomPage = context.pages()[0] as Page | ||
|
||
await _phantomPage.goto(`chrome-extension://${extensionId}/popup.html`) | ||
|
||
// await unlockForFixtures(_phantomPage, PASSWORD) | ||
|
||
await use(context) | ||
}, | ||
phantomPage: async ({ context: _ }, use) => { | ||
await use(_phantomPage) | ||
}, | ||
extensionId: async ({ context }, use) => { | ||
const extensionId = await getExtensionId(context, 'Keplr') | ||
|
||
await use(extensionId) | ||
}, | ||
phantom: async ({ context, extensionId }, use) => { | ||
const phantomWallet = new PhantomWallet(_phantomPage, context, PASSWORD, extensionId) | ||
|
||
await use(phantomWallet) | ||
}, | ||
|
||
page: async ({ page }, use) => { | ||
await page.goto('') | ||
await use(page) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ets/phantom/src/pages/SettingPage/page.ts → ...ts/phantom/src/pages/SettingsPage/page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './selectors/loading' |