Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 116 additions & 2 deletions lib/commands/record-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -335,6 +335,120 @@ export async function stopRecordingScreen (
});
}

/**
Comment thread
mykola-mokhnach marked this conversation as resolved.
Outdated
* @typedef {Object} StartRecordingOptions
*
* @property {string} videoFilter - The video filter spec to apply for ffmpeg.
Comment thread
mykola-mokhnach marked this conversation as resolved.
Outdated
* See https://trac.ffmpeg.org/wiki/FilteringGuide for more details on the possible values.
* Example: Set it to `scale=ifnot(gte(iw\,1024)\,iw\,1024):-2` in order to limit the video width
* to 1024px. The height will be adjusted automatically to match the actual ratio.
* @property {number|string} fps [15] - The count of frames per second in the resulting video.
* The greater fps it has the bigger file size is.
* @property {string} preset [veryfast] - One of the supported encoding presets. Possible values are:
* - ultrafast
* - superfast
* - veryfast
* - faster
* - fast
* - medium
* - slow
* - slower
* - veryslow
* A preset is a collection of options that will provide a certain encoding speed to compression ratio.
* A slower preset will provide better compression (compression is quality per filesize).
* This means that, for example, if you target a certain file size or constant bit rate, you will achieve better
* quality with a slower preset. Read https://trac.ffmpeg.org/wiki/Encode/H.264 for more details.
* @property {boolean} captureCursor [false] - Whether to capture the mouse cursor while recording
* the screen
* @property {boolean} captureClicks [false] - Whether to capture mouse clicks while recording the
* screen
* @property {string} audioInput - If set then the given audio input will be used to record the computer audio
* along with the desktop video. The list of available devices could be retrieved using
* `ffmpeg -list_devices true -f dshow -i dummy` command.
* @property {string|number} timeLimit [600] - The maximum recording time, in seconds. The default
* value is 600 seconds (10 minutes).
* @property {boolean} forceRestart [true] - Whether to ignore the call if a screen recording is currently running
* (`false`) or to start a new recording immediately and terminate the existing one if running (`true`).
*/

/**
* 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
);
}

/**
* @typedef {Object} StopRecordingOptions
*
* @property {string} remotePath - The path to the remote location, where the resulting video should be uploaded.
* The following protocols are supported: http/https, ftp.
* Null or empty string value (the default setting) means the content of resulting
* file should be encoded as Base64 and passed as the endpoint response value.
* An exception will be thrown if the generated media file is too big to
* fit into the available process memory.
* @property {string} user - The name of the user for the remote authentication.
* @property {string} pass - The password for the remote authentication.
* @property {string} method - The http multipart upload method name. The 'PUT' one is used by default.
* @property {Object} headers - Additional headers mapping for multipart http(s) uploads
* @property {string} fileFieldName [file] - The name of the form field, where the file content BLOB should be stored for
* http(s) uploads
* @property {Object[]|[string, string][]} formFields - Additional form fields for multipart http(s) uploads
*/

/**
* 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<string>} 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
*/
2 changes: 2 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ export class WindowsDriver extends BaseDriver {

execPowerShell = powershellCommands.execPowerShell;

windowsStartRecordingScreen = recordScreenCommands.windowsStartRecordingScreen;
windowsStopRecordingScreen = recordScreenCommands.windowsStopRecordingScreen;
startRecordingScreen = recordScreenCommands.startRecordingScreen;
stopRecordingScreen = recordScreenCommands.stopRecordingScreen;

Expand Down
5 changes: 3 additions & 2 deletions lib/execute-method-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -16,7 +17,7 @@ export const executeMethodMap = {
},
},
'windows: stopRecordingScreen': {
command: 'stopRecordingScreen',
command: 'windowsStopRecordingScreen',
params: {
optional: [
'remotePath',
Expand Down