wacat - 一款开源随机测试工具

[复制链接]
发表于 2026-1-28 10:45:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
想象一下,你离开电脑一会儿去拿一杯咖啡。与此同时,你的猫走过键盘,引发了一些紊乱。
wacat 应用步调:

  •         • 访问你的网页应用的根网址
  •         • 随机访问应用中的每个链接
  •         • 在表单中添加随机文本输入
  •         • 从下拉菜单、复选框等中选择随机值
  •         • 随机序次点击每个按钮
别的,wacat 还可以:

  •         • 检测欣赏器与服务器之间的 HTTP 错误(比方 HTTP 500 错误)
  •         • 检测欣赏器控制台日记中的错误
  •         • 从网页中检测错误字符串

    •                 • 你可以在参数文件中提供错误字符串

  •         • 支持用户设置随机表单文本输入
  •         • 可以从外部文件读取表单输入
  •         • 可以仅测试链接,这可以用于应用步调的烟雾测试
  •         • 支持某些身份验证场景

    •                 • 你可以在 JSON 文件中提供身份验证设置

  •         • 支持设置不访问的页面
  •         • 支持无头模式
  •         • 支持设置页面下载等候时间和整个测试的超时值
  •         • 支持在 CI 管道中运行
wacat 内部利用 Playwright[1] 工具。wacat 已颠末测试,可在 Windows、Linux 和 Mac 上运行。
如果你发现了 bug 或须要某些特定功能,请创建一个新的 issue。
当前 wacat 版本为 1.1.2。请检察本页末端以检察更改汗青。
告诫

请仅测试您自己的网页应用步调,或得到测试他人应用步调的允许。在未经允许的情况下测试他人应用步调的毛病大概是违法的。
由于这是我的业余项目,统统皆有大概,最好密切关注 wacat 应用步调的举动,如果它访问了错误的页面,请利用 ctrl + c 克制。请注意,如果您的应用步调利用身份验证,而您的 wacat 身份验证设置不准确或 wacat 不实用于您的情况,那么您的帐户大概会被锁定或出现类似题目。别的,wacat 大概会扰乱您的应用步调数据库等。因此,最好仅在测试情况中举行测试。
安装

安装 Node.js

安装 Node.js 官方指引[2]
克隆 wacat 并安装

克隆 wacat,进入 wacat 目次而且运行:
  1. npm install && npx playwright install --with-deps && npm run build && npm i -g
复制代码
注意:由于 Playwright 工具是全局安装的,因此在运行前面的下令时大概会要求输入暗码。
更新 wacat

更新 wacat 版本的指令:
  1. git pull && 
  2. npm install && npx playwright install --with-deps && npm run build && npm i -g
复制代码
运行

Basic running

在 wacat 文件夹中运行以下下令:
  1. wacat test <your url>
复制代码
比方:
  1. wacat test https://mikesmallhelp-test-application.vercel.app/
复制代码
在 URL https://mikesmallhelp-test-application.vercel.app/ 中测试一个简朴的应用步调。该应用步调包罗以下页面:



起首,wacat 应用步调会打开 Chromium 欣赏器并访问下令中提供的根 URL:

根页面不包罗任何输入字段、下拉菜单等。wacat 简朴地网络两个子页面的链接并访问它们。在每个子页面中,wacat 起首点击按钮,然后填写表单输入,选择下拉菜单项等,末了再次点击按钮。以下是您可以复制、粘贴并运行的下令。同样,您可以运行全部其他示例,并请随意利用我的测试应用步调。
  1. wacat test https://mikesmallhelp-test-application.vercel.app/
复制代码
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
  3. [*]
  4. [*]
  5. [*]        Running 1 test using 1 worker
  6. [*]        [chromium] › test.spec.ts:41:1 › test an application
  7. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/
  8. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
  9. [*]        Push the button #1
  10. [*]        Filling the #1 text input field a value: _k6AKNU3z"{=myqS.K
  11. [*]        The label is 'Your Date of Birth Here', so generating an appropriate random content for the input field
  12. [*]        Filling the #2 text input field a value: 16/09/2004
  13. [*]        The #1 drop-down list. Selecting the option #2
  14. [*]        Selecting the #1 checkbox
  15. [*]        The #1 radio button group. Selecting the radio button #3
  16. [*]        Filling the #1 email input field a value: [email protected]
  17. [*]        Filling the #1 password input field a value: A#1!!a#!#AaA!A
  18. [*]        Filling the #1 search input field a value: SZOmqATkrV
  19. [*]        Filling the #1 url input field a value: https://nrebn.com
  20. [*]        Push the button #1
  21. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page
  22. [*]        Push the button #1
  23. [*]        Filling the #1 text input field a value: _k6AKNU3z"{=myqS.K
  24. [*]        The label is 'Your Date of Birth Here', so generating an appropriate random content for the input field
  25. [*]        Filling the #2 text input field a value: 16/09/2004
  26. [*]        The #1 drop-down list. Selecting the option #2
  27. [*]        Selecting the #1 checkbox
  28. [*]        The #1 radio button group. Selecting the radio button #2
  29. [*]        Filling the #1 email input field a value: [email protected]
  30. [*]        Filling the #1 password input field a value: aa2B#1aA!##2A#!AaA
  31. [*]        Filling the #1 search input field a value: lSjsBVOzkhCC
  32. [*]        Filling the #1 url input field a value: https://vpo7ut.net
  33. [*]        Push the button #1
  34. [*]        1 passed (24.3s)
  35. [/list]
  36. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2UwODVhNTczZmI2ODg4NDY0ODFjZWRlNjVkNmNiMjdiLnBuZw==[/img][/align]
  37. 请注意,输出包罗“1 passed”,因此 wacat 没有在应用步调中发现任何错误。别的,请注意,每个页面的默认等候时间为 5000 毫秒。如果您想更改此时间,请利用 --wait 标记(详见后文)。
  38. [size=2]检测 HTTP 错误[/size]
  39. wacat 可以检测欣赏器和服务器之间的 HTTP 错误。比方,如果在下面的示例应用步调中点击按钮,会出现 HTTP 500 错误。
  40. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvODhmZGRhMWI4YWQwNDkxMmI3OTYxMzhlZTIzYjBjYjkucG5n[/img][/align]
  41. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvOWZiYTZkOTgyN2IyNDQ2M2I1NjA2NDJlNjE3Y2ZmNDQucG5n[/img][/align]
  42. 比方:
  43. [code]
  44. wacat test https://mikesmallhelp-test-application-http-500-error.vercel.app/
复制代码
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application-http-500-error.vercel.app/. Please wait...
  3. [*]
  4. [*]        › Error:
  5. [*]        › Error occurred: Command failed: ROOT_URL='https://mikesmallhelp-test-application-http-500-error.vercel.app/' npx playwright test --project=chromium --headed
  6. [*]        › + stderr: + stdout:
  7. [*]        › Running 1 test using 1 worker
  8. [*]        [chromium] › test.spec.ts:40:1 › test an application
  9. [*]        › In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/
  10. [*]        In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/working-page
  11. [*]        Push the button #1
  12. [*]        Filling the #1 text input field a value: 4trK*edD
  13. [*]        The #1 drop-down list. Selecting the option #2
  14. [*]        Push the button #1
  15. [*]        In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500
  16. [*]        Push the button #1
  17. [*]        In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500: Request to https://mikesmallhelp-test-application-http-500-error.vercel.app/api/http-500 resulted
  18. [*]        › in status code 500
  19. [*]        In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500: Found an error message in the browser's console: Failed to load resource: the server responded
  20. [*]        › with a status of 500 ()
  21. [*]        In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500: Found an error message in the browser's console: Error fetching data: Error: Network response was
  22. [*]        › not ok
  23. [*]        › at r (https://mikesmallhelp-test-application-http-500-error.vercel.app/_next/static/chunks/pages/api-returns-http-500-d6a108dd102494f7.js:1:1402)
  24. [*]        › at async n (https://mikesmallhelp-test-application-http-500-error.vercel.app/_next/static/chunks/pages/api-returns-http-500-d6a108dd102494f7.js:1:735)
  25. [*]        1) [chromium] › test.spec.ts:40:1 › test an application ──────────────────────────────────────────
  26. [*]        ›
  27. [*]        › AssertionError: In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500: Request to
  28. [*]        › https://mikesmallhelp-test-application-http-500-error.vercel.app/api/http-500 resulted in status code 500
  29. [*]        ›
  30. [*]        › 51 |
  31. [*]        › 52 | if (!bypassHttpErrors) {
  32. [*]        › > 53 | fail(message);
  33. [*]        › | ^
  34. [*]        › 54 | }
  35. [*]        › 55 | }
  36. [*]        › 56 | });
  37. [*]        ›
  38. [*]        › at Page.<anonymous> (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:53:17)
  39. [*]        ›
  40. [*]        1 failed
  41. [*]        › [chromium] › test.spec.ts:40:1 › test an application
  42. [/list]
  43. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2M1ZWFjZWJmYTE1NzFlNDYzN2VmYTZmYzFiNmQ3ODYwLnBuZw==[/img][/align]
  44. 因此,wacat 会检测到 HTTP 500 错误,打印错误日记,表现文本 "1 failed" 并克制实行。详细的错误信息是:
  45. [code]
复制代码

  •         AssertionError: In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500: Request to 
  •          ›   https://mikesmallhelp-test-application-http-500-error.vercel.app/api/http-500 resulted in status code 500
如果您想绕过 HTTP 错误时克制实行的举动,请利用 --bypass-http-errors 标记。比方,以下下令:
  1. wacat test --bypass-http-errors https://mikesmallhelp-test-application-http-500-error.vercel.app/
复制代码
实行不会像上一个示例那样因 HTTP 500 错误而克制。wacat 会将 HTTP 500 错误打印到日记中,但实行会继续举行。
从目标应用步调的页面检测错误字符串

这是一个示例应用步调,此中一个子页面包罗错误文本 "Error occurred!":

在我们的示例中,我们设置 wacat 检测到 "Error occurred!"。我们还渴望检测到错误文本 "abc"。我们在 JSON 文件中举行如下设置:
  1. [/code][list=1]
  2. [*]        {
  3. [*]            "errorTextsInPages": ["abc", "Error occurred!"]
  4. [*]        }
  5. [/list]在 Windows 上运行下令(利用 --conf 标记通报 JSON 文件):
  6. [code]
  7. wacat test --conf example-files\configuration-error-texts.json https://mikesmallhelp-test-application-error-in-page.vercel.app
复制代码
在 Linux 和 Mac上运行下令:
  1. wacat test --conf example-files/configuration-error-texts.json https://mikesmallhelp-test-application-error-in-page.vercel.app
复制代码
下令的输出是:
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application-error-in-page.vercel.app. Please wait...
  3. [*]
  4. [*]        › Error:
  5. [*]        › Error occurred: Command failed: ROOT_URL='https://mikesmallhelp-test-application-error-in-page.vercel.app' CONFIGURATION_FILE_PATH=example-files/configuration-error-texts.json WAIT=2000 npx
  6. [*]        › playwright test --project=chromium --headed
  7. [*]        › + stderr: + stdout:
  8. [*]        › Running 1 test using 1 worker
  9. [*]        [chromium] › test.spec.ts:40:1 › test an application
  10. [*]        › In the page: https://mikesmallhelp-test-application-error-in-page.vercel.app/
  11. [*]        Check the page not contain the abc text
  12. [*]        Check the page not contain the Error occurred! text
  13. [*]        In the page: https://mikesmallhelp-test-application-error-in-page.vercel.app/error-text-in-page
  14. [*]        Check the page not contain the abc text
  15. [*]        Check the page not contain the Error occurred! text
  16. [*]        1) [chromium] › test.spec.ts:40:1 › test an application ──────────────────────────────────────────
  17. [*]        ›
  18. [*]        › Error: expect(received).not.toContain(expected) // indexOf
  19. [*]        ›
  20. [*]        › Expected substring: not "Error occurred!"
  21. [*]        › Received string: "Test page - error-text-in-pageError occurred!{"props":{"pageProps":{}},"page":"/error-text-in-page","query":{},"buildId":"MVBwm9bMplVdAQ-ZjLXZ5","nextExp
  22. [*]        › ort":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}"
  23. [*]        ›
  24. [*]        › 150 | for (const errorText of configuration.errorTextsInPages) {
  25. [*]        › 151 | console.log(`Check the page not contain the ${errorText} text`);
  26. [*]        › > 152 | expect(content).not.toContain(errorText);
  27. [*]        › | ^
  28. [*]        › 153 | }
  29. [*]        › 154 | }
  30. [*]        › 155 |
  31. [*]        ›
  32. [*]        › at checkPageForErrors (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:152:29)
  33. [*]        › at handlePage (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:122:5)
  34. [*]        › at visitLinks (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:398:13)
  35. [*]        › at handlePage (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:132:5)
  36. [*]        › at /home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:73:5
  37. [*]        ›
  38. [*]        1 failed
  39. [*]        › [chromium] › test.spec.ts:40:1 › test an application
  40. [/list]
  41. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0LzIxZjA0MzkzNjJlYTA0OTA2NTUzMjdhMGIyNWQ2Mjk4LnBuZw==[/img][/align]
  42. wacat 在一个子页面中检测到 "Error occurred!" 文本,陈诉错误并表现 "1 failed" 文本,实行克制。
  43. [size=2]检测欣赏器控制台中的错误[/size]
  44. 这是一个示例应用步调,此中包罗在欣赏器控制台中的错误日记纪录:
  45. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvOTBlYmRiZTljNjZiNDNhMjg5Y2ZmYzlkNjY0ODgyOTQucG5n[/img][/align]
  46. 示例下令
  47. [code]
  48. wacat test https://mikesmallhelp-test-application-error-in-browser-console.vercel.app
复制代码
实行克制在欣赏器控制台中的错误日记纪录处:
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app. Please wait...
  3. [*]
  4. [*]        › Error:
  5. [*]        › Error occurred: Command failed: ROOT_URL='https://mikesmallhelp-test-application-error-in-browser-console.vercel.app' WAIT=2000 npx playwright test --project=chromium --headed
  6. [*]        › + stderr: + stdout:
  7. [*]        › Running 1 test using 1 worker
  8. [*]        [chromium] › test.spec.ts:40:1 › test an application
  9. [*]        › In the page: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app/
  10. [*]        In the page: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app/working-page
  11. [*]        Push the button #1
  12. [*]        Filling the #1 text input field a value: q52<<r`k`bZzP<Jua#53RAn)cKg0&K14
  13. [*]        The #1 drop-down list. Selecting the option #2
  14. [*]        Push the button #1
  15. [*]        In the page: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app/error-in-browser-console: Found an error message in the browser's console: Hello! Something wrong!
  16. [*]        1) [chromium] › test.spec.ts:40:1 › test an application ──────────────────────────────────────────
  17. [*]        ›
  18. [*]        › AssertionError: In the page: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app/error-in-browser-console: Found an error message in the browser's console: Hello!
  19. [*]        › Something wrong!
  20. [*]        ›
  21. [*]        › 62 |
  22. [*]        › 63 | if (!bypassBrowserConsoleErrors && !bypassHttpErrors) {
  23. [*]        › > 64 | fail(message);
  24. [*]        › | ^
  25. [*]        › 65 | }
  26. [*]        › 66 | }
  27. [*]        › 67 | });
  28. [*]        ›
  29. [*]        › at Page.<anonymous> (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:64:17)
  30. [*]        ›
  31. [*]        1 failed
  32. [*]        › [chromium] › test.spec.ts:40:1 › test an application
  33. [/list]
  34. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2FlMmRlNzkxMDc2MWE0ODRkZjA2N2I3ZDJlMzg3OTRlLnBuZw==[/img][/align]
  35. wacat 打印消息 "Found an error message in the browser's console: Hello! Something wrong!" 并克制实行。
  36. 如果您想绕过此查抄并继续实行,请利用 --bypass-browser-console-errors 标记。以下下令:
  37. [code]
  38. wacat test --bypass-browser-console-errors https://mikesmallhelp-test-application-error-in-browser-console.vercel.app
复制代码
不会像上一个示例那样克制。wacat 会纪录错误消息,但继续实行。
设置随机表单输入

通常,wacat 会天生随机的表单输入。默认情况下,长度在 1 到 60 个字符之间,并利用默认字符集。利用 --random-input-texts-min-length 标记指定最小长度,利用 --random-input-texts-max-length 标记指定最大长度。利用 --random-input-texts-charset 标记指定字符集。示例下令和输出如下:
  1. wacat test --random-input-texts-min-length 1 --random-input-texts-max-length 3 --random-input-texts-charset ®©¥¬¿ https://mikesmallhelp-test-application.vercel.app/
复制代码
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
  3. [*]
  4. [*]
  5. [*]        Running 1 test using 1 worker
  6. [*]        [chromium] › test.spec.ts:41:1 › test an application
  7. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/
  8. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page
  9. [*]        Push the button #1
  10. [*]        Filling the #1 text input field a value: ®
  11. [*]        Filling the #2 text input field a value: ®
  12. [*]        Filling the #3 text input field a value: ®
  13. [*]        Filling the #4 text input field a value: ®
  14. [*]        Filling the #5 text input field a value: ®
  15. [*]        Filling the #6 text input field a value: ®
  16. [*]        The #1 drop-down list. Selecting the option #2
  17. [*]        Selecting the #1 checkbox
  18. [*]        The #1 radio button group. Selecting the radio button #3
  19. [*]        Push the button #1
  20. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
  21. [*]        Push the button #1
  22. [*]        Filling the #1 text input field a value: ®
  23. [*]        Filling the #2 text input field a value: ®
  24. [*]        Filling the #3 text input field a value: ®
  25. [*]        Filling the #4 text input field a value: ®
  26. [*]        Filling the #5 text input field a value: ®
  27. [*]        Filling the #6 text input field a value: ®
  28. [*]        The #1 drop-down list. Selecting the option #2
  29. [*]        Selecting the #1 checkbox
  30. [*]        The #1 radio button group. Selecting the radio button #2
  31. [*]        Push the button #1
  32. [*]        1 passed (54.0s)
  33. [/list]
  34. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0LzllN2E0Y2IzMDc1OTZlZTMzYTU0OWRiOTM5MDI0NjIxLnBuZw==[/img][/align]
  35. 在这个示例中,wacat 天生随机字符串 ®,长度在 1 到 3 个字符之间,字符来自指定的字符集 ®©¥¬¿。
  36. [size=2]从文件读取输入字段文本[/size]
  37. 别的,还可以从文件中读取输入字段,比方从文件 example-files/input.texts,内容如下:
  38. [code]
复制代码

  •         xaxa
  •         ybyb
wacat 利用文件中的每个输入文本添补目标应用步调中的每个输入字段,除非发生错误或页面变革。对于当地文件,在 Windows 上运行的下令为:
  1. wacat test --input-texts example-files\input-texts.txt https://mikesmallhelp-test-application.vercel.app/ 
复制代码
在 Linux 和 Mac 上:
  1. wacat test --input-texts example-files/input-texts.txt https://mikesmallhelp-test-application.vercel.app/ 
复制代码
对于远程文件:
  1. wacat test --input-texts https://raw.githubusercontent.com/mikesmallhelp/wacat/main/example-files/input-texts.txt https://mikesmallhelp-test-application.vercel.app/
复制代码
全部的指令输出为:
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
  3. [*]
  4. [*]        Running 1 test using 1 worker
  5. [*]        [chromium] › test.spec.ts:41:1 › test an application
  6. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/
  7. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page
  8. [*]        Push the button #1
  9. [*]        Filling the #1 text input field a value: xaxa
  10. [*]        Filling the #2 text input field a value: xaxa
  11. [*]        Filling the #3 text input field a value: xaxa
  12. [*]        Filling the #4 text input field a value: xaxa
  13. [*]        Filling the #5 text input field a value: xaxa
  14. [*]        Filling the #6 text input field a value: xaxa
  15. [*]        The #1 drop-down list. Selecting the option #2
  16. [*]        Selecting the #1 checkbox
  17. [*]        The #1 radio button group. Selecting the radio button #3
  18. [*]        Push the button #1
  19. [*]        Filling the #1 text input field a value: ybyb
  20. [*]        Filling the #2 text input field a value: ybyb
  21. [*]        Filling the #3 text input field a value: ybyb
  22. [*]        Filling the #4 text input field a value: ybyb
  23. [*]        Filling the #5 text input field a value: ybyb
  24. [*]        Filling the #6 text input field a value: ybyb
  25. [*]        The #1 drop-down list. Selecting the option #2
  26. [*]        Selecting the #1 checkbox
  27. [*]        The #1 radio button group. Selecting the radio button #1
  28. [*]        Push the button #1
  29. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
  30. [*]        Push the button #1
  31. [*]        Filling the #1 text input field a value: xaxa
  32. [*]        Filling the #2 text input field a value: xaxa
  33. [*]        Filling the #3 text input field a value: xaxa
  34. [*]        Filling the #4 text input field a value: xaxa
  35. [*]        Filling the #5 text input field a value: xaxa
  36. [*]        Filling the #6 text input field a value: xaxa
  37. [*]        The #1 drop-down list. Selecting the option #2
  38. [*]        Selecting the #1 checkbox
  39. [*]        The #1 radio button group. Selecting the radio button #1
  40. [*]        Push the button #1
  41. [*]        Filling the #1 text input field a value: ybyb
  42. [*]        Filling the #2 text input field a value: ybyb
  43. [*]        Filling the #3 text input field a value: ybyb
  44. [*]        Filling the #4 text input field a value: ybyb
  45. [*]        Filling the #5 text input field a value: ybyb
  46. [*]        Filling the #6 text input field a value: ybyb
  47. [*]        The #1 drop-down list. Selecting the option #2
  48. [*]        Selecting the #1 checkbox
  49. [*]        The #1 radio button group. Selecting the radio button #3
  50. [*]        Push the button #1
  51. [*]        1 passed (1.1m)
  52. [/list]
  53. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2QzZmZhYTRkZWQwMWE2YzU3ZDM2YTA5YjVhYzQwYmE2LnBuZw==[/img][/align]
  54. 在输出中,您可以看到利用了 input-texts.txt 文件中的值。您可以利用差别的输入文本文件举行测试,比方来自页面 https://github.com/0xspade/Combined-Wordlists?tab=readme-ov-file 的文件。当您利用大输入文本文件时,请利用 --timeout 参数(详见下文),并设置富足大的值。
  55. [size=3]仅测试链接[/size]
  56. 要仅测试应用步调中的链接,请利用 --only-links 标记。此时,wacat 会加载页面并检测 HTTP 错误,但不会填写输入字段等。示例下令和输出如下:
  57. [code]
  58. wacat test --only-links https://mikesmallhelp-test-application.vercel.app/
复制代码
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
  3. [*]
  4. [*]
  5. [*]        Running 1 test using 1 worker
  6. [*]        [chromium] › test.spec.ts:40:1 › test an application
  7. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/
  8. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page
  9. [*]        In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
  10. [*]        1 passed (14.7s)
  11. [/list][size=3]登录验证[/size]
  12. 这是一个带有简只身份验证的应用步调:
  13. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvN2Y2MWZkMzVlZTg0NGQ5YWEwYjUzMzgwNDRhNGRlMmEucG5n[/img][/align]
  14. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvZDkyMzQ1MWRhZTRiNGNkYTg2NWUwZDVkNTRkM2JjNzkucG5n[/img][/align]
  15. wacat 可以利用以下 JSON 文件对该应用步调举行身份验证:
  16. [code]
复制代码

  •         {
  •             "authentication": {
  •                 "usernameLabel": "Username",
  •                 "usernameValue": "Mike",
  •                 "passwordLabel": "assword",
  •                 "passwordValue": "Smallhelp",
  •                 "loginButtonLabel": "Login"
  •             }
  •         }
请注意,比方该应用步调包罗 "Username" 标签,这个标签被放入 JSON 中 "usernameLabel" 属性的值中。用户名值为 "Mike",被放入 JSON 中 "usernameValue" 属性的值中。同样的逻辑实用于暗码输入字段。应用步调有一个名为 "Login" 的按钮,被放入 JSON 中 "loginButtonLabel" 属性的值中。
在 Windows 上的示例运行下令为:
  1. wacat test --conf example-files\configuration-authentication.json https://mikesmallhelp-test-application-simple-authentication.vercel.app/
复制代码
在 Linux 和 Mac 运行:
  1. wacat test --conf example-files/configuration-authentication.json https://mikesmallhelp-test-application-simple-authentication.vercel.app/
复制代码
下令的输出为:
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application-simple-authentication.vercel.app/. Please wait...
  3. [*]
  4. [*]
  5. [*]        Running 1 test using 1 worker
  6. [*]        [chromium] › test.spec.ts:40:1 › test an application
  7. [*]        Filled the username and the password. Pushed the authentication button
  8. [*]        In the page: https://mikesmallhelp-test-application-simple-authentication.vercel.app/
  9. [*]        In the page: https://mikesmallhelp-test-application-simple-authentication.vercel.app/working-page2
  10. [*]        Push the button #1
  11. [*]        Filling the #1 text input field a value: =_e6PF[J{u98&QI`DP
  12. [*]        The #1 drop-down list. Selecting the option #2
  13. [*]        Push the button #1
  14. [*]        In the page: https://mikesmallhelp-test-application-simple-authentication.vercel.app/working-page
  15. [*]        Push the button #1
  16. [*]        Filling the #1 text input field a value: =_e6PF[J{u98&QI`DP
  17. [*]        The #1 drop-down list. Selecting the option #2
  18. [*]        Push the button #1
  19. [*]          1 passed (24.7s)
  20. [/list]
  21. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2Q5YjVhOTExZDY2ZjUwODRmNzczODQwNGZjNTA4NmUwLnBuZw==[/img][/align]
  22. 请注意输出中的文本 "Filled the username and the password. Pushed the authentication button",这意味着 wacat 已完成身份验证。
  23. [size=2]举行更复杂的身份验证[/size]
  24. 这是一个具有更复杂身份验证的应用步调:
  25. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvM2EzNTY3ZDUwMGQ2NDBiNTg2MTY5YzQ5NjBkOTQwMmMucG5n[/img][/align]
  26. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvNzNkZDZmMmIxYzk2NDE2NDlmODljZWNkMTQzMzNlMDEucG5n[/img][/align]
  27. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvMzJhY2U1MWE1YTM3NGNjZDk2ODYyODJjODM5ZWQ0ODMucG5n[/img][/align]
  28. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvYmJlYmVhMmJkYTU1NDgzZWEyNGNmYjdjNGY1NDMzODQucG5n[/img][/align]
  29. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvMDhlYzI5NjYwZjY3NDA3M2E3MTUyMWMwM2U4YjQ5YzkucG5n[/img][/align]
  30. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvZjYzNzAyZmY0Yjc1NDk4MzkyNzM5Y2RhNjVmYjQ2YzAucG5n[/img][/align]
  31. wacat 可以利用以下 JSON 文件对该应用步调举行身份验证:
  32. [code]
复制代码

  •         {
  •             "authentication": {
  •                 "beforeAuthenticationLinkTexts": [
  •                     "lease go to an application",
  •                     "lease login"
  •                 ],
  •                 "usernameLabel": "Username",
  •                 "usernameValue": "Mike",
  •                 "usernameButtonLabel": "Next",
  •                 "passwordLabel": "assword",
  •                 "passwordValue": "Smallhelp",
  •                 "loginButtonLabel": "Login"
  •             }
  •         }
这个 JSON 比前一个示例更复杂。它包罗 "beforeAuthenticationLinkTexts" 属性,此中包罗 "lease go to an application" 和 "lease login" 链接文本,这些文本出如今身份验证页面之前的页面中。应用步调在输入用户名的页面中有一个 "Next" 按钮。"Next" 的值被放入 JSON 中 "usernameButtonLabel" 属性的值中。
在 Windows 上的示例运行下令为:
  1. wacat test --conf example-files\configuration-complicated-authentication.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码
在 Linux 和 Mac 运行:
  1. wacat test --conf example-files/configuration-complicated-authentication.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码
输出为:
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/. Please wait...
  3. [*]
  4. [*]
  5. [*]        Running 1 test using 1 worker
  6. [*]        [chromium] › test.spec.ts:40:1 › test an application
  7. [*]        Filled the username and the password. Pushed the authentication button
  8. [*]        In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
  9. [*]        In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page
  10. [*]        Push the button #1
  11. [*]        Filling the #1 text input field a value: Agc-QmUBS,Z]zx,~q*:ZNX*?L
  12. [*]        The #1 drop-down list. Selecting the option #2
  13. [*]        Push the button #1
  14. [*]        In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page2
  15. [*]        Push the button #1
  16. [*]        Filling the #1 text input field a value: Agc-QmUBS,Z]zx,~q*:ZNX*?L
  17. [*]        The #1 drop-down list. Selecting the option #2
  18. [*]        Push the button #1
  19. [*]       
  20. In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout
  21. [*]          1 passed (28.7s)
  22. [/list]
  23. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2M4MGE3YjI1NzllZWY5YmY2NjczOTc0MTI1NTI2MGYwLnBuZw==[/img][/align]
  24. [size=2]设置不访问的页面[/size]
  25. wacat 筹划为不超出您正在测试的主机范围。您还可以设置更多不访问的页面 URL。
  26. 检察前一个示例:
  27. [code]
  28. In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout
复制代码
如果您不想进入登出页面,可以在 JSON 中添加 "notVisitLinkUrls" 属性。该属性包罗不访问的 URL。示例 JSON 如下:
  1. [/code][list=1]
  2. [*]        {
  3. [*]            "authentication": {
  4. [*]                "beforeAuthenticationLinkTexts": [
  5. [*]                    "Please go to an application",
  6. [*]                    "Please login"
  7. [*]                ],
  8. [*]                "usernameLabel": "Username",
  9. [*]                "usernameValue": "Mike",
  10. [*]                "usernameButtonLabel": "Next",
  11. [*]                "passwordLabel": "Password",
  12. [*]                "passwordValue": "Smallhelp",
  13. [*]                "loginButtonLabel": "Login"
  14. [*]            },
  15. [*]            "notVisitLinkUrls": [
  16. [*]                "https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout"
  17. [*]            ]
  18. [*]        }
  19. [/list]
  20. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0Lzk4NzU5ZmMyMDk5MjNiNTE1NGVmNzMxNzJjOThjMDI2LnBuZw==[/img][/align]
  21. 在 Windows 上的示例运行下令为:
  22. [code]
  23. wacat test --conf example-files/configuration-complicated-authentication-with-not-visit-link-urls-remote.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码
在 Linux 和 Mac 上的运行下令为:
  1. wacat test --conf example-files/configuration-complicated-authentication-with-not-visit-link-urls-remote.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码
下令输出为:
  1. [/code][list=1]
  2. [*]        Testing in url: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/. Please wait...
  3. [*]
  4. [*]        Running 1 test using 1 worker
  5. [*]        [chromium] › test.spec.ts:40:1 › test an application
  6. [*]        Filled the username and the password. Pushed the authentication button
  7. [*]        In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
  8. [*]        In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page2
  9. [*]        Push the button #1
  10. [*]        Filling the #1 text input field a value: R?nSk,UP(UBO*t'm1^a^7HIv
  11. [*]        The #1 drop-down list. Selecting the option #2
  12. [*]        Push the button #1
  13. [*]        In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page
  14. [*]        Push the button #1
  15. [*]        Filling the #1 text input field a value: R?nSk,UP(UBO*t'm1^a^7HIv
  16. [*]        The #1 drop-down list. Selecting the option #2
  17. [*]        Push the button #1
  18. [*]          1 passed (23.2s)
  19. [/list]
  20. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0Lzk4NzU5ZmMyMDk5MjNiNTE1NGVmNzMxNzJjOThjMDI2LnBuZw==[/img][/align]
  21. 请注意,输出中不再有以下行:
  22. [code]
  23. In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout
复制代码
以无头模式运行

利用 --headless 标记以无头模式(无欣赏器)运行。示例下令如下:
  1. wacat test --headless https://mikesmallhelp-test-application.vercel.app/
复制代码
在 CI 管道中运行

wacat 可以在 CI 管道中利用 --headless 标记运行。
设置等候时间

默认情况下,wacat 每个页面下载等候时间为 5000 毫秒。利用 --wait 标记以毫秒为单元设置页面下载等候时间。2000 毫秒等候时间的示例下令如下:
  1. wacat test --wait 2000 https://mikesmallhelp-test-application.vercel.app/
复制代码
注意:wacat 内部利用 Playwright 工具。通常情况下,Playwright 测试可以等候一些特定的文本。但 wacat 不知道要等候什么文本,因此利用等候时间。
设置整个测试的超时时间

默认情况下,整个测试下令的超时时间为 120 秒。利用 --timeout 标记以秒为单元设置整个测试的超时时间。超时时间值至少为 1 秒。50 秒超时时间的示例下令如下:
  1. wacat test --timeout 50 https://mikesmallhelp-test-application.vercel.app/
复制代码
注意:Playwright 内部利用的是毫秒。以是如果在这个示例中发生超时,输出会类似于:
  1. Test timeout of 50000ms exceeded.
复制代码
Help 指令

To see all the flags, run the command:
  1. wacat test --help
复制代码
  1. [/code][list=1]
  2. [*]        Test any web application, for example: wacat test http://localhost:3000
  3. [*]
  4. [*]        USAGE
  5. [*]          $ wacat test URL [--bypass-browser-console-errors] [--bypass-http-errors] [--conf <value>] [--debug] [--headless] [--input-texts <value>] [--only-links] [--random-input-texts-charset
  6. [*]            <value>] [--random-input-texts-max-length <value>] [--random-input-texts-min-length <value>] [--timeout <value>] [--wait <value>]
  7. [*]
  8. [*]        ARGUMENTS
  9. [*]          URL  Application url to test, for example: http://localhost:3000
  10. [*]
  11. [*]        FLAGS
  12. [*]          --bypass-browser-console-errors          Bypass the browser console's error messages
  13. [*]          --bypass-http-errors                     Bypass the HTTP errors
  14. [*]          --conf=<value>                           Path to the configuration file
  15. [*]          --debug                                  Enable debug mode
  16. [*]          --headless                               Headless mode
  17. [*]          --input-texts=<value>                    Path to the input texts file
  18. [*]          --only-links                             Test only links
  19. [*]          --random-input-texts-charset=<value>     Random input texts character set
  20. [*]          --random-input-texts-max-length=<value>  Random input texts max length
  21. [*]          --random-input-texts-min-length=<value>  Random input texts min length
  22. [*]          --timeout=<value>                        A whole test run timeout in seconds
  23. [*]          --wait=<value>                           A wait in milliseconds to wait a page load
  24. [*]
  25. [*]        DESCRIPTION
  26. [*]          Test any web application, for example: wacat test http://localhost:3000
  27. [*]
  28. [*]        EXAMPLES
  29. [*]          $ wacat test http://localhost:3000
  30. [/list]
  31. [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0Lzc0NTQxMGYyMDFiYjZlNzYzZmZjMTQ3NzVhMzE3Nzg3LnBuZw==[/img][/align]
  32. [size=3]开发 wacat[/size]
  33. [size=2]利用技能[/size]
  34. wacat 利用以下的一些技能:
  35. [list]
  36. [*]        • Typescript
  37. [*]        • Bash script
  38. [*]        • oclif, The Open CLI Framework
  39. [*]        • Playwright
  40. [*]        • Next.js for the test applications
  41. [/list][size=2]开发指引[/size]
  42. 在 Linux 和 Mac 上,举行更改并运行
  43. [code]
  44. npm run test && npm run build && npm install -g && ./run-tests.sh
复制代码
run-tests.sh 脚本会运行全部测试用例,并验证 wacat 是否正常工作。大概,只需将更改推送到代码库,让 GitHub Actions 运行测试。
在 Windows 上,举行更改并运行
  1. npm run test && npm run build && npm install -g
复制代码
对于 Windows,如今还没有像 ./run-tests.sh 如许的自动测试脚本。运行
  1. run-manual-tests.bat
复制代码
并从输出中验证统统是否正常。
贡献

我们热烈接待各种情势的贡献。请检察题目页面。如果发现 bug 或须要某个特定功能,请创建一个新的 issue。
请注意:如果您添加了新功能,请为其添加测试用例。请检察 run-tests.sh 文件。还请思量添加单元测试。
Change history

1.1.0 16.4.2024


  •         • can derive the text input type from the label and generates an appropriate random content for the input field

    •                 • supports derivation from different email and date labels

1.0.0 23.3.2024


  •         • Windows support
  •         • support for the most typical html input types like radio, email etc.
  •         • more flags like --random-input-texts-charset
  •         • bug fixes
  •         • GitHub Actions tests for Mac
引用链接

[1] Playwright: https://playwright.dev/
[2] 安装 Node.js 官方指引: https://nodejs.org/en
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表