-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathTakesScreenshot.js
34 lines (30 loc) · 980 Bytes
/
TakesScreenshot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var File = require('../classes/File');
var Instance = require('../classes/Instance');
var OutputType = require('./OutputType');
var addFinalProp = require('../utils').addFinalProp;
var assert = require('../assert');
module.exports = TakesScreenshot;
function TakesScreenshot(instance) {
addFinalProp(this, '_instance', instance);
}
TakesScreenshot.prototype.getScreenshotAs = function(target) {
assert(target).extends(OutputType).throws(
'Target must be an instance of OutputType'
);
if (target === OutputType.BASE64 || target === OutputType.BYTES) {
return this._instance.getScreenshotAsSync(target._instance);
} else if (target === OutputType.FILE) {
return new File(
new Instance(this._instance.getScreenshotAsSync(target._instance))
);
}
throw new Error(
'This type isn\'t supported. Expected one of: '
+ [
'OutputType.FILE,',
'OutputType.BASE64,',
'or OutputType.BYTES.'
].join(' ')
);
};