Skip to content

Commit

Permalink
test: Test playright screen shot
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Jul 24, 2024
1 parent 8fa693f commit 5ee780b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
if: always()
with:
name: playwright-report
path: playwright-report/
path: packages/e2e/test-results
retention-days: 30
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"package:e2e": "yarn build && ./scripts/copy-ui-files.sh",
"package:test": "yarn build && ./scripts/copy-ui-files.sh && ./scripts/package-for-test.sh",
"test": "cross-env NODE_OPTIONS=--openssl-legacy-provider lerna run --parallel --load-env-files=false test",
"test:e2e": "concurrently \"cross-env BROWSER=none yarn run start:ui\" \"wait-on -t 30000 http://127.0.0.1:3000 && cd packages/e2e && yarn test:e2e\"",
"test:e2e": "cd packages/e2e && yarn test:e2e",
"test:ci": "yarn build:main && yarn test",
"lint": "lerna run --stream lint",
"postinstall": "husky install",
Expand Down
44 changes: 23 additions & 21 deletions packages/e2e/__tests__/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {test, expect} from "@playwright/test";

let electronApp: ElectronApplication;


test.beforeAll(async () => {
electronApp = await electron.launch({args: ["../../packages/neuron-wallet/dist/main.js"]});
await new Promise((resolve) => {
electronApp.once("window", async (page) => {
resolve(page)
});
})
electronApp.on("window", async (page) => {
const filename = page.url()?.split("/").pop();
console.log(`Window opened: ${filename}`);
Expand All @@ -20,12 +24,9 @@ test.beforeAll(async () => {
});
});

/*
test.afterAll(async () => {
await electronApp.close();
});
*/

test.afterAll(async() => {
await electronApp.close()
})

let page: Page;

Expand All @@ -50,11 +51,12 @@ test("Launch Neuron", async () => {
});

test("Create Wallet", async () => {
page = await electronApp.firstWindow();
let createWallet = await page.getByText('钱包 1').isVisible();
console.log("createWallet"+createWallet);
if (!createWallet) {
await page.screenshot({path: "./test-results/createWallet.png"});
await page.getByLabel("导入助记词").click();
await page.getByLabel("Import Wallet Seed").click();
await page.locator("div").filter({hasText: /^1$/}).getByRole("textbox").click();
await page.locator("div").filter({hasText: /^1$/}).getByRole("textbox").fill("verb");
await page.locator("div").filter({hasText: /^2$/}).getByRole("textbox").click();
Expand All @@ -79,29 +81,29 @@ test("Create Wallet", async () => {
await page.locator("div").filter({hasText: /^11$/}).getByRole("textbox").fill("portion");
await page.locator("div").filter({hasText: /^12$/}).getByRole("textbox").click();
await page.locator("div").filter({hasText: /^12$/}).getByRole("textbox").fill("hero");
await page.getByLabel("下一步").click();
await page.getByPlaceholder("请设置一个强密码用于保护您的钱包").fill("Aa111111");
await page.getByPlaceholder("重复密码").click();
await page.getByPlaceholder("重复密码").fill("Aa111111");
await page.getByLabel("完成创建").click();
await page.getByRole('button', {name: '开始同步'}).click();
await page.getByLabel("Next").click();
await page.getByPlaceholder("Create a strong password to protect your wallet").fill("Aa111111");
await page.getByPlaceholder("Repeat Password").click();
await page.getByPlaceholder("Repeat Password").fill("Aa111111");
await page.getByLabel("Finish Creating").click();
await page.getByRole('button', {name: 'Start Sync'}).click();
console.log('主网环境已进入!');
// await page.waitForTimeout(20000);

//切换到测试网
let dialogShow= await page.getByLabel('添加网络').isVisible();
let dialogShow= await page.getByLabel('Add Network').isVisible();
if (dialogShow){
await page.getByLabel('添加网络').click();
await page.getByLabel('Add Network').click();
// await page.locator("id=url").fill("http://127.0.0.1:8114");
await page.locator("id=name").fill("testnet");
await page.getByRole('button', {name: '确认'}).click();
await page.getByRole('button', {name: '确认'}).click();
await page.getByRole('button', {name: 'Ok'}).click();
await page.getByRole('button', {name: 'Ok'}).click();
}else {
await page.getByTitle('设置').click();
await page.getByRole('button', {name: '添加网络'}).first().click();
await page.getByTitle('Set').click();
await page.getByRole('button', {name: 'Add Network'}).first().click();
await page.locator("id=url").fill("http://127.0.0.1:8114");
await page.locator("id=name").fill("testnet");
await page.getByRole('button', {name: '确认'}).click();
await page.getByRole('button', {name: 'Ok'}).click();
// await page.getByRole('button', {name: '确认'}).click();
await page.getByText('testnet').click();
}
Expand Down
28 changes: 28 additions & 0 deletions packages/e2e/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { concurrently } from 'concurrently'
import path from 'path'
const waitOn = require('wait-on');

async function globalSetup() {
const { commands } = concurrently(
[
{
command: 'cross-env BROWSER=none yarn run start:ui',
name: 'start ui',
cwd: path.resolve(__dirname, '../../'),
},
],
);
await waitOn({
resources: [
'http://127.0.0.1:3000'
],
timeout: 30_000,
})
console.log('ui start success')
return async () => {
console.log('stop ui server')
await commands[0].kill()
}
}

export default globalSetup;
3 changes: 2 additions & 1 deletion packages/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const config: PlaywrightTestConfig = {
testDir: "./__tests__/tests/",
maxFailures: 2,
timeout: 180000,
retries: 1
retries: 1,
globalSetup: require.resolve('./global-setup'),
};

export default config;

0 comments on commit 5ee780b

Please sign in to comment.