-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import { Condition } from 'selenium-webdriver'; | ||
|
||
export default function mediaBuffered(mediaElement) { | ||
return new Condition('for audio to finish loading', driver => | ||
driver.executeScript(mediaElement => { | ||
return new Condition('for audio to finish buffering', async driver => { | ||
const result = await driver.executeScript(mediaElement => { | ||
return ( | ||
mediaElement.readyState === HTMLMediaElement.HAVE_ENOUGH_DATA && | ||
mediaElement.buffered.length && | ||
mediaElement.buffered.end(0) === mediaElement.duration | ||
); | ||
}, mediaElement) | ||
); | ||
}, mediaElement); | ||
|
||
// TODO: If the result is positive, audio finished buffering, we still need to wait for an unknown time to refresh the UI. | ||
// Will be great if we can remove this sleep. | ||
result && (await driver.sleep(2000)); | ||
|
||
return result; | ||
}); | ||
} |