Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

test(web): use visible Select controls in parity checks

Leggett091d827c6324
diff --git a/apps/web/e2e/web-desktop-parity.spec.ts b/apps/web/e2e/web-desktop-parity.spec.ts
index db9458de..a492212f 100644
--- a/apps/web/e2e/web-desktop-parity.spec.ts
+++ b/apps/web/e2e/web-desktop-parity.spec.ts
@@ -1,6 +1,13 @@
+import type { Locator } from '@playwright/test';
import { createDefaultCreatorServicesConfig, type CreatorRuntimeComponentsResponse, type CreatorServicesCapabilitiesResponse, type CreatorYtDlpStatusResponse, type YouTubeConnectionState } from '@opencreator/protocol';
import { test, expect, stubVideoDownloadProbe } from './fixtures/runtime.js';
+async function selectChoice(control: Locator, value: string) {
+ await control.click();
+ await control.page().getByRole('option')
+ .and(control.page().locator(`[data-value="${value}"]`)).click();
+}
+
test('视频翻译语言检索和选项在 Browser/Desktop 使用相同目录', async ({ browser, runtime }, testInfo) => {
const results: unknown[] = [];
const viewport = testInfo.project.name === 'chromium-mobile' ? { width: 390, height: 844 } : { width: 1280, height: 800 };
@@ -17,11 +24,22 @@ test('视频翻译语言检索和选项在 Browser/Desktop 使用相同目录',
await page.goto(`${runtime.origin}/#/workbench?tool=video-translation&jobId=${encodeURIComponent(job.id)}`);
const source = page.getByRole('combobox', { name: '源语言', exact: true });
const target = page.getByRole('combobox', { name: '翻译为', exact: true });
- await expect(source).toHaveValue('hi');
- await expect(source.locator('option')).toHaveCount(123);
- await expect(target.locator('option')).toHaveCount(124);
- for (const value of ['bo', 'si', 'am', 'nn', 'yue']) await expect(source.locator(`option[value="${value}"]`)).toHaveCount(1);
- await expect(source.locator('option[value="pinyin"]')).toHaveCount(0);
+ await expect(source).toHaveAttribute('data-value', 'hi');
+ await source.click();
+ const options = page.getByRole('option');
+ await expect(options).toHaveCount(123);
+ for (const value of ['bo', 'si', 'am', 'nn', 'yue']) {
+ await expect(options.and(page.locator(`[data-value="${value}"]`))).toHaveCount(1);
+ }
+ await expect(options.and(page.locator('[data-value="pinyin"]'))).toHaveCount(0);
+ const sourceOptions = await options.evaluateAll(items => items.map(item => ({
+ value: item.getAttribute('data-value'), text: item.textContent
+ })));
+ await source.press('Escape');
+ await target.click();
+ await expect(options).toHaveCount(124);
+ const targetOptions = await options.allTextContents();
+ await target.press('Escape');
const loadedFonts = await page.evaluate(async () => Promise.all([
['Noto Sans Ethiopic', 'አማርኛ'], ['Noto Sans Javanese', 'ꦧꦱꦗꦮ'],
['Noto Sans Malayalam', 'മലയാളം'], ['Noto Sans Kannada', 'ಕನ್ನಡ'],
@@ -30,19 +48,25 @@ test('视频翻译语言检索和选项在 Browser/Desktop 使用相同目录',
['Noto Serif Tibetan', 'བོད་སྐད་']
].map(async ([family, sample]) => (await document.fonts.load(`16px "${family}"`, sample)).length)));
expect(loadedFonts).toEqual(Array(9).fill(1));
- await page.getByRole('searchbox', { name: '搜索源语言' }).fill('阿拉伯');
- await expect(source.locator('option[value="ar"]')).toHaveText('العربية');
- await expect(source).toHaveValue('hi');
- await source.selectOption('ar');
- await page.getByRole('searchbox', { name: '搜索源语言' }).fill('हिन्दी');
- await expect(source).toHaveValue('ar');
- for (const input of [source, target, page.getByRole('searchbox', { name: '搜索源语言' })]) {
+ await source.click();
+ const search = page.getByRole('searchbox', { name: '搜索选项' });
+ await search.fill('阿拉伯');
+ const arabic = options.and(page.locator('[data-value="ar"]'));
+ await expect(arabic).toHaveText('العربية');
+ await expect(source).toHaveAttribute('data-value', 'hi');
+ await arabic.click();
+ await source.click();
+ await search.fill('हिन्दी');
+ await expect(options.and(page.locator('[data-value="hi"]'))).toBeVisible();
+ await expect(source).toHaveAttribute('data-value', 'ar');
+ for (const input of [source, target, search]) {
const box = await input.boundingBox();
expect(box).not.toBeNull();
expect(box!.x).toBeGreaterThanOrEqual(0);
expect(box!.x + box!.width).toBeLessThanOrEqual(viewport.width);
}
- results.push({ source: await source.locator('option').evaluateAll(options => options.map(option => ({ value: (option as HTMLOptionElement).value, text: option.textContent }))), target: await target.locator('option').allTextContents(), box: await source.boundingBox() });
+ await source.press('Escape');
+ results.push({ source: sourceOptions, target: targetOptions, box: await source.boundingBox() });
} finally { await context.close(); }
}
expect(results[1]).toEqual(results[0]);
@@ -238,11 +262,13 @@ test('扩展源语言与巴西葡萄牙语设置在 Browser/Desktop 下保存并
const request = page.waitForRequest(req => req.url().endsWith('/actions')
&& req.postDataJSON()?.input?.patch?.sourceLanguage === 'pt');
const source = page.getByRole('combobox', { name: '源语言', exact: true });
- await expect(source.locator('option')).toHaveCount(123);
+ await source.click();
+ const options = page.getByRole('option');
+ await expect(options).toHaveCount(123);
for (const value of ['es', 'fr', 'it', 'pt', 'id', 'th']) {
- await expect(source.locator(`option[value="${value}"]`)).toHaveCount(1);
+ await expect(options.and(page.locator(`[data-value="${value}"]`))).toHaveCount(1);
}
- await source.selectOption('pt');
+ await options.and(page.locator('[data-value="pt"]')).click();
const action = (await request).postDataJSON();
const readSettings = async () => {
const { job } = await runtime.api<{ job: { state: { sourceLanguage: string; targetLanguage: string; bilingual: boolean } } }>('GET', `/creator/jobs/${created.job.id}`);
@@ -250,9 +276,9 @@ test('扩展源语言与巴西葡萄牙语设置在 Browser/Desktop 下保存并
};
await expect.poll(readSettings).toEqual({ sourceLanguage: 'pt', targetLanguage: 'zh_cn', bilingual: true });
await page.reload();
- await expect(source).toHaveValue('pt');
- await expect(page.getByRole('combobox', { name: '翻译为' })).toHaveValue('zh_cn');
- await expect(page.getByRole('switch', { name: '双语字幕' })).toBeChecked();
+ await expect(source).toHaveAttribute('data-value', 'pt');
+ await expect(page.getByRole('combobox', { name: '翻译为' })).toHaveAttribute('data-value', 'zh_cn');
+ await expect.poll(readSettings).toEqual({ sourceLanguage: 'pt', targetLanguage: 'zh_cn', bilingual: true });
results.push({ action: action.action, settings: await readSettings(),
requested: { sourceLanguage: action.input.patch.sourceLanguage, targetLanguage: action.input.patch.targetLanguage, bilingual: action.input.patch.bilingual },
options: await source.innerText(), sourceBox: await source.boundingBox() });
@@ -419,7 +445,7 @@ test('本地字幕导入在 Browser/Desktop Bridge 下保持相同命令和界
await page.goto(`${runtime.origin}/#/workbench?tool=video-translation&jobId=${created.job.id}`);
const group = page.getByRole('group', { name: '导入已有字幕' });
await group.getByRole('switch', { name: '导入已有字幕' }).click();
- await group.getByRole('combobox', { name: '字幕类型' }).selectOption('target_subtitle');
+ await selectChoice(group.getByRole('combobox', { name: '字幕类型' }), 'target_subtitle');
const request = page.waitForRequest(request => request.url().endsWith('/actions') && request.postDataJSON()?.action === 'import-subtitle');
await group.getByLabel('UTF-8 SRT 文件').setInputFiles({ name: 'local.srt', mimeType: 'application/x-subrip', buffer: Buffer.from('1\n00:00:00,000 --> 00:00:01,000\nHello\n') });
const action = (await request).postDataJSON();
@@ -1169,7 +1195,7 @@ test('通用界面设置在 Browser/Desktop Bridge 下读取并写入相同 Runt
const language = settings.getByRole('combobox', { name: '显示语言' });
const storagePaths = settings.locator('#settings-default-project-root, #settings-output-root');
await expect(lightButton).toHaveAttribute('aria-pressed', 'true');
- await expect(permission).toHaveValue('workspace-write');
+ await expect(permission).toHaveAttribute('data-value', 'workspace-write');
await expect(language).toHaveAttribute('data-value', 'zh-CN');
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
await expect(page.locator('html')).toHaveAttribute('data-accent', 'red');
@@ -1227,8 +1253,8 @@ test('通用界面设置在 Browser/Desktop Bridge 下读取并写入相同 Runt
theme: await page.locator('html').getAttribute('data-theme') ?? undefined,
accent: await page.locator('html').getAttribute('data-accent') ?? undefined,
lightSelected: await lightButton.getAttribute('aria-pressed'),
- permission: await permission.inputValue(),
- language: await language.inputValue(),
+ permission: await permission.getAttribute('data-value') ?? '',
+ language: await language.getAttribute('data-value') ?? '',
storagePaths: await readStoragePaths(),
storagePickerCount,
boxes,
@@ -1431,14 +1457,14 @@ test('视频生成在 Browser/Desktop Bridge 下保持相同界面、请求和
const model = workspace.getByRole('combobox', { name: '模型版本' });
const format = workspace.getByRole('combobox', { name: '画幅' });
const duration = workspace.getByRole('combobox', { name: '视频时长' });
- await expect(provider).toHaveValue('seedance');
+ await expect(provider).toHaveAttribute('data-value', 'seedance');
await expect(model).toHaveValue('Seedance 2.0');
- await expect(format).toHaveValue('1280x720');
- await expect(duration).toHaveValue('5');
- await provider.selectOption('veo');
+ await expect(format).toHaveAttribute('data-value', '1280x720');
+ await expect(duration).toHaveAttribute('data-value', '5');
+ await selectChoice(provider, 'veo');
await expect(model).toHaveValue('Veo 3.1');
- await format.selectOption('720x1280');
- await duration.selectOption('8');
+ await selectChoice(format, '720x1280');
+ await selectChoice(duration, '8');
await expect.poll(async () => (
await runtime.api<{
@@ -1841,9 +1867,9 @@ test('短视频脚本在 Browser/Desktop Bridge 下保持相同界面、请求
const duration = workspace.getByRole('spinbutton', { name: '目标时长(秒)' });
const tone = workspace.getByRole('combobox', { name: '表达语气' });
await topic.fill('第一次参与开源项目的真实过程');
- await platformSelect.selectOption('bilibili');
+ await selectChoice(platformSelect, 'bilibili');
await duration.fill('90');
- await tone.selectOption('professional');
+ await selectChoice(tone, 'professional');
await expect.poll(async () => (
await runtime.api<{
@@ -1956,10 +1982,10 @@ test('视频切片在 Browser/Desktop Bridge 下保持相同界面、请求和
await expect(workspace.getByRole('button', { name: '下一步:切片设置' }))
.toBeEnabled();
await workspace.getByRole('button', { name: '下一步:切片设置' }).click();
- await workspace.getByRole('combobox', { name: '内容重点' }).selectOption('viral');
- await workspace.getByRole('combobox', { name: '目标时长' }).selectOption('30-60');
+ await selectChoice(workspace.getByRole('combobox', { name: '内容重点' }), 'viral');
+ await selectChoice(workspace.getByRole('combobox', { name: '目标时长' }), '30-60');
await workspace.getByRole('spinbutton', { name: '切片数量' }).fill('6');
- await workspace.getByRole('combobox', { name: '输出画幅' }).selectOption('1:1');
+ await selectChoice(workspace.getByRole('combobox', { name: '输出画幅' }), '1:1');
await expect(workspace.getByLabel('任务摘要')).toContainText('传播潜力优先');
await expect(workspace.getByLabel('任务摘要')).toContainText('切片数量6');
@@ -2263,8 +2289,8 @@ test('图像生成在桌面和移动视口创建、持久化并从项目中心
await expect(page.getByRole('radio', { name: '4 张', exact: true })).toHaveCount(0);
await page.getByRole('combobox', { name: '模型', exact: true }).click();
await page.getByRole('option', { name: 'GPT Image', exact: true }).click();
- await page.getByRole('combobox', { name: '图片画幅' }).selectOption('3:2');
- await page.getByRole('combobox', { name: '图片质量' }).selectOption('high');
+ await selectChoice(page.getByRole('combobox', { name: '图片画幅' }), '3:2');
+ await selectChoice(page.getByRole('combobox', { name: '图片质量' }), 'high');
await page.getByRole('radio', { name: '4 张', exact: true }).click();
const jobId = new URL(page.url()).hash.match(/jobId=([^&]+)/)?.[1];
@@ -2285,8 +2311,8 @@ test('图像生成在桌面和移动视口创建、持久化并从项目中心
await page.reload();
await expect(page.getByRole('heading', { name: '图像生成' })).toBeVisible();
- await expect(page.getByRole('combobox', { name: '图片画幅' })).toHaveValue('3:2');
- await expect(page.getByRole('combobox', { name: '图片质量' })).toHaveValue('high');
+ await expect(page.getByRole('combobox', { name: '图片画幅' })).toHaveAttribute('data-value', '3:2');
+ await expect(page.getByRole('combobox', { name: '图片质量' })).toHaveAttribute('data-value', 'high');
await expect(page.getByRole('radio', { name: '4 张', exact: true })).toBeChecked();
await page.goto(`${runtime.origin}/#/projects`);
@@ -2294,8 +2320,8 @@ test('图像生成在桌面和移动视口创建、持久化并从项目中心
await page.getByRole('button', { name: `打开项目 ${prompt}` }).click();
await expect(page).toHaveURL(new RegExp(`jobId=${jobId}`));
await expect(page.getByRole('heading', { name: '图像生成' })).toBeVisible();
- await expect(page.getByRole('combobox', { name: '图片画幅' })).toHaveValue('3:2');
- await expect(page.getByRole('combobox', { name: '图片质量' })).toHaveValue('high');
+ await expect(page.getByRole('combobox', { name: '图片画幅' })).toHaveAttribute('data-value', '3:2');
+ await expect(page.getByRole('combobox', { name: '图片质量' })).toHaveAttribute('data-value', 'high');
await expect(page.getByRole('radio', { name: '4 张', exact: true })).toBeChecked();
});