You can't. Go home and use selenium.
Phantomjs just doesn't support video tag. What you can do is to change your app to emulate video element api, not great but something. The nice thing about this you can speed time ;)
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
React.createClass( | |
componentDidMount: -> | |
video = @getVideoElement() | |
video.addEventListener "ended", @ended, false | |
video.addEventListener "durationchange", @durationChange, false | |
video.addEventListener "timeupdate", @timeUpdate, false | |
video.play() | |
componentWillUnmount: -> | |
video = @getVideoElement() | |
video.pause() | |
video.removeEventListener("ended", @ended) | |
video.removeEventListener("durationchange", @durationChange) | |
video.removeEventListener("timeupdate", @timeUpdate) | |
getVideoElement: -> | |
# here could be more sofisticated check | |
if window.RailsEnv == 'test' | |
video = new VideoTagEmulator() | |
else | |
video = @getDOMNode() | |
render: -> | |
`<video src={this.props.url} poster={this.props.poster} ></video>` | |
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
class window.VideoTagEmulator | |
speed: 0.1 | |
constructor: -> | |
@handlers = {} | |
@duration = 5 | |
@target = { | |
duration: 0, | |
currentTime: 0, | |
ended: false | |
} | |
addEventListener: (eventType, handler) -> | |
@handlers[eventType] = handler | |
removeEventListener: -> | |
@_stopLoop() | |
@handlers = {} | |
play: -> | |
@_startLoop() | |
pause: -> | |
@_stopLoop() | |
_playFrame: -> | |
@target.currentTime += 1 | |
@handlers.timeupdate(target: @target) | |
if @target.currentTime == 1 | |
@target.duration = @duration | |
@handlers.durationchange(target: @target) | |
else if @target.currentTime > @duration | |
@_stopLoop() | |
@target.ended = true | |
@handlers.ended(target: @target) | |
_startLoop: -> | |
@timerId = window.setInterval( | |
@_playFrame.bind(@), | |
1000 * @speed | |
) | |
_stopLoop: -> | |
window.clearInterval(@timerId) |