Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should add deviceType as argument to allure', () => {
global.browser.capabilities.deviceType = 'myDevice';
configModule.default.usingAllure = false;
allureMocks.addArgument = jest.fn();
let video = new Video(options);
video.testname = undefined;
video.onSuiteEnd(passedScenario);
expect(allureMocks.addArgument).not.toHaveBeenCalled();
configModule.default.usingAllure = true;
allureMocks.addArgument = jest.fn();
video = new Video(options);
video.testname = undefined;
video.onSuiteEnd(passedScenario);
expect(allureMocks.addArgument).toHaveBeenCalledWith('deviceType', 'myDevice');
});
it('should add browserVersion as argument to allure', () => {
global.browser.capabilities.browserVersion = '1.2.3';
configModule.default.usingAllure = false;
allureMocks.addArgument = jest.fn();
let video = new Video(options);
video.testname = undefined;
video.onTestEnd({ title: 'TEST', state: 'passed' });
expect(allureMocks.addArgument).not.toHaveBeenCalled();
configModule.default.usingAllure = true;
allureMocks.addArgument = jest.fn();
video = new Video(options);
video.testname = undefined;
video.onTestEnd({ title: 'TEST', state: 'passed' });
expect(allureMocks.addArgument).toHaveBeenCalledWith('browserVersion', '1.2.3');
});
it('should add video attachment placeholder to Allure, if using Allure', () => {
let video = new Video(options);
video.onTestEnd({ title: 'TEST', state: 'failed' });
expect(allureMocks.addAttachment).not.toHaveBeenCalled();
allureMocks.addAttachment = jest.fn();
options.saveAllVideos = true;
video = new Video(options);
video.onTestEnd({ title: 'TEST', state: 'passed' });
expect(allureMocks.addAttachment).not.toHaveBeenCalled();
allureMocks.addAttachment = jest.fn();
video = new Video(options);
video.config.usingAllure = true;
video.onTestEnd({ title: 'TEST', state: 'failed' });
expect(allureMocks.addAttachment).toHaveBeenCalled();
allureMocks.addAttachment = jest.fn();
video = new Video(options);
video.config.usingAllure = true;
video.onTestEnd({ title: 'TEST', state: 'failed' });
expect(allureMocks.addAttachment).toHaveBeenCalled();
});
onTestEnd (test) {
this.testnameStructure.pop();
if(config.usingAllure) {
if (browser.capabilities.deviceType) {
allureReporter.addArgument('deviceType', browser.capabilities.deviceType);
}
if (browser.capabilities.browserVersion) {
allureReporter.addArgument('browserVersion', browser.capabilities.browserVersion);
}
}
if (test.state === 'failed' || (test.state === 'passed' && config.saveAllVideos)) {
const filePath = path.resolve(this.recordingPath, this.frameNr.toString().padStart(4, '0') + '.png');
try {
browser.saveScreenshot(filePath);
helpers.debugLog('- Screenshot!!\n');
} catch (e) {
fs.writeFile(filePath, notAvailableImage, 'base64');
helpers.debugLog('- Screenshot not available...\n');
}
onTestEnd (test) {
this.testnameStructure.pop();
if(config.usingAllure) {
if (browser.capabilities.deviceType) {
allureReporter.addArgument('deviceType', browser.capabilities.deviceType);
}
if (browser.capabilities.browserVersion) {
allureReporter.addArgument('browserVersion', browser.capabilities.browserVersion);
}
}
if (test.state === 'failed' || (test.state === 'passed' && config.saveAllVideos)) {
const filePath = path.resolve(this.recordingPath, this.frameNr.toString().padStart(4, '0') + '.png');
try {
browser.saveScreenshot(filePath);
helpers.debugLog('- Screenshot!!\n');
} catch (e) {
fs.writeFile(filePath, notAvailableImage, 'base64');
helpers.debugLog('- Screenshot not available...\n');
}
const videoPath = path.resolve(config.outputDir, this.testname + '.mp4');
this.videos.push(videoPath);
onSuiteEnd (suite) {
if (config.usingAllure) {
if (browser.capabilities.deviceType) {
allureReporter.addArgument('deviceType', browser.capabilities.deviceType);
}
if (browser.capabilities.browserVersion) {
allureReporter.addArgument('browserVersion', browser.capabilities.browserVersion);
}
}
if (suite.type === 'scenario') {
const hasFailedTests = suite.tests.filter(test => test.state === 'failed').length > 0;
const allTestsPassed = suite.tests.filter(test => test.state === 'failed').length === 0;
if (hasFailedTests || (allTestsPassed && config.saveAllVideos)) {
const filePath = path.resolve(this.recordingPath, this.frameNr.toString().padStart(4, '0') + '.png');
try {
browser.saveScreenshot(filePath);
helpers.debugLog('- Screenshot!!\n');
} catch (e) {
onSuiteEnd (suite) {
if (config.usingAllure) {
if (browser.capabilities.deviceType) {
allureReporter.addArgument('deviceType', browser.capabilities.deviceType);
}
if (browser.capabilities.browserVersion) {
allureReporter.addArgument('browserVersion', browser.capabilities.browserVersion);
}
}
if (suite.type === 'scenario') {
const hasFailedTests = suite.tests.filter(test => test.state === 'failed').length > 0;
const allTestsPassed = suite.tests.filter(test => test.state === 'failed').length === 0;
if (hasFailedTests || (allTestsPassed && config.saveAllVideos)) {
const filePath = path.resolve(this.recordingPath, this.frameNr.toString().padStart(4, '0') + '.png');
try {
browser.saveScreenshot(filePath);
helpers.debugLog('- Screenshot!!\n');
} catch (e) {
fs.writeFile(filePath, notAvailableImage, 'base64');
helpers.debugLog('- Screenshot not available...\n');
}
beforeEach(() => {
allureMocks.addAttachment = jest.fn();
allureMocks.addArgument = jest.fn();
helpers.default.generateVideo = jest.fn();
options.saveAllVideos = false;
configModule.default.saveAllVideos = false;
configModule.default.usingAllure = false;
});
if (test.state === 'failed' || (test.state === 'passed' && config.saveAllVideos)) {
const filePath = path.resolve(this.recordingPath, this.frameNr.toString().padStart(4, '0') + '.png');
try {
browser.saveScreenshot(filePath);
helpers.debugLog('- Screenshot!!\n');
} catch (e) {
fs.writeFile(filePath, notAvailableImage, 'base64');
helpers.debugLog('- Screenshot not available...\n');
}
const videoPath = path.resolve(config.outputDir, this.testname + '.mp4');
this.videos.push(videoPath);
if (config.usingAllure) {
allureReporter.addAttachment('Execution video', videoPath, 'video/mp4');
}
const command = `"${ffmpegPath}" -y -r 10 -i "${this.recordingPath}/%04d.png" -vcodec libx264` +
` -crf 32 -pix_fmt yuv420p -vf "scale=1200:trunc(ow/a/2)*2","setpts=${config.videoSlowdownMultiplier}.0*PTS"` +
` "${path.resolve(config.outputDir, this.testname)}.mp4"`;
helpers.debugLog(`ffmpeg command: ${command}\n`);
this.ffmpegCommands.push(command);
}
}