-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cat-voices): playwright refactoring
- Loading branch information
Showing
16 changed files
with
373 additions
and
177 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
47 changes: 26 additions & 21 deletions
47
...ces/packages/libs/catalyst_cardano/catalyst_cardano/wallet-automation/README.md
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 |
---|---|---|
@@ -1,44 +1,49 @@ | ||
# Wallet Automation | ||
|
||
Welcome to wallet automation, a testing package in Playwright that tests wallet integration for Catalyst Voices. | ||
|
||
## Introduction | ||
|
||
Wallet automation is a testing package in Playwright that automates the wallet creation process for the Catalyst project. | ||
Wallet automation is a testing package in Playwright that automates the wallet creation process for the Catalyst project. | ||
It is a part of the Catalyst Voices ecosystem. | ||
|
||
## Getting Started | ||
|
||
1. Clone this repository: | ||
|
||
```sh | ||
git clone | ||
cd catalyst-voices | ||
``` | ||
```sh | ||
git clone | ||
cd catalyst-voices | ||
``` | ||
|
||
2. Install Flutter and Dart: | ||
|
||
```sh | ||
brew install flutter | ||
``` | ||
```sh | ||
brew install flutter | ||
``` | ||
|
||
3. Bootstrap the project: | ||
|
||
```sh | ||
melos bootstrap | ||
``` | ||
```sh | ||
melos bootstrap | ||
``` | ||
|
||
4. Execute earthly command from this directory: | ||
|
||
```sh | ||
earthly +package-app | ||
``` | ||
```sh | ||
earthly +package-app | ||
``` | ||
|
||
5. Use docker compose to run the app: | ||
|
||
```sh | ||
docker compose up | ||
``` | ||
The app should be running on `localhost:8000`. | ||
```sh | ||
docker compose up | ||
``` | ||
|
||
The app should be running on `localhost:8000`. | ||
|
||
6. You can now run tests with the following command: | ||
|
||
```sh | ||
npx playwright test | ||
``` | ||
```sh | ||
npx playwright test | ||
``` |
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
18 changes: 18 additions & 0 deletions
18
...packages/libs/catalyst_cardano/catalyst_cardano/wallet-automation/pages/walletListPage.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
import { BrowserExtensionName } from '../utils/extensions'; | ||
|
||
|
||
export class WalletListPage { | ||
readonly page: Page; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
async clickEnableWallet(walletName: BrowserExtensionName): Promise<void> { | ||
const enableButton = (walletName: BrowserExtensionName) => this.page.locator( | ||
`flt-semantics:has(flt-semantics-img[aria-label*="Name: ${walletName.toLowerCase()}"]) ` + | ||
`flt-semantics[role="button"]:has-text("Enable wallet")` | ||
); | ||
await enableButton(walletName).click(); | ||
} | ||
} |
31 changes: 15 additions & 16 deletions
31
...es/packages/libs/catalyst_cardano/catalyst_cardano/wallet-automation/playwright.config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
import dotenv from 'dotenv'; | ||
import path from 'path'; | ||
import { defineConfig, devices } from "@playwright/test"; | ||
import dotenv from "dotenv"; | ||
import path from "path"; | ||
|
||
dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
dotenv.config({ path: path.resolve(__dirname, ".env") }); | ||
|
||
export default defineConfig({ | ||
testDir: './tests', | ||
testDir: "./tests", | ||
fullyParallel: false, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 1, | ||
workers: process.env.CI ? 1 : 1, | ||
use: { | ||
baseURL: process.env.APP_URL || 'http://localhost:8000', | ||
screenshot: 'only-on-failure', | ||
trace: 'on', | ||
video: 'on', | ||
|
||
baseURL: process.env.APP_URL || "http://localhost:8000", | ||
screenshot: "only-on-failure", | ||
trace: "on", | ||
video: "on", | ||
}, | ||
reporter: [ | ||
['html', { open: 'never', outputFolder: '/results' }], | ||
['junit', { outputFile: '/results/cardano-wallet.junit-report.xml' }]], | ||
timeout: 120 * 1000, | ||
["junit", { outputFile: "/results/cardano-wallet.junit-report.xml" }], | ||
], | ||
timeout: 60 * 1000, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
] | ||
], | ||
}); |
68 changes: 68 additions & 0 deletions
68
catalyst_voices/packages/libs/catalyst_cardano/catalyst_cardano/wallet-automation/setup.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { BrowserContext, chromium, Page } from "@playwright/test"; | ||
import { ExtensionDownloader } from "./utils/extensionDownloader"; | ||
import { BrowserExtensionName } from "./utils/extensions"; | ||
import { | ||
allowExtension, | ||
onboardWallet, | ||
WalletConfig, | ||
} from "./utils/wallets/walletUtils"; | ||
|
||
const installExtension = async (extensionName: BrowserExtensionName) => { | ||
const extensionPath = await new ExtensionDownloader().getExtension( | ||
extensionName | ||
); | ||
const browser = await chromium.launchPersistentContext("", { | ||
headless: false, // extensions only work in headful mode | ||
args: [ | ||
`--disable-extensions-except=${extensionPath}`, | ||
`--load-extension=${extensionPath}`, | ||
], | ||
}); | ||
let [background] = browser.serviceWorkers(); | ||
if (!background) background = await browser.waitForEvent("serviceworker"); | ||
return browser; | ||
}; | ||
|
||
export const restoreWallet = async (walletConfig: WalletConfig) => { | ||
const browser = await installExtension(walletConfig.extension.Name); | ||
const extensionTab = browser.pages()[0]; | ||
walletConfig.extension.HomeUrl = await getDynamicUrlInChrome( | ||
extensionTab, | ||
walletConfig | ||
); | ||
await extensionTab.goto(walletConfig.extension.HomeUrl); | ||
await onboardWallet(extensionTab, walletConfig); | ||
return browser; | ||
}; | ||
|
||
export const enableWallet = async ( | ||
walletConfig: WalletConfig, | ||
browser: BrowserContext | ||
) => { | ||
const page = browser.pages()[0]; | ||
await page.reload(); | ||
await page.goto("/"); | ||
await page.waitForTimeout(4000); | ||
const [walletPopup] = await Promise.all([ | ||
browser.waitForEvent("page"), | ||
page.locator('//*[text()="Enable wallet"]').click(), | ||
]); | ||
await walletPopup.waitForTimeout(2000); | ||
await allowExtension(walletPopup, walletConfig.extension.Name); | ||
await page.waitForTimeout(2000); | ||
return browser; | ||
}; | ||
|
||
/** | ||
* We need this because some extensions have dynamic URLs | ||
**/ | ||
const getDynamicUrlInChrome = async ( | ||
extensionTab: Page, | ||
walletConfig: WalletConfig | ||
): Promise<string> => { | ||
await extensionTab.goto("chrome://extensions/"); | ||
const extensionId = await extensionTab | ||
.locator("extensions-item") | ||
.getAttribute("id"); | ||
return `chrome-extension://${extensionId}/${walletConfig.extension.HomeUrl}`; | ||
}; |
Oops, something went wrong.