壓力測試使用 Playwright 與 Artillery (入門篇)
Load testing with Playwright and Artillery. stress testing.
Last updated
Load testing with Playwright and Artillery. stress testing.
Last updated
# 需事先安裝好 node.js
# 透過 npm 安裝。其他環境安裝請參考官網。
npm install -g artillery@latest
# 檢查是否安裝
npx artillery dino
# 查看版本
artillery versionconfig:
target: http://192.168.xxx.xxx/
phases:
- duration: 10
arrivalRate: 1
rampTo: 5
name: Simple Test
# Load the Playwright engine:
engines:
playwright:
launchOptions:
headless: false # 將看到開啟的 browser。
# Path to JavaScript file that defines Playwright test functions
processor: "./stress-test.js"
scenarios:
- engine: playwright
testFunction: "testFlow"module.exports = {testFlow};
// delay promise
const delay = (millisecond) => new Promise((resolve) => setTimeout(resolve, millisecond));
async function testFlow(page) {
//進入到測試網站
await page.goto("http://192.168.xxx.xxx/");
//按下登入連接切換到登入畫面
await page.locator('[href*="login"]').first().click();
//此時應已切換到登入畫面
//輸入帳號
await page.locator('[class="mud-input mud-input-outlined"]').first().fill('user_id');
//輸入密碼
await page.locator('[class="mud-input mud-input-outlined password"]').first().fill('user_pwd');
//點擊登入
await page.getByRole('button', { name: '登入' }).click();
}# 指令 artillery run {stress-test.yml}
artillery run stress-test.yml