alessandro trinca tornidor commited on
Commit
e259e97
1 Parent(s): 7157083

test: update playwright package, add e2e tests (english rec) for gradio app

Browse files
static/package.json CHANGED
@@ -10,6 +10,6 @@
10
  "author": "",
11
  "license": "ISC",
12
  "dependencies": {
13
- "@playwright/test": "^1.48.2"
14
  }
15
  }
 
10
  "author": "",
11
  "license": "ISC",
12
  "dependencies": {
13
+ "@playwright/test": "^1.49.0"
14
  }
15
  }
static/playwright.config.ts CHANGED
@@ -25,13 +25,22 @@ export default defineConfig({
25
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
26
  use: {
27
  /* Base URL to use in actions like `await page.goto('/')`. */
28
- baseURL: 'http://127.0.0.1:3000',
 
29
  viewport: { width: 1280, height: 900 },
30
  ignoreHTTPSErrors: true,
31
  permissions: ['microphone'],
32
  screenshot: 'only-on-failure',
33
  trace: 'on-first-retry',
34
  video: 'retain-on-failure',
 
 
 
 
 
 
 
 
35
  /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
36
  },
37
 
 
25
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
26
  use: {
27
  /* Base URL to use in actions like `await page.goto('/')`. */
28
+ // baseURL: 'http://127.0.0.1:3000',
29
+ browserName: "chromium",
30
  viewport: { width: 1280, height: 900 },
31
  ignoreHTTPSErrors: true,
32
  permissions: ['microphone'],
33
  screenshot: 'only-on-failure',
34
  trace: 'on-first-retry',
35
  video: 'retain-on-failure',
36
+ launchOptions: {
37
+ headless: false,
38
+ ignoreDefaultArgs: ['--mute-audio'],
39
+ args: [
40
+ "--use-fake-device-for-media-stream",
41
+ "--use-fake-ui-for-media-stream",
42
+ ],
43
+ }
44
  /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
45
  },
46
 
static/pnpm-lock.yaml CHANGED
@@ -9,13 +9,13 @@ importers:
9
  .:
10
  dependencies:
11
  '@playwright/test':
12
- specifier: ^1.48.2
13
- version: 1.48.2
14
 
15
  packages:
16
 
17
- '@playwright/test@1.48.2':
18
- resolution: {integrity: sha512-54w1xCWfXuax7dz4W2M9uw0gDyh+ti/0K/MxcCUxChFh37kkdxPdfZDw5QBbuPUJHr1CiHJ1hXgSs+GgeQc5Zw==}
19
  engines: {node: '>=18'}
20
  hasBin: true
21
 
@@ -24,29 +24,29 @@ packages:
24
  engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
25
  os: [darwin]
26
 
27
- playwright-core@1.48.2:
28
- resolution: {integrity: sha512-sjjw+qrLFlriJo64du+EK0kJgZzoQPsabGF4lBvsid+3CNIZIYLgnMj9V6JY5VhM2Peh20DJWIVpVljLLnlawA==}
29
  engines: {node: '>=18'}
30
  hasBin: true
31
 
32
- playwright@1.48.2:
33
- resolution: {integrity: sha512-NjYvYgp4BPmiwfe31j4gHLa3J7bD2WiBz8Lk2RoSsmX38SVIARZ18VYjxLjAcDsAhA+F4iSEXTSGgjua0rrlgQ==}
34
  engines: {node: '>=18'}
35
  hasBin: true
36
 
37
  snapshots:
38
 
39
- '@playwright/test@1.48.2':
40
  dependencies:
41
- playwright: 1.48.2
42
 
43
  fsevents@2.3.2:
44
  optional: true
45
 
46
- playwright-core@1.48.2: {}
47
 
48
- playwright@1.48.2:
49
  dependencies:
50
- playwright-core: 1.48.2
51
  optionalDependencies:
52
  fsevents: 2.3.2
 
9
  .:
10
  dependencies:
11
  '@playwright/test':
12
+ specifier: ^1.49.0
13
+ version: 1.49.0
14
 
15
  packages:
16
 
17
+ '@playwright/test@1.49.0':
18
+ resolution: {integrity: sha512-DMulbwQURa8rNIQrf94+jPJQ4FmOVdpE5ZppRNvWVjvhC+6sOeo28r8MgIpQRYouXRtt/FCCXU7zn20jnHR4Qw==}
19
  engines: {node: '>=18'}
20
  hasBin: true
21
 
 
24
  engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
25
  os: [darwin]
26
 
27
+ playwright-core@1.49.0:
28
+ resolution: {integrity: sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA==}
29
  engines: {node: '>=18'}
30
  hasBin: true
31
 
32
+ playwright@1.49.0:
33
+ resolution: {integrity: sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A==}
34
  engines: {node: '>=18'}
35
  hasBin: true
36
 
37
  snapshots:
38
 
39
+ '@playwright/test@1.49.0':
40
  dependencies:
41
+ playwright: 1.49.0
42
 
43
  fsevents@2.3.2:
44
  optional: true
45
 
46
+ playwright-core@1.49.0: {}
47
 
48
+ playwright@1.49.0:
49
  dependencies:
50
+ playwright-core: 1.49.0
51
  optionalDependencies:
52
  fsevents: 2.3.2
static/tests/test-app-7860-rec-en.spec.ts ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { test, expect, chromium } from "@playwright/test";
2
+
3
+ const basedirAudioFiles = `${__dirname}/../../tests/events`
4
+
5
+ test("test: get a phonetic accuracy evaluation from a recorded audio.", async () => {
6
+ const testAudioEnvPath = `${basedirAudioFiles}/test_en.wav`
7
+ console.log("start");
8
+ console.log("testAudioEnvPath", testAudioEnvPath, "#");
9
+ const browser = await chromium.launch({
10
+ args: [
11
+ "--use-fake-device-for-media-stream",
12
+ "--use-fake-ui-for-media-stream",
13
+ "--use-file-for-fake-audio-capture=/home/wlsuser/workspace/ai-pronunciation-trainer-hf/tests/events/test_en.wav",
14
+ ],
15
+ ignoreDefaultArgs: ['--mute-audio']
16
+ })
17
+
18
+ const context = await browser.newContext();
19
+ context.grantPermissions(["microphone"]);
20
+ const page = await browser.newPage({});
21
+
22
+ await page.goto('http://localhost:7860/');
23
+ const buttonTTS = page.getByRole('button', { name: 'Run TTS' })
24
+ await buttonTTS.click();
25
+ // todo: improve this hardcoded timeout
26
+ await page.waitForTimeout(3000);
27
+
28
+ const buttonPlay = page.getByLabel('Play', { exact: true })
29
+ await buttonPlay.click();
30
+ const waveFormTTS = page.locator('.scroll > .wrapper').first();
31
+ await waveFormTTS.waitFor({ state: 'attached' });
32
+ await waveFormTTS.waitFor({ state: 'visible' });
33
+ await expect(waveFormTTS).toBeVisible();
34
+ console.log("waveFormTTS??");
35
+
36
+ const buttonRecordTTS = page.getByRole('button', { name: 'Record', exact: true })
37
+ await buttonRecordTTS.click();
38
+ console.log("buttonRecordTTS??");
39
+ const buttonStopTTS = page.getByRole('button', { name: 'Stop', exact: true })
40
+ await buttonStopTTS.click();
41
+ console.log("buttonStopTTS??");
42
+
43
+ const buttonRecognizeSpeechAccuracy = page.getByRole('button', { name: 'Recognize speech accuracy' })
44
+ console.log("buttonRecognizeSpeechAccuracy??");
45
+ console.log("buttonRecognizeSpeechAccuracy??");
46
+ await buttonRecognizeSpeechAccuracy.click();
47
+ console.log("buttonRecognizeSpeechAccuracy=>click!");
48
+ console.log("buttonRecognizeSpeechAccuracy=>click!");
49
+ await page.waitForTimeout(300);
50
+
51
+ const errorsElements = page.getByText(/Error/);
52
+ const ErrorText = errorsElements.all()
53
+ console.log("ErrorText:", (await ErrorText).length, "#");
54
+ await expect(errorsElements).toHaveCount(0);
55
+ console.log("end");
56
+ await page.close();
57
+ });
static/tests/test-app-7860-upload-en.spec.ts ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { test, expect, chromium, Locator } from "@playwright/test";
2
+
3
+ const basedirAudioFiles = `${__dirname}/../../tests/events`
4
+
5
+ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", async () => {
6
+ const testAudioEnvPath = `${basedirAudioFiles}/test_en.wav`
7
+ console.log("start");
8
+ console.log("testAudioEnvPath", testAudioEnvPath, "#");
9
+
10
+ const browser = await chromium.launch({
11
+ args: [
12
+ "--use-fake-device-for-media-stream",
13
+ ],
14
+ ignoreDefaultArgs: ['--mute-audio']
15
+ })
16
+
17
+ const context = await browser.newContext();
18
+ context.grantPermissions(["microphone"]);
19
+ const page = await browser.newPage({});
20
+
21
+ await page.goto('http://localhost:7860/');
22
+ await page.getByRole('button', { name: 'Run TTS' }).click();
23
+ const buttonPlay = page.getByLabel('Play', { exact: true })
24
+ await buttonPlay.click();
25
+ const waveFormTTS = page.locator('.scroll > .wrapper').first();
26
+ await waveFormTTS.waitFor({ state: 'attached' });
27
+ await waveFormTTS.waitFor({ state: 'visible' });
28
+ await expect(waveFormTTS).toBeVisible();
29
+ console.log("waveFormTTS??");
30
+
31
+ const fileChooserPromise = page.waitForEvent('filechooser');
32
+ await page.getByLabel('Upload file').click();
33
+ await page.getByRole('button', { name: 'Drop Audio Here - or - Click' }).click();
34
+ const fileChooser = await fileChooserPromise;
35
+ await fileChooser.setFiles(testAudioEnvPath);
36
+
37
+ await page.getByRole('button', { name: 'Recognize speech accuracy' }).click();
38
+
39
+ await page.waitForTimeout(300);
40
+ const errorsElements = page.getByText(/Error/);
41
+ const ErrorText = errorsElements.all()
42
+ console.log("ErrorText:", (await ErrorText).length, "#");
43
+ await expect(errorsElements).toHaveCount(0);
44
+ console.log("end");
45
+ await page.close();
46
+ });
static/tests/{test-1.spec.ts → test-webApp-3000.spec.ts} RENAMED
@@ -10,7 +10,7 @@ test("test: get a custom sample writing within the input field.", async () => {
10
  const context = await browser.newContext();
11
  context.grantPermissions(["microphone"]);
12
  const page = await browser.newPage({});
13
- await page.goto("/");
14
 
15
  const inputField = page.getByPlaceholder(
16
  "Write and press enter to filter"
 
10
  const context = await browser.newContext();
11
  context.grantPermissions(["microphone"]);
12
  const page = await browser.newPage({});
13
+ await page.goto("http://localhost:3000");
14
 
15
  const inputField = page.getByPlaceholder(
16
  "Write and press enter to filter"