Laman kursus / Bengkel AI / W05
W05 · M05 · 15 minit · Hari 2, 10:10 hingga 10:25

Ujian UI dan API dijana AI yang menemui pepijat sebenar

AI-generated UI and API tests that find a real bug

Matlamat / Goal

Minta AI menjana ujian Playwright untuk sempadan kuantiti, simpan dan jalankan pada ShopFast, baca kegagalan, kemudian jana ujian API daripada kontrak OpenAPI.

Ask the AI for a Playwright test for the quantity boundary, save and run it against ShopFast, read the failure, then generate API tests from the OpenAPI contract.

Peraturan data: guna data sintetik ShopFast sahaja. Model percuma dihoskan di luar negara. Output AI ialah draf yang mesti disemak manusia.

Langkah demi langkah dengan tangkapan skrin sebenar

Langkah 1 / Step 1 · opencode (Build)

Jalankan /gen-ui-test untuk kes sempadan kuantiti 10. AI membaca dokumen dahulu dan mungkin berhenti seketika pada Preparing write. Apabila dialog Permission required muncul, baca pratonton dan pilih Allow once.

Run /gen-ui-test for the quantity 10 boundary case. The AI reads the documents first and may pause at Preparing write. When the Permission required dialog appears, read the preview and choose Allow once.

/gen-ui-test TC-CHK-004 tambah P002 kuantiti 10 ke troli dan semak troli menerima kuantiti 10 (REQ-CHK-01)
Jalankan /gen-ui-test untuk kes sempadan kuantiti 10. AI membaca dokumen dahulu dan mungkin berhenti seketika pada Preparing write. Apabila dialog Permission required muncul, baca pratonton dan pilih Allow once.
Langkah 2 / Step 2 · opencode

Allow once. Ujian dan arahan disimpan dalam outputs/m05-ui-test.md.

Allow once. The test and instructions are saved in outputs/m05-ui-test.md.

Allow once (Enter)
Allow once. Ujian dan arahan disimpan dalam outputs/m05-ui-test.md.
Langkah 3 / Step 3 · PowerShell

Simpan blok kod sebagai fail spec dan jalankan. Kegagalan di sini ialah penemuan sebenar untuk dihasilkan semula dan dilaporkan dalam Modul 6.

Save the code block as a spec file and run it. A failure here is a real finding to reproduce and report in Module 6.

$md = Get-Content outputs\m05-ui-test.md -Raw
[regex]::Match($md, '(?s)```(?:js|javascript)\s*(.*?)```').Groups[1].Value | Set-Content -Encoding utf8 shopfast\tests\ui\m05-senario.spec.js
cd shopfast
npx playwright test tests/ui/m05-senario.spec.js --reporter=list
Simpan blok kod sebagai fail spec dan jalankan. Kegagalan di sini ialah penemuan sebenar untuk dihasilkan semula dan dilaporkan dalam Modul 6.
Langkah 4 / Step 4 · opencode (Build)

Kembali ke opencode, jalankan /gen-api-tests daripada kontrak OpenAPI. AI membaca dokumen dahulu dan mungkin berhenti seketika pada Preparing write. Apabila dialog Permission required muncul, baca pratonton dan pilih Allow once.

Back in opencode, run /gen-api-tests from the OpenAPI contract. The AI reads the documents first and may pause at Preparing write. When the Permission required dialog appears, read the preview and choose Allow once.

/gen-api-tests REQ-CHK-01 REQ-CHK-03
Kembali ke opencode, jalankan /gen-api-tests daripada kontrak OpenAPI. AI membaca dokumen dahulu dan mungkin berhenti seketika pada Preparing write. Apabila dialog Permission required muncul, baca pratonton dan pilih Allow once.
Langkah 5 / Step 5 · opencode

Allow once. Semak ujian API yang dijana sebelum digunakan.

Allow once. Review the generated API tests before using them.

Allow once (Enter)
Allow once. Semak ujian API yang dijana sebelum digunakan.

Semakan manusia / Human check

  1. Ujian memilih elemen melalui data-testid yang benar-benar wujud
    The test selects elements by data-testid that really exist
  2. Ujian yang gagal ialah penemuan: hasilkan semula secara manual sebelum log pepijat
    A failing test is a finding: reproduce it by hand before logging a bug
  3. Ujian yang dijana disemak seperti kod sebelum di-commit
    Generated tests are reviewed like code before they are committed

Contoh output sebenar

Jawapan AI berbeza setiap larian. Bandingkan struktur dan semak kandungan.

Jika ada masalah / Troubleshooting

MasalahTindakan
opencode is not recognisedClose and reopen PowerShell so PATH refreshes. Still failing: powershell -ExecutionPolicy Bypass -File .\setup\install-opencode.ps1 -Portable
Scripts are disabled on this systemSet-ExecutionPolicy -Scope CurrentUser RemoteSigned, or run opencode.cmd instead of opencode
The model is slow or stopsWait up to 2 minutes. Press Esc to interrupt, then send the prompt again. Try another free model with /models
Permission required dialogRead the preview. Choose Allow once for files in outputs/. Reject anything outside the lab folder
File or command not foundCheck the status bar path ends with \lab. Commands and @files are relative to the lab folder
Answer uses Indonesian words or dashesReply: Ikut AGENTS.md peraturan 1 dan 14, tulis semula dalam Bahasa Melayu Malaysia
Network or proxy error$env:HTTPS_PROXY = "http://proxy:port" and $env:NO_PROXY = "localhost,127.0.0.1" before starting opencode
Port 3000 already in use$env:PORT = 3001 before npm start, and use http://localhost:3001

Pautan