Skip to content

Commit

Permalink
prepare Playwright test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
terryzfeng committed Jun 11, 2024
1 parent 7c38538 commit d6696b5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 44 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 34 additions & 19 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ export default defineConfig({
name: 'chromium',
use: {
...devices['Desktop Chrome'],
launchOptions: { ignoreDefaultArgs: ['--mute-audio'] },
launchOptions: {
ignoreDefaultArgs: ['--mute-audio'],
args: ['--autoplay-policy=no-user-gesture-required']
},
}
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
Expand All @@ -65,16 +68,28 @@ export default defineConfig({
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: {
// ...devices['Desktop Chrome'],
// channel: 'chrome',
// launchOptions: {
// ignoreDefaultArgs: ['--mute-audio']
// },
// },
// },
{
name: 'Google Chrome',
use: {
...devices['Desktop Chrome'],
channel: 'chrome',
launchOptions: {
ignoreDefaultArgs: ['--mute-audio'],
args: ['--autoplay-policy=no-user-gesture-required']
},
},
},
{
name: 'Google Chrome Canary',
use: {
...devices['Desktop Chrome'],
channel: 'chrome-canary',
launchOptions: {
ignoreDefaultArgs: ['--mute-audio'],
args: ['--autoplay-policy=no-user-gesture-required']
},
},
}
],

/* Run your local dev server before starting the tests */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello Sine Test</title>
<title>AudioWorklet Add Module Resolution</title>
</head>
<body>
<h1>Audioworklet Add Module Resolution</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/playwright/pages/offline-sine.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>Offline Sine Test</h1>
<p>Write 441Hz sine wave for 1 second to AudioBuffer using OfflineAudioContext, sampleRate: 44100</p>

<script>
const sampleRate = 44100.0;
const sampleRate = 44100;
const length = 1;
const numChannels = 1;
const freq = 441;
Expand Down
20 changes: 11 additions & 9 deletions src/tests/playwright/pages/realtime-sine.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ <h1>Realtime Sine Test</h1>
osc.type = 'sine';
osc.frequency.value = 440;
osc.connect(audioContext.destination);
const startButton = document.getElementById('start');

startButton.addEventListener('click', () => {
startButton.disabled = true;
let updateFrequencyPromise;
document.getElementById('start').addEventListener('click', () => {
osc.start();

// after 1 second, change to 880 Hz
setTimeout(() => {
osc.frequency.value = 880;
osc.stop(audioContext.currentTime + 1);
}, 1000);
}, { once: true });
// Update frequency after 1 second
updateFrequencyPromise = new Promise((resolve, reject) => {
setTimeout(() => {
osc.frequency.value = 880;
osc.stop(audioContext.currentTime + 1);
resolve();
}, 1000);
});
});
</script>
</body>
</html>
12 changes: 5 additions & 7 deletions src/tests/playwright/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ import { test, expect } from '@playwright/test';

test('Hello Sine (realtime)', async ({ page }) => {
await page.goto('pages/realtime-sine.html');

const h1 = await page.$('h1');
const text = await h1?.textContent();
expect(text).toBe('Realtime Sine Test');
await page.click('#start');

const osc = await page.evaluateHandle(object => osc);

await page.click('#start');

// Check 440Hz
const f1 = await osc.getProperty('frequency');
const f1Val = await f1.getProperty('value');
expect(await f1Val.jsonValue()).toBe(440);

await page.waitForTimeout(1000);
// wait for the updateFrequency promise to resolve
const updateFrequencyPromise = await page.evaluate(() => updateFrequencyPromise);

// Check 880Hz
const f2 = await osc.getProperty('frequency');
const f2Val = await f2.getProperty('value');
expect(await f2Val.jsonValue()).toBe(880);

await page.waitForTimeout(1000);
});

test('Hello Sine (offline)', async ({ page }) => {
Expand Down
7 changes: 7 additions & 0 deletions src/tests/playwright/version.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from '@playwright/test';

test('Browser version', async ({ browser }) => {
const version = await browser.version();
console.log('Browser version:', version);
expect(version).not.toBe(null);
});

0 comments on commit d6696b5

Please sign in to comment.