Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate test script by LLM #24

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion test4/prompts_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,90 @@ function clearAllItems() {
```

## Conclusion2
加上aria-label 跟 data-testid 基本沒有影響
加上aria-label 跟 data-testid 基本沒有影響


# Generate test script with Chatgpt

## Prompt1
(網頁的程式碼html )(省略文字)
寫一個playwright測試,測試所有的功能是否正常運作。

## Response1
```
const { test, expect } = require('@playwright/test');

test.describe('To-Do List functionality', () => {

test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000'); // 修改為你應用程式的本地網址
});

test('should add a new item to the list', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const itemList = page.locator('#itemList');

await input.fill('測試項目1');
await addButton.click();

await expect(itemList).toContainText('測試項目1');
});

test('should edit an existing item', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const editButton = page.locator('[data-testid="edit-button"]');

// 新增一個項目
await input.fill('測試項目2');
await addButton.click();

// 編輯該項目
await editButton.click();
await input.fill('已編輯項目');
await addButton.click();

await expect(page.locator('#itemList li')).toContainText('已編輯項目');
});

test('should delete an item from the list', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const deleteButton = page.locator('[data-testid="delete-button"]');

// 新增一個項目
await input.fill('測試項目3');
await addButton.click();

// 刪除該項目
await deleteButton.click();

await expect(page.locator('#itemList')).not.toContainText('測試項目3');
});

test('should clear all items from the list', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const clearAllButton = page.locator('[data-testid="clear-all-button"]');

// 新增兩個項目
await input.fill('測試項目4');
await addButton.click();
await input.fill('測試項目5');
await addButton.click();

// 清除所有項目
await clearAllButton.click();

await expect(page.locator('#itemList')).toBeEmpty();
});
});
```
## Conclusion1
已測試
- 新增項目
- 編輯項目
- 刪除單項
- 刪除全部
符合題目要求 可以接受
68 changes: 68 additions & 0 deletions test4/tests/chatgptV1.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { test, expect } from '@playwright/test';

test.describe('To-Do List functionality', () => {

test.beforeEach(async ({ page }) => {
await page.goto('http://127.0.0.1:8080/');
});

test('should add a new item to the list', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const itemList = page.locator('#itemList');

await input.fill('測試項目1');
await addButton.click();

await expect(itemList).toContainText('測試項目1');
});

test('should edit an existing item', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const editButton = page.locator('[data-testid="edit-button"]');

// 新增一個項目
await input.fill('測試項目2');
await addButton.click();

// 編輯該項目
await editButton.click();
await input.fill('已編輯項目');
await addButton.click();

await expect(page.locator('#itemList li')).toContainText('已編輯項目');
});

test('should delete an item from the list', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const deleteButton = page.locator('[data-testid="delete-button"]');

// 新增一個項目
await input.fill('測試項目3');
await addButton.click();

// 刪除該項目
await deleteButton.click();

await expect(page.locator('#itemList')).not.toContainText('測試項目3');
});

test('should clear all items from the list', async ({ page }) => {
const input = page.locator('#itemInput');
const addButton = page.locator('[data-testid="add-button"]');
const clearAllButton = page.locator('[data-testid="clear-all-button"]');

// 新增兩個項目
await input.fill('測試項目4');
await addButton.click();
await input.fill('測試項目5');
await addButton.click();

// 清除所有項目
await clearAllButton.click();

await expect(page.locator('#itemList')).toBeEmpty();
});
});