Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
new option - singleVideoPath for customizing the path of single videos
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyam1 committed Jan 10, 2017
1 parent 65a587a commit 43220bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
28 changes: 22 additions & 6 deletions lib/VideoReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ var Joi = require('joi'),
Uuid = require('node-uuid'),
Debug = require('debug'),
SubtitlesParser = require('subtitles-parser'),
_ = require('lodash');
_ = require('lodash'),
SanitizeFilename = require('sanitize-filename');


var debug = Debug('protractor-video-reporter');

function randomVideoName() {
return Uuid.v4() + '.mov';
}

}

function VideoReporter(options) {

Expand All @@ -24,6 +25,7 @@ function VideoReporter(options) {
options = _.defaults({}, options, {
saveSuccessVideos: false,
singleVideo: true,
singleVideoPath: 'uuid',
createSubtitles: true,
ffmpegCmd: 'ffmpeg',
ffmpegArgs: [
Expand All @@ -43,9 +45,12 @@ function VideoReporter(options) {
.description('The path to the directory where videos are stored. If not existing, it gets created.'),
saveSuccessVideos: Joi.boolean()
.description('If true, will save the videos of the succussfull specs, as well as the failed specs.'),

singleVideo: Joi.boolean()
.description('If true, will create a single video file for all the specs.'),
singleVideoPath: Joi.alternatives().try(
Joi.valid('uuid', 'fullName'),
Joi.func()
),
createSubtitles: Joi.boolean()
.description('If true and singleVideo is also true, will create a SRT subtitles file with the name details of the currently running spec.'),

Expand Down Expand Up @@ -123,11 +128,22 @@ VideoReporter.prototype._stopScreencast = function(removeVideo) {
self._ffmpeg = null;
};

VideoReporter.prototype._singleVideoPath = function(result) {
var self = this;
if (self.options.singleVideoPath === 'uuid') {
return Uuid.v4() + '.mov';
} else if (self.options.singleVideoPath === 'fullName') {
return SanitizeFilename(result.fullName + '.mov');
} else {
return self.options.singleVideoPath(result);
}
}


VideoReporter.prototype.specStarted = function() {
VideoReporter.prototype.specStarted = function(result) {
var self = this;
if (!self.options.singleVideo) {
var videoPath = Path.join(self.options.baseDirectory, randomVideoName());
var videoPath = Path.join(self.options.baseDirectory, self._singleVideoPath(result));
self._startScreencast(videoPath);

} else if (self.options.createSubtitles) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"lodash": "^4.6.0",
"mkdirp": "^0.5.1",
"node-uuid": "^1.4.3",
"subtitles-parser": "0.0.2"
"subtitles-parser": "0.0.2",
"sanitize-filename": "^1.6.1"
}
}
21 changes: 19 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,26 @@ In the protractor configuration file:

* `singleVideo` (bool): If `true`, will create a single video file for all the specs. Defaults to `true`.
The file will be saved to `baseDirectory/protractor-specs.mov`.
If `singleVideo` is false, the reporter will create a separate video file for every spec and place it at `baseDirectory/{some random UUID}.mov`.
If `singleVideo` is false, the reporter will create a separate video file for every spec and place it under the `baseDirectory`.
The exact location is determined by `singleVideoPath`.

* `singleVideoPath`: (string, function):

When `uuid` (default): Each spec video file will be placed at `baseDirectory/{some random UUID}.mov`.
If you prefer this option, you would have to look at the "Spec video is in: ..." messages that are printed to the console.

When `fullName`: Each spec video will be placed at `baseDirectory/{spec full name} - {spec status}.mov`.
The full name of the spec will be sanitized to be a valid file name

If you want to determine the full name yourself you can pass a function.
The function recieves a single argument, the result object passed to `specStarted`.
For example, you can do:

singleVideoPath: function (result) {
// don't actually do this, you need to make sure fullName is a valid file name
result.fullName + '.mov';
}

* `createSubtitles` (bool): If `true` and singleVideo is also true, will create a SRT subtitles file with the name details of the currently running spec. Defaults to `true`.
The file will be saves to `baseDirectory/protractor-specs.srt`.

Expand All @@ -63,4 +80,4 @@ The file will be saves to `baseDirectory/protractor-specs.srt`.
# Debugging
If you encouter any issues with the reporter, e.g. video files are not created,
turn on debugging by settings the `DEBUG` environment to `protractor-video-reporter`.
turn on debugging by settings the `DEBUG` environment to `protractor-video-reporter`.

1 comment on commit 43220bd

@avieiravalle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code never worked whit me

Please sign in to comment.