I\'ve been trying to cover tag by automated tests, to start with just to confirmed it is playing.
I\'m using the usual angular test suite, kar
Assuming you're playing sound using HTML5 under the hood, you can do the following - basically use
browser.executeScript
to access pause
like you wanted. You'll need to have a way to navigate to your tag; in this case it was the first one. This works in my sandbox. Note: I am not affiliated with angular-media-player - it was just the first result on Google that I could get to work with protractor - I reuse when I can.
describe('angularjs homepage', function() {
it('should have a title', function() {
browser.get('http://mrgamer.github.io/angular-media-player/interactive.html');
// add a song to the playlist
element(by.repeater('song in prefabPlaylist')).click();
// hook into the browser
var isPaused = function () {
return browser.executeScript(function () {
return document.getElementsByTagName('audio')[0].paused;
});
};
// make sure it's not playing
expect(isPaused()).toBe(true);
// start playing
element(by.css('div[ng-click="mediaPlayer.playPause()"]')).click();
// for some reason these were needed for me; maybe it's the way the directive is implemented?
browser.waitForAngular();
browser.waitForAngular();
browser.waitForAngular();
// make sure it's playing
expect(isPaused()).toBe(false);
// pause
element(by.css('div[ng-click="mediaPlayer.playPause()"]')).click();
// make sure it's paused
expect(isPaused()).toBe(true);
});
});
Also you could use someone else's directive like this website (or any other) and not worry about unit-testing (they've presumably done this for you) and just evaluate the scope for their object and make sure you're setting its properties correctly in your E2E tests and not even test for sound if you don't like executeScript
.