马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
想象一下,你离开电脑一会儿去拿一杯咖啡。与此同时,你的猫走过键盘,引发了一些紊乱。
wacat 应用步调:
- • 访问你的网页应用的根网址
- • 随机访问应用中的每个链接
- • 在表单中添加随机文本输入
- • 从下拉菜单、复选框等中选择随机值
- • 随机序次点击每个按钮
别的,wacat 还可以:
- • 检测欣赏器与服务器之间的 HTTP 错误(比方 HTTP 500 错误)
- • 检测欣赏器控制台日记中的错误
- • 从网页中检测错误字符串
- • 支持用户设置随机表单文本输入
- • 可以从外部文件读取表单输入
- • 可以仅测试链接,这可以用于应用步调的烟雾测试
- • 支持某些身份验证场景
- • 支持设置不访问的页面
- • 支持无头模式
- • 支持设置页面下载等候时间和整个测试的超时值
- • 支持在 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 目次而且运行:- npm install && npx playwright install --with-deps && npm run build && npm i -g
复制代码 注意:由于 Playwright 工具是全局安装的,因此在运行前面的下令时大概会要求输入暗码。
更新 wacat
更新 wacat 版本的指令:- git pull &&
- npm install && npx playwright install --with-deps && npm run build && npm i -g
复制代码 运行
Basic running
在 wacat 文件夹中运行以下下令:比方:- wacat test https://mikesmallhelp-test-application.vercel.app/
复制代码 在 URL https://mikesmallhelp-test-application.vercel.app/ 中测试一个简朴的应用步调。该应用步调包罗以下页面:
起首,wacat 应用步调会打开 Chromium 欣赏器并访问下令中提供的根 URL:
根页面不包罗任何输入字段、下拉菜单等。wacat 简朴地网络两个子页面的链接并访问它们。在每个子页面中,wacat 起首点击按钮,然后填写表单输入,选择下拉菜单项等,末了再次点击按钮。以下是您可以复制、粘贴并运行的下令。同样,您可以运行全部其他示例,并请随意利用我的测试应用步调。- wacat test https://mikesmallhelp-test-application.vercel.app/
复制代码- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
- [*]
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:41:1 › test an application
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
- [*] Push the button #1
- [*] Filling the #1 text input field a value: _k6AKNU3z"{=myqS.K
- [*] The label is 'Your Date of Birth Here', so generating an appropriate random content for the input field
- [*] Filling the #2 text input field a value: 16/09/2004
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #3
- [*] Filling the #1 email input field a value: [email protected]
- [*] Filling the #1 password input field a value: A#1!!a#!#AaA!A
- [*] Filling the #1 search input field a value: SZOmqATkrV
- [*] Filling the #1 url input field a value: https://nrebn.com
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: _k6AKNU3z"{=myqS.K
- [*] The label is 'Your Date of Birth Here', so generating an appropriate random content for the input field
- [*] Filling the #2 text input field a value: 16/09/2004
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #2
- [*] Filling the #1 email input field a value: [email protected]
- [*] Filling the #1 password input field a value: aa2B#1aA!##2A#!AaA
- [*] Filling the #1 search input field a value: lSjsBVOzkhCC
- [*] Filling the #1 url input field a value: https://vpo7ut.net
- [*] Push the button #1
- [*] 1 passed (24.3s)
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2UwODVhNTczZmI2ODg4NDY0ODFjZWRlNjVkNmNiMjdiLnBuZw==[/img][/align]
- 请注意,输出包罗“1 passed”,因此 wacat 没有在应用步调中发现任何错误。别的,请注意,每个页面的默认等候时间为 5000 毫秒。如果您想更改此时间,请利用 --wait 标记(详见后文)。
- [size=2]检测 HTTP 错误[/size]
- wacat 可以检测欣赏器和服务器之间的 HTTP 错误。比方,如果在下面的示例应用步调中点击按钮,会出现 HTTP 500 错误。
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvODhmZGRhMWI4YWQwNDkxMmI3OTYxMzhlZTIzYjBjYjkucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvOWZiYTZkOTgyN2IyNDQ2M2I1NjA2NDJlNjE3Y2ZmNDQucG5n[/img][/align]
- 比方:
- [code]
- wacat test https://mikesmallhelp-test-application-http-500-error.vercel.app/
复制代码- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application-http-500-error.vercel.app/. Please wait...
- [*]
- [*] › Error:
- [*] › Error occurred: Command failed: ROOT_URL='https://mikesmallhelp-test-application-http-500-error.vercel.app/' npx playwright test --project=chromium --headed
- [*] › + stderr: + stdout:
- [*] › Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] › In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: 4trK*edD
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application-http-500-error.vercel.app/api-returns-http-500
- [*] Push the button #1
- [*] 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
- [*] 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
- [*] › with a status of 500 ()
- [*] 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
- [*] › not ok
- [*] › at r (https://mikesmallhelp-test-application-http-500-error.vercel.app/_next/static/chunks/pages/api-returns-http-500-d6a108dd102494f7.js:1:1402)
- [*] › at async n (https://mikesmallhelp-test-application-http-500-error.vercel.app/_next/static/chunks/pages/api-returns-http-500-d6a108dd102494f7.js:1:735)
- [*] 1) [chromium] › test.spec.ts:40:1 › test an application ──────────────────────────────────────────
- [*] ›
- [*] › 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
- [*] ›
- [*] › 51 |
- [*] › 52 | if (!bypassHttpErrors) {
- [*] › > 53 | fail(message);
- [*] › | ^
- [*] › 54 | }
- [*] › 55 | }
- [*] › 56 | });
- [*] ›
- [*] › at Page.<anonymous> (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:53:17)
- [*] ›
- [*] 1 failed
- [*] › [chromium] › test.spec.ts:40:1 › test an application
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2M1ZWFjZWJmYTE1NzFlNDYzN2VmYTZmYzFiNmQ3ODYwLnBuZw==[/img][/align]
- 因此,wacat 会检测到 HTTP 500 错误,打印错误日记,表现文本 "1 failed" 并克制实行。详细的错误信息是:
- [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 标记。比方,以下下令:- 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 文件中举行如下设置:- [/code][list=1]
- [*] {
- [*] "errorTextsInPages": ["abc", "Error occurred!"]
- [*] }
- [/list]在 Windows 上运行下令(利用 --conf 标记通报 JSON 文件):
- [code]
- wacat test --conf example-files\configuration-error-texts.json https://mikesmallhelp-test-application-error-in-page.vercel.app
复制代码 在 Linux 和 Mac上运行下令:- wacat test --conf example-files/configuration-error-texts.json https://mikesmallhelp-test-application-error-in-page.vercel.app
复制代码 下令的输出是:- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application-error-in-page.vercel.app. Please wait...
- [*]
- [*] › Error:
- [*] › 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
- [*] › playwright test --project=chromium --headed
- [*] › + stderr: + stdout:
- [*] › Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] › In the page: https://mikesmallhelp-test-application-error-in-page.vercel.app/
- [*] Check the page not contain the abc text
- [*] Check the page not contain the Error occurred! text
- [*] In the page: https://mikesmallhelp-test-application-error-in-page.vercel.app/error-text-in-page
- [*] Check the page not contain the abc text
- [*] Check the page not contain the Error occurred! text
- [*] 1) [chromium] › test.spec.ts:40:1 › test an application ──────────────────────────────────────────
- [*] ›
- [*] › Error: expect(received).not.toContain(expected) // indexOf
- [*] ›
- [*] › Expected substring: not "Error occurred!"
- [*] › Received string: "Test page - error-text-in-pageError occurred!{"props":{"pageProps":{}},"page":"/error-text-in-page","query":{},"buildId":"MVBwm9bMplVdAQ-ZjLXZ5","nextExp
- [*] › ort":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}"
- [*] ›
- [*] › 150 | for (const errorText of configuration.errorTextsInPages) {
- [*] › 151 | console.log(`Check the page not contain the ${errorText} text`);
- [*] › > 152 | expect(content).not.toContain(errorText);
- [*] › | ^
- [*] › 153 | }
- [*] › 154 | }
- [*] › 155 |
- [*] ›
- [*] › at checkPageForErrors (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:152:29)
- [*] › at handlePage (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:122:5)
- [*] › at visitLinks (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:398:13)
- [*] › at handlePage (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:132:5)
- [*] › at /home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:73:5
- [*] ›
- [*] 1 failed
- [*] › [chromium] › test.spec.ts:40:1 › test an application
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0LzIxZjA0MzkzNjJlYTA0OTA2NTUzMjdhMGIyNWQ2Mjk4LnBuZw==[/img][/align]
- wacat 在一个子页面中检测到 "Error occurred!" 文本,陈诉错误并表现 "1 failed" 文本,实行克制。
- [size=2]检测欣赏器控制台中的错误[/size]
- 这是一个示例应用步调,此中包罗在欣赏器控制台中的错误日记纪录:
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvOTBlYmRiZTljNjZiNDNhMjg5Y2ZmYzlkNjY0ODgyOTQucG5n[/img][/align]
- 示例下令
- [code]
- wacat test https://mikesmallhelp-test-application-error-in-browser-console.vercel.app
复制代码 实行克制在欣赏器控制台中的错误日记纪录处:- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app. Please wait...
- [*]
- [*] › Error:
- [*] › Error occurred: Command failed: ROOT_URL='https://mikesmallhelp-test-application-error-in-browser-console.vercel.app' WAIT=2000 npx playwright test --project=chromium --headed
- [*] › + stderr: + stdout:
- [*] › Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] › In the page: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application-error-in-browser-console.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: q52<<r`k`bZzP<Jua#53RAn)cKg0&K14
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] 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!
- [*] 1) [chromium] › test.spec.ts:40:1 › test an application ──────────────────────────────────────────
- [*] ›
- [*] › 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!
- [*] › Something wrong!
- [*] ›
- [*] › 62 |
- [*] › 63 | if (!bypassBrowserConsoleErrors && !bypassHttpErrors) {
- [*] › > 64 | fail(message);
- [*] › | ^
- [*] › 65 | }
- [*] › 66 | }
- [*] › 67 | });
- [*] ›
- [*] › at Page.<anonymous> (/home/lenovo/projektit/wacat/e2e-tests/test.spec.ts:64:17)
- [*] ›
- [*] 1 failed
- [*] › [chromium] › test.spec.ts:40:1 › test an application
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2FlMmRlNzkxMDc2MWE0ODRkZjA2N2I3ZDJlMzg3OTRlLnBuZw==[/img][/align]
- wacat 打印消息 "Found an error message in the browser's console: Hello! Something wrong!" 并克制实行。
- 如果您想绕过此查抄并继续实行,请利用 --bypass-browser-console-errors 标记。以下下令:
- [code]
- 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 标记指定字符集。示例下令和输出如下:- wacat test --random-input-texts-min-length 1 --random-input-texts-max-length 3 --random-input-texts-charset ®©¥¬¿ https://mikesmallhelp-test-application.vercel.app/
复制代码- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
- [*]
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:41:1 › test an application
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: ®
- [*] Filling the #2 text input field a value: ®
- [*] Filling the #3 text input field a value: ®
- [*] Filling the #4 text input field a value: ®
- [*] Filling the #5 text input field a value: ®
- [*] Filling the #6 text input field a value: ®
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #3
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
- [*] Push the button #1
- [*] Filling the #1 text input field a value: ®
- [*] Filling the #2 text input field a value: ®
- [*] Filling the #3 text input field a value: ®
- [*] Filling the #4 text input field a value: ®
- [*] Filling the #5 text input field a value: ®
- [*] Filling the #6 text input field a value: ®
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #2
- [*] Push the button #1
- [*] 1 passed (54.0s)
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0LzllN2E0Y2IzMDc1OTZlZTMzYTU0OWRiOTM5MDI0NjIxLnBuZw==[/img][/align]
- 在这个示例中,wacat 天生随机字符串 ®,长度在 1 到 3 个字符之间,字符来自指定的字符集 ®©¥¬¿。
- [size=2]从文件读取输入字段文本[/size]
- 别的,还可以从文件中读取输入字段,比方从文件 example-files/input.texts,内容如下:
- [code]
复制代码 wacat 利用文件中的每个输入文本添补目标应用步调中的每个输入字段,除非发生错误或页面变革。对于当地文件,在 Windows 上运行的下令为:- wacat test --input-texts example-files\input-texts.txt https://mikesmallhelp-test-application.vercel.app/
复制代码 在 Linux 和 Mac 上:- wacat test --input-texts example-files/input-texts.txt https://mikesmallhelp-test-application.vercel.app/
复制代码 对于远程文件:- wacat test --input-texts https://raw.githubusercontent.com/mikesmallhelp/wacat/main/example-files/input-texts.txt https://mikesmallhelp-test-application.vercel.app/
复制代码 全部的指令输出为:- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:41:1 › test an application
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: xaxa
- [*] Filling the #2 text input field a value: xaxa
- [*] Filling the #3 text input field a value: xaxa
- [*] Filling the #4 text input field a value: xaxa
- [*] Filling the #5 text input field a value: xaxa
- [*] Filling the #6 text input field a value: xaxa
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #3
- [*] Push the button #1
- [*] Filling the #1 text input field a value: ybyb
- [*] Filling the #2 text input field a value: ybyb
- [*] Filling the #3 text input field a value: ybyb
- [*] Filling the #4 text input field a value: ybyb
- [*] Filling the #5 text input field a value: ybyb
- [*] Filling the #6 text input field a value: ybyb
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #1
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
- [*] Push the button #1
- [*] Filling the #1 text input field a value: xaxa
- [*] Filling the #2 text input field a value: xaxa
- [*] Filling the #3 text input field a value: xaxa
- [*] Filling the #4 text input field a value: xaxa
- [*] Filling the #5 text input field a value: xaxa
- [*] Filling the #6 text input field a value: xaxa
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #1
- [*] Push the button #1
- [*] Filling the #1 text input field a value: ybyb
- [*] Filling the #2 text input field a value: ybyb
- [*] Filling the #3 text input field a value: ybyb
- [*] Filling the #4 text input field a value: ybyb
- [*] Filling the #5 text input field a value: ybyb
- [*] Filling the #6 text input field a value: ybyb
- [*] The #1 drop-down list. Selecting the option #2
- [*] Selecting the #1 checkbox
- [*] The #1 radio button group. Selecting the radio button #3
- [*] Push the button #1
- [*] 1 passed (1.1m)
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2QzZmZhYTRkZWQwMWE2YzU3ZDM2YTA5YjVhYzQwYmE2LnBuZw==[/img][/align]
- 在输出中,您可以看到利用了 input-texts.txt 文件中的值。您可以利用差别的输入文本文件举行测试,比方来自页面 https://github.com/0xspade/Combined-Wordlists?tab=readme-ov-file 的文件。当您利用大输入文本文件时,请利用 --timeout 参数(详见下文),并设置富足大的值。
- [size=3]仅测试链接[/size]
- 要仅测试应用步调中的链接,请利用 --only-links 标记。此时,wacat 会加载页面并检测 HTTP 错误,但不会填写输入字段等。示例下令和输出如下:
- [code]
- wacat test --only-links https://mikesmallhelp-test-application.vercel.app/
复制代码- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application.vercel.app/. Please wait...
- [*]
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page
- [*] In the page: https://mikesmallhelp-test-application.vercel.app/working-page2
- [*] 1 passed (14.7s)
- [/list][size=3]登录验证[/size]
- 这是一个带有简只身份验证的应用步调:
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvN2Y2MWZkMzVlZTg0NGQ5YWEwYjUzMzgwNDRhNGRlMmEucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvZDkyMzQ1MWRhZTRiNGNkYTg2NWUwZDVkNTRkM2JjNzkucG5n[/img][/align]
- wacat 可以利用以下 JSON 文件对该应用步调举行身份验证:
- [code]
复制代码
- {
- "authentication": {
- "usernameLabel": "Username",
- "usernameValue": "Mike",
- "passwordLabel": "
assword",
- "passwordValue": "Smallhelp",
- "loginButtonLabel": "Login"
- }
- }
请注意,比方该应用步调包罗 "Username" 标签,这个标签被放入 JSON 中 "usernameLabel" 属性的值中。用户名值为 "Mike",被放入 JSON 中 "usernameValue" 属性的值中。同样的逻辑实用于暗码输入字段。应用步调有一个名为 "Login" 的按钮,被放入 JSON 中 "loginButtonLabel" 属性的值中。
在 Windows 上的示例运行下令为:- wacat test --conf example-files\configuration-authentication.json https://mikesmallhelp-test-application-simple-authentication.vercel.app/
复制代码 在 Linux 和 Mac 运行:- wacat test --conf example-files/configuration-authentication.json https://mikesmallhelp-test-application-simple-authentication.vercel.app/
复制代码 下令的输出为:- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application-simple-authentication.vercel.app/. Please wait...
- [*]
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] Filled the username and the password. Pushed the authentication button
- [*] In the page: https://mikesmallhelp-test-application-simple-authentication.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application-simple-authentication.vercel.app/working-page2
- [*] Push the button #1
- [*] Filling the #1 text input field a value: =_e6PF[J{u98&QI`DP
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application-simple-authentication.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: =_e6PF[J{u98&QI`DP
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] 1 passed (24.7s)
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2Q5YjVhOTExZDY2ZjUwODRmNzczODQwNGZjNTA4NmUwLnBuZw==[/img][/align]
- 请注意输出中的文本 "Filled the username and the password. Pushed the authentication button",这意味着 wacat 已完成身份验证。
- [size=2]举行更复杂的身份验证[/size]
- 这是一个具有更复杂身份验证的应用步调:
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvM2EzNTY3ZDUwMGQ2NDBiNTg2MTY5YzQ5NjBkOTQwMmMucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvNzNkZDZmMmIxYzk2NDE2NDlmODljZWNkMTQzMzNlMDEucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvMzJhY2U1MWE1YTM3NGNjZDk2ODYyODJjODM5ZWQ0ODMucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvYmJlYmVhMmJkYTU1NDgzZWEyNGNmYjdjNGY1NDMzODQucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvMDhlYzI5NjYwZjY3NDA3M2E3MTUyMWMwM2U4YjQ5YzkucG5n[/img][/align]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pLWJsb2cuY3NkbmltZy5jbi9kaXJlY3QvZjYzNzAyZmY0Yjc1NDk4MzkyNzM5Y2RhNjVmYjQ2YzAucG5n[/img][/align]
- wacat 可以利用以下 JSON 文件对该应用步调举行身份验证:
- [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 上的示例运行下令为:- wacat test --conf example-files\configuration-complicated-authentication.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码 在 Linux 和 Mac 运行:- wacat test --conf example-files/configuration-complicated-authentication.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码 输出为:- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/. Please wait...
- [*]
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] Filled the username and the password. Pushed the authentication button
- [*] In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: Agc-QmUBS,Z]zx,~q*:ZNX*?L
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page2
- [*] Push the button #1
- [*] Filling the #1 text input field a value: Agc-QmUBS,Z]zx,~q*:ZNX*?L
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*]
- In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout
- [*] 1 passed (28.7s)
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0L2M4MGE3YjI1NzllZWY5YmY2NjczOTc0MTI1NTI2MGYwLnBuZw==[/img][/align]
- [size=2]设置不访问的页面[/size]
- wacat 筹划为不超出您正在测试的主机范围。您还可以设置更多不访问的页面 URL。
- 检察前一个示例:
- [code]
- In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout
复制代码 如果您不想进入登出页面,可以在 JSON 中添加 "notVisitLinkUrls" 属性。该属性包罗不访问的 URL。示例 JSON 如下:- [/code][list=1]
- [*] {
- [*] "authentication": {
- [*] "beforeAuthenticationLinkTexts": [
- [*] "Please go to an application",
- [*] "Please login"
- [*] ],
- [*] "usernameLabel": "Username",
- [*] "usernameValue": "Mike",
- [*] "usernameButtonLabel": "Next",
- [*] "passwordLabel": "Password",
- [*] "passwordValue": "Smallhelp",
- [*] "loginButtonLabel": "Login"
- [*] },
- [*] "notVisitLinkUrls": [
- [*] "https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout"
- [*] ]
- [*] }
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0Lzk4NzU5ZmMyMDk5MjNiNTE1NGVmNzMxNzJjOThjMDI2LnBuZw==[/img][/align]
- 在 Windows 上的示例运行下令为:
- [code]
- 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 上的运行下令为:- wacat test --conf example-files/configuration-complicated-authentication-with-not-visit-link-urls-remote.json https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
复制代码 下令输出为:- [/code][list=1]
- [*] Testing in url: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/. Please wait...
- [*]
- [*] Running 1 test using 1 worker
- [*] [chromium] › test.spec.ts:40:1 › test an application
- [*] Filled the username and the password. Pushed the authentication button
- [*] In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/
- [*] In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page2
- [*] Push the button #1
- [*] Filling the #1 text input field a value: R?nSk,UP(UBO*t'm1^a^7HIv
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/working-page
- [*] Push the button #1
- [*] Filling the #1 text input field a value: R?nSk,UP(UBO*t'm1^a^7HIv
- [*] The #1 drop-down list. Selecting the option #2
- [*] Push the button #1
- [*] 1 passed (23.2s)
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0Lzk4NzU5ZmMyMDk5MjNiNTE1NGVmNzMxNzJjOThjMDI2LnBuZw==[/img][/align]
- 请注意,输出中不再有以下行:
- [code]
- In the page: https://mikesmallhelp-test-application-more-complicated-authentication.vercel.app/logout
复制代码 以无头模式运行
利用 --headless 标记以无头模式(无欣赏器)运行。示例下令如下:- wacat test --headless https://mikesmallhelp-test-application.vercel.app/
复制代码 在 CI 管道中运行
wacat 可以在 CI 管道中利用 --headless 标记运行。
设置等候时间
默认情况下,wacat 每个页面下载等候时间为 5000 毫秒。利用 --wait 标记以毫秒为单元设置页面下载等候时间。2000 毫秒等候时间的示例下令如下:- wacat test --wait 2000 https://mikesmallhelp-test-application.vercel.app/
复制代码 注意:wacat 内部利用 Playwright 工具。通常情况下,Playwright 测试可以等候一些特定的文本。但 wacat 不知道要等候什么文本,因此利用等候时间。
设置整个测试的超时时间
默认情况下,整个测试下令的超时时间为 120 秒。利用 --timeout 标记以秒为单元设置整个测试的超时时间。超时时间值至少为 1 秒。50 秒超时时间的示例下令如下:- wacat test --timeout 50 https://mikesmallhelp-test-application.vercel.app/
复制代码 注意:Playwright 内部利用的是毫秒。以是如果在这个示例中发生超时,输出会类似于:- Test timeout of 50000ms exceeded.
复制代码 Help 指令
To see all the flags, run the command:- [/code][list=1]
- [*] Test any web application, for example: wacat test http://localhost:3000
- [*]
- [*] USAGE
- [*] $ wacat test URL [--bypass-browser-console-errors] [--bypass-http-errors] [--conf <value>] [--debug] [--headless] [--input-texts <value>] [--only-links] [--random-input-texts-charset
- [*] <value>] [--random-input-texts-max-length <value>] [--random-input-texts-min-length <value>] [--timeout <value>] [--wait <value>]
- [*]
- [*] ARGUMENTS
- [*] URL Application url to test, for example: http://localhost:3000
- [*]
- [*] FLAGS
- [*] --bypass-browser-console-errors Bypass the browser console's error messages
- [*] --bypass-http-errors Bypass the HTTP errors
- [*] --conf=<value> Path to the configuration file
- [*] --debug Enable debug mode
- [*] --headless Headless mode
- [*] --input-texts=<value> Path to the input texts file
- [*] --only-links Test only links
- [*] --random-input-texts-charset=<value> Random input texts character set
- [*] --random-input-texts-max-length=<value> Random input texts max length
- [*] --random-input-texts-min-length=<value> Random input texts min length
- [*] --timeout=<value> A whole test run timeout in seconds
- [*] --wait=<value> A wait in milliseconds to wait a page load
- [*]
- [*] DESCRIPTION
- [*] Test any web application, for example: wacat test http://localhost:3000
- [*]
- [*] EXAMPLES
- [*] $ wacat test http://localhost:3000
- [/list]
- [align=center][img]https://dis.qidao123.com/imgproxy/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuL2ltZ19jb252ZXJ0Lzc0NTQxMGYyMDFiYjZlNzYzZmZjMTQ3NzVhMzE3Nzg3LnBuZw==[/img][/align]
- [size=3]开发 wacat[/size]
- [size=2]利用技能[/size]
- wacat 利用以下的一些技能:
- [list]
- [*] • Typescript
- [*] • Bash script
- [*] • oclif, The Open CLI Framework
- [*] • Playwright
- [*] • Next.js for the test applications
- [/list][size=2]开发指引[/size]
- 在 Linux 和 Mac 上,举行更改并运行
- [code]
- npm run test && npm run build && npm install -g && ./run-tests.sh
复制代码 run-tests.sh 脚本会运行全部测试用例,并验证 wacat 是否正常工作。大概,只需将更改推送到代码库,让 GitHub Actions 运行测试。
在 Windows 上,举行更改并运行- npm run test && npm run build && npm install -g
复制代码 对于 Windows,如今还没有像 ./run-tests.sh 如许的自动测试脚本。运行并从输出中验证统统是否正常。
贡献
我们热烈接待各种情势的贡献。请检察题目页面。如果发现 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
|