import { test, expect } from '@playwright/test'; test('验证林俊杰六首歌曲的URL配对是否正确', async ({ page }) => { // 导航到首页 await page.goto('http://localhost:3000/'); // 等待页面加载完成 await page.waitForLoadState('networkidle'); await page.waitForSelector('.hot-songs-section'); // 定义歌曲列表和预期的URL const expectedSongs = [ { id: 1, title: '江南', expectedUrl: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3' }, { id: 2, title: '小酒窝', expectedUrl: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3' }, { id: 3, title: '曹操', expectedUrl: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3' }, { id: 4, title: '她说', expectedUrl: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3' }, { id: 5, title: '背对背拥抱', expectedUrl: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-5.mp3' }, { id: 6, title: '一千年以后', expectedUrl: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-6.mp3' } ]; // 遍历每首歌曲进行验证 for (const song of expectedSongs) { console.log(`验证歌曲: ${song.title}`); // 使用更精确的选择器点击歌曲 const songElement = page.locator(`.songs-list .song-item:has(.song-info h3:text("${song.title}"))`); await songElement.waitFor(); await songElement.click(); // 等待页面跳转完成 await page.waitForURL(`/songs/${song.id}`); await page.waitForLoadState('networkidle'); // 等待歌曲详情页面元素加载完成 await page.waitForSelector('.song-detail-content'); await page.waitForSelector('.album-cover img'); // 获取音频元素的src属性 const audioElement = page.locator('audio'); await audioElement.waitFor(); const actualUrl = await audioElement.getAttribute('src'); // 验证URL是否正确 expect(actualUrl).toBe(song.expectedUrl); console.log(`✓ 歌曲 ${song.title} 的URL正确: ${actualUrl}`); // 返回首页 const backButton = page.locator('.back-btn'); await backButton.waitFor(); await backButton.click(); await page.waitForURL('/'); await page.waitForLoadState('networkidle'); await page.waitForSelector('.hot-songs-section'); } console.log('\n所有歌曲的URL配对验证通过!'); });