Skip to content

Commit

Permalink
Merge pull request #24 from Yuankai619/develop/test4p2
Browse files Browse the repository at this point in the history
Generate test script by LLM
  • Loading branch information
Yuankai619 authored Sep 22, 2024
2 parents 2715768 + 906e504 commit 80c5b86
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 1 deletion.
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();
});
});

0 comments on commit 80c5b86

Please sign in to comment.