-
Notifications
You must be signed in to change notification settings - Fork 21
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
8465574
commit 6146b6f
Showing
27 changed files
with
401 additions
and
9 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
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,5 +1,5 @@ | ||
|
||
const version = '2.1.21'; | ||
const version = '2.1.23'; | ||
const versionBuild = '2020-0101-1'; | ||
|
||
export default { | ||
|
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,4 @@ | ||
node_modules/ | ||
test-results/ | ||
playwright-report/ | ||
playwright/.cache/ |
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,20 @@ | ||
import dotenv from 'dotenv'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
function setupDotEnv() { | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const results = [ | ||
dotenv.config({ | ||
path: path.resolve(__dirname, '../../.env'), | ||
}), | ||
]; | ||
const errorResult = results.find((result) => result.error); | ||
|
||
if (errorResult) { | ||
throw errorResult.error; | ||
} | ||
} | ||
setupDotEnv(); |
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,45 @@ | ||
{ | ||
"private": true, | ||
"name": "@onekeyfe/e2e", | ||
"version": "2.1.23", | ||
"keywords": [ | ||
"cross-inpage-provider" | ||
], | ||
"author": "[email protected]", | ||
"repository": "https://github.com/OneKeyHQ/cross-inpage-provider", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"type": "module", | ||
"files": [ | ||
"dist/*" | ||
], | ||
"exports": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/cjs/index.js" | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"module": "./dist/index.js", | ||
"main": "./dist/cjs/index.js", | ||
"scripts": { | ||
"env": "node dotEnvInit.js", | ||
"report": "yarn env && npx playwright show-report", | ||
"test": "yarn env && npx playwright test", | ||
"test:headed": "yarn env && npx playwright test --headed && yarn report", | ||
"test:ui": "yarn env && npx playwright test --ui" | ||
}, | ||
"dependencies": { | ||
"@onekeyfe/inpage-providers-hub": "2.1.23", | ||
"@onekeyfe/cross-inpage-provider-injected": "2.1.23", | ||
"@onekeyfe/cross-inpage-provider-types": "2.1.23", | ||
"lodash-es": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.49.1", | ||
"@types/lodash-es": "^4.17.12", | ||
"@types/node": "^20.12.7", | ||
"playwright": "^1.49.1" | ||
} | ||
} |
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,22 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
testDir: './tests', | ||
testMatch: ['**/*.e2e.ts', '**/*.e2e.js'], | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: 'html', | ||
use: { | ||
baseURL: 'http://localhost:3000', | ||
trace: 'on-first-retry', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
outputDir: 'test-results', | ||
}); |
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,39 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './src', | ||
testMatch: '*.spec.ts', | ||
timeout: 1000 * 60, | ||
fullyParallel: false, | ||
forbidOnly: !!process.env.CI, | ||
retries: 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: [['html', { outputFolder: 'reports' }]], | ||
|
||
use: { | ||
screenshot: 'on', | ||
trace: 'on', | ||
// video: 'on', | ||
}, | ||
|
||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'], viewport: { width: 1920, height: 800 } }, | ||
}, | ||
|
||
{ | ||
name: 'Mobile Chrome', | ||
use: { ...devices['iPhone 6'] }, | ||
}, | ||
], | ||
}); |
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,64 @@ | ||
// 在文件顶部添加这个声明 | ||
declare global { | ||
interface Window { | ||
$1key: { | ||
hello: () => string; | ||
}; | ||
} | ||
} | ||
|
||
import { expect, test } from '@playwright/test'; | ||
|
||
test.skip('Bing search test', async ({ page }) => { | ||
// 打开 Bing | ||
await page.goto('https://www.baidu.com'); | ||
|
||
// 等待搜索输入框出现并输入内容 | ||
const searchInput = page.locator('#kw'); | ||
await searchInput.fill('hemoglobin consists of click to select chainsmokers songs'); | ||
await searchInput.press('Enter'); | ||
|
||
// 等待搜索结果出现 | ||
await page.waitForSelector('.result.c-container.xpath-log.new-pmd'); | ||
|
||
// 获取第二个搜索结果 | ||
const secondResult = page.locator('.result.c-container.xpath-log.new-pmd').nth(1); | ||
|
||
// 使用 evaluate 来高亮元素 | ||
await secondResult.evaluate((element) => { | ||
element.style.backgroundColor = 'yellow'; | ||
element.style.border = '2px solid red'; | ||
}); | ||
|
||
const init1key = () => { | ||
window.$1key = { | ||
hello: () => 'world', | ||
}; | ||
}; | ||
|
||
// 注入全局变量 | ||
await page.evaluate(init1key); | ||
|
||
// 验证 $1key 全局变量存在 | ||
const hasOneKey = await page.evaluate(() => { | ||
return window.$1key !== undefined; | ||
}); | ||
expect(hasOneKey).toBe(true); | ||
|
||
// 验证 $1key.hello 方法存在且可调用 | ||
const hasHelloMethod = await page.evaluate<string>(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call | ||
const result = window.$1key ? window.$1key.hello() : ''; | ||
return result; | ||
}); | ||
expect(hasHelloMethod).toBe('world'); | ||
|
||
// 截个图(可选) | ||
await page.screenshot({ path: 'test-results/screenshots/bing-search.png' }); | ||
|
||
// 验证搜索结果存在 | ||
await expect(secondResult).toBeVisible(); | ||
|
||
// 设置浏览器在测试完成后保持打开状态 | ||
await page.pause(); | ||
}); |
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,37 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import { connectButtonData } from '@onekeyfe/inpage-providers-hub'; | ||
|
||
const injectedCode = fs.readFileSync( | ||
path.resolve( | ||
'node_modules/@onekeyfe/cross-inpage-provider-injected/dist/injected/injectedNative.js', | ||
), | ||
'utf-8', | ||
); | ||
|
||
import { expect, test } from '@playwright/test'; | ||
|
||
test('dapp-test', async ({ page }) => { | ||
console.log(connectButtonData.sitesConfig[0]); | ||
|
||
// await page.goto('https://dapp-example.onekeytest.com'); | ||
// https://app.uniswap.org/ | ||
await page.goto('https://app.uniswap.org/'); | ||
|
||
// eval injectedCode | ||
await page.evaluate(injectedCode); | ||
|
||
// 验证 $onekey 全局变量存在 | ||
const hasOneKey = await page.evaluate(() => { | ||
// @ts-ignore | ||
return window.$onekey !== undefined; | ||
}); | ||
expect(hasOneKey).toBe(true); | ||
|
||
// 截个图(可选) | ||
await page.screenshot({ path: 'test-results/screenshots/dapp-test.png' }); | ||
|
||
// 设置浏览器在测试完成后保持打开状态 | ||
await page.pause(); | ||
}); |
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,6 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.skip('basic test', async ({ page }) => { | ||
await page.goto('https://example.walletconnect.org'); | ||
await expect(page).toHaveTitle(/React/); | ||
}); |
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,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["**/*.ts", "**/*.tsx", "dotEnvInit.js"], | ||
"exclude": ["node_modules"] | ||
} |
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,58 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@playwright/test@^1.49.1": | ||
version "1.49.1" | ||
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.49.1.tgz#55fa360658b3187bfb6371e2f8a64f50ef80c827" | ||
integrity sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g== | ||
dependencies: | ||
playwright "1.49.1" | ||
|
||
"@types/lodash-es@^4.17.12": | ||
version "4.17.12" | ||
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.12.tgz#65f6d1e5f80539aa7cfbfc962de5def0cf4f341b" | ||
integrity sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ== | ||
dependencies: | ||
"@types/lodash" "*" | ||
|
||
"@types/lodash@*": | ||
version "4.17.13" | ||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.13.tgz#786e2d67cfd95e32862143abe7463a7f90c300eb" | ||
integrity sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg== | ||
|
||
"@types/node@^20.12.7": | ||
version "20.17.10" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.17.10.tgz#3f7166190aece19a0d1d364d75c8b0b5778c1e18" | ||
integrity sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA== | ||
dependencies: | ||
undici-types "~6.19.2" | ||
|
||
[email protected]: | ||
version "2.3.2" | ||
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" | ||
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== | ||
|
||
lodash-es@^4.17.21: | ||
version "4.17.21" | ||
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee" | ||
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw== | ||
|
||
[email protected]: | ||
version "1.49.1" | ||
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.49.1.tgz#32c62f046e950f586ff9e35ed490a424f2248015" | ||
integrity sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg== | ||
|
||
[email protected], playwright@^1.49.1: | ||
version "1.49.1" | ||
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.49.1.tgz#830266dbca3008022afa7b4783565db9944ded7c" | ||
integrity sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA== | ||
dependencies: | ||
playwright-core "1.49.1" | ||
optionalDependencies: | ||
fsevents "2.3.2" | ||
|
||
undici-types@~6.19.2: | ||
version "6.19.8" | ||
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" | ||
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== |
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
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
Oops, something went wrong.