I'm trying to get the video properties using Testcafe to play()
, pause()
, get the current playing time, and set the current time.
The problem is that I'm hard coding the set time and ideally I'd like that to be a function that I can pass any time
value I want.
I wrote the following simple test:
import { ClientFunction } from 'testcafe';
const URL = 'https://www.youtube.com/watch?v=RWQtB6Xv01Q';
fixture `Portal Experience playback`
.page `${URL}`;
function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
test('Testing YouTube', async t => {
const play = ClientFunction(() => document.querySelector('.video-stream').play());
const pause = ClientFunction(() => document.querySelector('.video-stream').pause());
const currentTime = ClientFunction(() => document.querySelector('.video-stream').currentTime);
const setTime = await t.eval(() => document.querySelector('.video-stream').currentTime = 5);
await setTime;
console.info(`Video time is ${await currentTime()}`);
await play;
await sleep(5000);
console.info(`Video time is ${await currentTime()}`);
await pause;
});
The play
, pause
, and currentTime
I can just copy and past to a class inside a page model.
The page model would be:
export class Player {
constructor () {
this.play = ClientFunction(() => document.querySelector('.video-stream').play());
this.pause = ClientFunction(() => document.querySelector('.video-stream').pause());
this.currentTime = ClientFunction(() => document.querySelector('.video-stream').currentTime);
}
// a function to set video time
}
How do I turn setTime
into a function inside a page model?
Aucun commentaire:
Enregistrer un commentaire