|
1 | | -# ton-connect-qa |
| 1 | +# TON-Connect QA |
2 | 2 |
|
3 | | -## QA |
| 3 | +This guide provides a quick setup process for Playwright to automate tests for TON Dapps, note that this is a basic configuration |
4 | 4 |
|
5 | | -Write scenarios in folder [features](features) see [Gherkin Reference](https://cucumber.io/docs/gherkin/reference/) |
| 5 | +## Prerequisites |
6 | 6 |
|
7 | | -## SE |
| 7 | +- Node.js v18+ |
| 8 | +- Playwright and TypeScript knowledge |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +1. Install Playwright and its dependencies: |
| 13 | + |
| 14 | +```bash |
| 15 | +npm init playwright@latest |
| 16 | +``` |
| 17 | + |
| 18 | +Follow the prompts to complete the installation |
| 19 | + |
| 20 | + |
| 21 | +2. Install dev dependency: |
| 22 | + |
| 23 | +```bash |
| 24 | +npm install --save-dev @tonconnect/qa |
| 25 | +``` |
| 26 | + |
| 27 | +## Setup |
| 28 | + |
| 29 | +1. Create or update your Playwright configuration file (e.g., `playwright.config.ts`): |
| 30 | + |
| 31 | +```typescript |
| 32 | +import 'dotenv/config' |
| 33 | +import { defineConfig, devices } from '@playwright/test' |
| 34 | + |
| 35 | +// Define Playwright configuration |
| 36 | +export default defineConfig({ |
| 37 | + testDir: './test', |
| 38 | + fullyParallel: true, |
| 39 | + forbidOnly: !!process.env.CI, |
| 40 | + retries: process.env.CI ? 2 : 0, |
| 41 | + workers: process.env.CI ? 1 : undefined, |
| 42 | + reporter: 'html', |
| 43 | + use: { |
| 44 | + // Set base URL for tests |
| 45 | + baseURL: 'http://localhost:3000', |
| 46 | + trace: 'on-first-retry', |
| 47 | + }, |
| 48 | + projects: [ |
| 49 | + { |
| 50 | + name: 'chromium', |
| 51 | + use: { ...devices['Desktop Chrome'] }, |
| 52 | + }, |
| 53 | + ], |
| 54 | +}) |
| 55 | +``` |
| 56 | + |
| 57 | +2. Create a test file (e.g., `tests/example.spec.ts`): |
| 58 | + |
| 59 | +```typescript |
| 60 | +// Import necessary modules and setup |
| 61 | +import { TonConnectWidget, testWith, tonkeeperFixture } from '../qa' |
| 62 | + |
| 63 | +// Create a test instance Tonkeeper fixtures |
| 64 | +const test = testWith(tonkeeperFixture(process.env.WALLET_MNEMONIC!)) |
| 65 | + |
| 66 | +// Extract expect function from test |
| 67 | +const { expect } = test |
| 68 | + |
| 69 | +// Define a basic test case |
| 70 | +test('lab', async ({ context, wallet }) => { |
| 71 | + // Navigate to the homepage |
| 72 | + const app = await context.newPage() |
| 73 | + await app.goto('https://ton-connect.github.io/demo-dapp-with-react-ui/') |
| 74 | + |
| 75 | + // Click the connect button |
| 76 | + const connectButton = app.getByRole('button', { name: 'Connect wallet to send the transaction' }) |
| 77 | + |
| 78 | + // Connect Tonkeeper to the dapp |
| 79 | + const tonConnect = new TonConnectWidget(app, connectButton) |
| 80 | + await tonConnect.connectWallet('Tonkeeper') |
| 81 | + await wallet.connect() |
| 82 | + |
| 83 | + // Verify the connected account address |
| 84 | + const accountSelector = app.locator('div[data-tc-text]') |
| 85 | + await expect(accountSelector).toHaveText('0QAy…WfyR') |
| 86 | + |
| 87 | + // Sending transactions |
| 88 | + await app.getByRole('button', { name: 'Send transaction' }).click() |
| 89 | + await wallet.accept() |
| 90 | +}) |
| 91 | +``` |
| 92 | + |
| 93 | +## Running Tests |
| 94 | + |
| 95 | +To run your Playwright tests with Tonkeeper: |
| 96 | + |
| 97 | +1. Start your local development server (if testing against a local app). |
| 98 | + |
| 99 | +2. Run the tests: |
| 100 | + |
| 101 | +```bash |
| 102 | +npx playwright test --config playwright-test.config.ts |
| 103 | +``` |
| 104 | + |
| 105 | +This will execute your tests using Playwright with Tonkeeper integration |
| 106 | + |
| 107 | + |
| 108 | +## BDD |
| 109 | +### QA |
| 110 | + |
| 111 | +Write scenarios in folder [features](features) see [Gherkin Reference](https://cucumber.io/docs/gherkin/reference/) and [Cucumber Anti-Patterns](https://www.thinkcode.se/blog/2016/06/22/cucumber-antipatterns) |
| 112 | + |
| 113 | +### SE |
8 | 114 |
|
9 | 115 | Describe step in folder [steps](steps) |
10 | 116 |
|
11 | | -## Run |
| 117 | +## Develop |
12 | 118 |
|
13 | 119 | ```shell |
14 | 120 | npm install |
15 | 121 | npm run lint |
16 | 122 | npm run format |
17 | 123 | npx playwright install |
| 124 | +pnpm exec playwright install |
18 | 125 | npm test |
19 | 126 | # or |
20 | 127 | npm run watch |
21 | 128 | ``` |
| 129 | + |
| 130 | +## Techstack |
| 131 | + |
| 132 | +- [Gherkin](https://cucumber.io/docs/gherkin/) — language used for describe acceptance scenarios |
| 133 | + - [Cucumber Anti-Patterns](https://www.thinkcode.se/blog/2016/06/22/cucumber-antipatterns) |
| 134 | +- [Node.js](https://nodejs.org/) — main platform for automation implementation |
| 135 | +- [Playwright](https://playwright.dev/) + [BDD](https://vitalets.github.io/playwright-bdd/) — framework browser automation used for implementation steps uses in scenarios |
| 136 | + |
| 137 | +## TODO research |
| 138 | + |
| 139 | +- https://www.browserstack.com/ |
| 140 | + - https://vitalets.github.io/playwright-bdd/#/guides/usage-with-browserstack |
| 141 | +- https://saucelabs.com/ |
| 142 | + - https://vitalets.github.io/playwright-bdd/#/guides/usage-with-saucelabs |
| 143 | +- https://nx.dev/ |
| 144 | + - https://vitalets.github.io/playwright-bdd/#/guides/usage-with-nx |
| 145 | +- IDE integration |
| 146 | + - Intellij IDE / Aqua https://vitalets.github.io/playwright-bdd/#/guides/ide-integration?id=intellij-ide-aqua |
| 147 | + - VS Code https://vitalets.github.io/playwright-bdd/#/guides/ide-integration?id=vs-code |
0 commit comments