My current challenge involves implementing automated tests for the <audio>
tag to ensure it is playing.
For testing, I am utilizing the standard angular test suite with karma and protractor.
"devDependencies": {
"karma": "~0.10",
"protractor": "~0.20.1",
"http-server": "^0.6.1",
"bower": "^1.3.1",
"shelljs": "^0.2.6",
"karma-junit-reporter": "^0.2.2",
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-watch": "~0.4.3"
}
One issue on the Karma side is the difficulty of adding resources to be used in the tests, which means no file to play during testing. If there was a way to reference a specific file to play from, checking the paused
property would be straightforward.
On the end-to-end (e2e) testing side, there is a functional demo app that works perfectly fine when manually interacting with it. However, accessing the sound element or ensuring playback using Protractor API has proven challenging as certain elements like document
and angular
are not available due to the nature of e2e testing.
beforeEach(function() {
browser.get("index.html")
});
it("Ensure the player is playing", function () {
$$("button").first().click();
// what to do?
});
To address this, one idea is to mock the audio API and simulate updated properties, but it still involves testing against my own code rather than actual sound playback of an audio sprite. Testing whether the sound starts and stops as expected becomes complex, especially since accurately mocking the currentTime
can be challenging.
Ideally, I aim to conduct these tests within unit tests using a functioning resource. This way, validating if the sound is playing could be as simple as
expect(!element[0].paused).toEqual(true);
.
The core question remains: How can I provide a file in my unit tests to serve as an audio source?