Skip to content

Commit 6987f0e

Browse files
committed
pwa-audio-recorder: ?test=1 for test automation
1 parent 7c1de60 commit 6987f0e

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/pwa-audio-recorder/app.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ async function init() {
9090
const clipContainer = insertClip();
9191
finalizeClip({clipContainer, id, recordingDescription, blob, storage});
9292
}
93+
94+
if (new URLSearchParams(window.location.search).get('test') === '1') {
95+
runTest();
96+
}
9397
}
9498

9599
/**
@@ -209,3 +213,28 @@ function visualizeRecording({stream, outlineIndicator, waveformIndicator}) {
209213

210214
draw();
211215
}
216+
217+
async function runTest() {
218+
// 1. Start recording
219+
recordButton.click();
220+
221+
// 2. After 10 seconds, start playback
222+
await new Promise((resolve) => setTimeout(resolve, 10000));
223+
const playbackSource = document.querySelector('#playback-source');
224+
playbackSource.play();
225+
226+
// 3. After 10 seconds, stop recording and stop playback
227+
await new Promise((resolve) => setTimeout(resolve, 10000));
228+
recordButton.click();
229+
playbackSource.pause();
230+
playbackSource.currentTime = 0;
231+
232+
// 4. Download the recorded audio
233+
await new Promise((resolve) => setTimeout(resolve, 1000));
234+
const clip = soundClips.firstElementChild;
235+
const audio = clip.querySelector('audio');
236+
const a = document.createElement('a');
237+
a.href = audio.src;
238+
a.download = 'recorded_audio.webm';
239+
a.click();
240+
}

src/pwa-audio-recorder/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
<div class="mdc-card clip clip-recording">
6060
<div class="mdc-card__actions">
61-
<audio src="audio_long16.wav" controls></audio>
61+
<audio id="playback-source" src="audio_long16.wav" controls></audio>
6262
</div>
6363
<div class="mdc-card__content recording-description">audio_long16.wav (Use this to test same-tab echo cancellation)</div>
6464
</div>

0 commit comments

Comments
 (0)