diff --git a/lib/commands/record-screen.js b/lib/commands/record-screen.js index 7adc3fa..cf9e9ac 100644 --- a/lib/commands/record-screen.js +++ b/lib/commands/record-screen.js @@ -234,7 +234,7 @@ export class ScreenRecorder { * (`false`) or to start a new recording immediately and terminate the existing one if running (`true`). * @throws {Error} If screen recording has failed to start or is not supported on the device under test. */ -export async function startRecordingScreen ( +export async function windowsStartRecordingScreen ( timeLimit, videoFilter, fps, @@ -301,7 +301,7 @@ export async function startRecordingScreen ( * or the file content cannot be uploaded to the remote location * or screen recording is not supported on the device under test. */ -export async function stopRecordingScreen ( +export async function windowsStopRecordingScreen ( remotePath, user, pass, @@ -335,6 +335,97 @@ export async function stopRecordingScreen ( }); } +/** + * Record the display in background while the automated test is running. + * This method requires FFMPEG (https://www.ffmpeg.org/download.html) to be installed + * and present in PATH. + * The resulting video uses H264 codec and is ready to be played by media players built-in into web browsers. + * + * @param {StartRecordingOptions} [options] - The available options. + * @this {import('../driver').WindowsDriver} + * @throws {Error} If screen recording has failed to start or is not supported on the device under test. + */ +export async function startRecordingScreen(options = {}) { + const { + timeLimit, + videoFilter, + fps, + preset, + captureCursor, + captureClicks, + audioInput, + forceRestart = true, + } = options; + + await this.windowsStartRecordingScreen( + timeLimit, + videoFilter, + fps, + preset, + captureCursor, + captureClicks, + audioInput, + forceRestart + ); +} + +/** + * Stop recording the screen. + * If no screen recording has been started before then the method returns an empty string. + * + * @param {StopRecordingOptions} [options] - The available options. + * @returns {Promise} Base64-encoded content of the recorded media file if 'remotePath' + * parameter is falsy or an empty string. + * @this {import('../driver').WindowsDriver} + * @throws {Error} If there was an error while getting the name of a media file + * or the file content cannot be uploaded to the remote location + * or screen recording is not supported on the device under test. + */ +export async function stopRecordingScreen(options = {}) { + const {remotePath, user, pass, method, headers, fileFieldName, formFields} = options; + + return await this.windowsStopRecordingScreen( + remotePath, + user, + pass, + method, + headers, + fileFieldName, + formFields + ); +} + /** * @typedef {import('../driver').WindowsDriver} WindowsDriver */ + +/** + * For detailed explanations of each property, + * please refer to the parameters of the {@linkcode windowsStartRecordingScreen} function. + * + * @typedef {Object} StartRecordingOptions + * + * @property {string} [videoFilter] + * @property {number|string} [fps=15] + * @property {string} [preset='veryfast'] + * @property {boolean} [captureCursor=false] + * @property {boolean} [captureClicks=false] + * @property {string} [audioInput] + * @property {string|number} [timeLimit=600] + * @property {boolean} [forceRestart=true] + */ + +/** + * For detailed explanations of each property, + * please refer to the parameters of the {@linkcode windowsStopRecordingScreen} function. + * + * @typedef {Object} StopRecordingOptions + * + * @property {string} [remotePath] + * @property {string} [user] + * @property {string} [pass] + * @property {string} [method] + * @property {Object} [headers] + * @property {string} [fileFieldName='file'] + * @property {Object[]|[string, string][]} [formFields] + */ \ No newline at end of file diff --git a/lib/driver.js b/lib/driver.js index 622cfad..ef82bb1 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -204,6 +204,8 @@ export class WindowsDriver extends BaseDriver { execPowerShell = powershellCommands.execPowerShell; + windowsStartRecordingScreen = recordScreenCommands.windowsStartRecordingScreen; + windowsStopRecordingScreen = recordScreenCommands.windowsStopRecordingScreen; startRecordingScreen = recordScreenCommands.startRecordingScreen; stopRecordingScreen = recordScreenCommands.stopRecordingScreen; diff --git a/lib/execute-method-map.ts b/lib/execute-method-map.ts index 783ad4f..5e7fca1 100644 --- a/lib/execute-method-map.ts +++ b/lib/execute-method-map.ts @@ -2,10 +2,11 @@ import { ExecuteMethodMap } from '@appium/types'; export const executeMethodMap = { 'windows: startRecordingScreen': { - command: 'startRecordingScreen', + command: 'windowsStartRecordingScreen', params: { optional: [ 'timeLimit', + 'videoFilter', 'fps', 'preset', 'captureCursor', @@ -16,7 +17,7 @@ export const executeMethodMap = { }, }, 'windows: stopRecordingScreen': { - command: 'stopRecordingScreen', + command: 'windowsStopRecordingScreen', params: { optional: [ 'remotePath',