How to use screenRecorder.start method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

ar.js

Source:ar.js Github

copy

Full Screen

1"use strict";2const fs = require('fs');3const http = require('http');4const path = require('path');5const Events = require('events');6const deepMixIn = require('mout/object/deepMixIn');7const pick = require('mout/object/pick');8const sprintf = require('nyks/string/format');9const defer = require('nyks/promise/defer');10const promisify = require('nyks/function/promisify');11const {vlc : VLC, ffmpeg : FFMPEG } = require('screen-capture-recorder');12const SWFReader = require('swf-properties');13const screenRotation = require('screen-rotation');14const ReOrientDisplay = promisify(screenRotation.ReOrientDisplay);15const GetDisplaySettings = promisify(screenRotation.GetDisplaySettings);16const express = require('express');17const mv = promisify(require('fs-extra').copy);18const nw = !!global.window;19const gui = nw ? window.require('nw.gui') : null;20class AnimationRecorder extends Events.EventEmitter {21 constructor(config) {22 super();23 this.config = {24 output_path : 'test.avi',25 capture_mode : 'html5', //or swf26 swf_version : '2.0', //1.0 or 2.027 duration : 180, //max duration28 width : 640,29 height : 480,30 debug : false,31 orientation : "auto", //or 'keep'32 };33 deepMixIn(this.config, config);34 if(this.config.debug) {35 gui.Window.get().show();36 gui.Window.get().showDevTools();37 gui.Window.get().hide();38 }39 var source_path = this.config.source_path;40 if(!source_path)41 throw new Error("Missing source path");42 if(process.env.CWD) {43 this.config.source_path = path.join(process.env.CWD, this.config.source_path);44 this.config.output_path = path.join(process.env.CWD, this.config.output_path);45 }46 this.config.source_path = path.resolve(source_path);47 this.config.source_name = path.basename(this.config.source_path);48 if(!this.config.output_path)49 throw new Error("Missing output path");50 this.config.output_path = path.resolve(this.config.output_path);51 var app = express();52 app.use(express.static(path.dirname(source_path)));53 var template = fs.readFileSync(path.join(__dirname, '_flash_bootstrap.html'), "utf-8");54 template = template.replace("{MOVIE_NAME}", this.config.source_name);55 app.use('/_flash_bootstrap.html', function(req, res) { res.end(template); });56 this.server = http.createServer(app);57 console.log("Path is ", this.config.source_path);58 const recorder_args = [{x : 0, y : 0, w : this.config.width, h : this.config.height}, {'fps' : 30}];59 this._screenrecorder = this.config.recorder == 'ffmpeg' ? new FFMPEG(...recorder_args) : this._screenrecorder = new VLC(...recorder_args);60 if(!fs.existsSync(source_path))61 throw "Invalid configuration source path";62 }63 async run() {64 if(this.config.capture_mode == "swf") {65 var props = await new Promise((resolve, reject) => {66 SWFReader(this.config.source_path, function(err, props) {67 if(err)68 return reject(err);69 resolve(props);70 });71 });72 if(this.config.swf_version == "1.0")73 this.config.duration = props.frameRate != 0 ? props.frameCount / props.frameRate : 0;74 this.config.width = props.frameSize.width;75 this.config.height = props.frameSize.height;76 }77 var size = pick(this.config, 'width', 'height');78 var getRotation = function(size, screen) {79 if(size.width <= screen.width && size.height <= screen.height)80 return 0;81 if(size.width <= screen.height && size.width <= screen.height)82 return 1;83 throw "Cannot find matching rotation";84 };85 var screenInfos = await GetDisplaySettings();86 var screen = {87 width : screenInfos.Size.Width,88 height : screenInfos.Size.Height,89 orientation : screenInfos.Orientation || screenInfos.orientation,90 };91 console.log({content : size, screen : screen, screenInfos});92 if(this.config.orientation == "auto") {93 var oriontation = getRotation(size, screen);94 if(oriontation !== screen.orientation)95 await ReOrientDisplay(oriontation);96 }97 this.port = await new Promise((resolve) => {98 this.server.listen(function() {99 resolve(this.address().port);100 });101 });102 await this._screenrecorder.warmup();103 await this.startGUI();104 }105 async startGUI() {106 var options = {107 focus : true,108 //toolbar:true || !!this.config.toolbar,109 //'new-instance': true,110 height : Number(this.config.height),111 width : Number(this.config.width),112 always_on_top : true,113 frame : false,114 resizable : false,115 show : false,116 };117 var frame_url = sprintf("http://127.0.0.1:%d/%s", this.port, this.config.capture_mode == "swf" ? "_flash_bootstrap.html" : this.config.source_name);118 console.log("Browsing to ", {frame_url}, {t : gui.Window.open});119 var appframe = await new Promise((resolve) => gui.Window.open(frame_url, options, resolve));120 if(!this.config.debug)121 appframe.on('closed', gui.App.quit);122 let waitAppLoaded = defer();123 appframe.once('loaded', waitAppLoaded.resolve.bind(null));124 await waitAppLoaded;125 console.log("LOADED");126 appframe.x = appframe.y = 0;127 appframe.show();128 console.log("CATPURE MODE", this.config.capture_mode);129 appframe.window.addEventListener("AR_BEGIN", async () => {130 await this._screenrecorder.StartRecord();131 console.log("Record started");132 });133 appframe.window.addEventListener("AR_END", async () => {134 const path = await this._screenrecorder.StopRecord();135 try {136 if(fs.existsSync(this.config.output_path))137 fs.unlinkSync(this.config.output_path);138 await mv(path, this.config.output_path);139 } catch(err) {140 console.log('get when stop recording', err);141 } finally {142 appframe.close();143 }144 });145 var timeout = this.config.duration * 1000;146 console.log("Will timeout after", this.config.duration);147 if(this.config.capture_mode == "swf" && this.config.swf_version == "1.0") {148 setTimeout(appframe.window.dispatchEvent.bind(appframe.window), 200, new Event("AR_BEGIN"));149 timeout += 200;150 }151 setTimeout(appframe.window.dispatchEvent.bind(appframe.window), timeout, new Event("AR_END"));152 }153}...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1// TiScreenRecorder : example app. 2// @kosso : November 20163// open a single window4var win = Ti.UI.createWindow({5 backgroundColor:'white'6});7var label = Ti.UI.createLabel({8 text: 'ready',9 backgroundColor: '#99ffffff',10 color: '#333',11 width: Ti.UI.SIZE,12 borderRadius: 6,13 bottom: 5,14 left: 5,15 zIndex: 1016});17win.add(label);18var screenrecorder = require('com.kosso.tiscreenrecorder');19var isRecording = false;20var btn_rec = Ti.UI.createButton({21 title: ' o ',22 width: 30,23 bottom: 5,24 zIndex: 10,25 height: 30,26 borderRadius: 15,27 color: 'white',28 tintColor: 'white',29 textAlign: 'center',30 backgroundColor: '#990000'31});32btn_rec.addEventListener('click', function(){33 if(isRecording){34 screenrecorder.stopRecording();35 label.text = 'stopped';36 setTimeout(function(){37 label.text = 'ready';38 }, 3000);39 } else {40 var d = new Date();41 var filename = 'recording_'+d.getTime()+'.mp4';42 var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);43 if ( file.exists() ) {44 file.deleteFile();45 }46 var video_url = file.nativePath; // eg: file:///etc/etc...47 file = null;48 console.log('video_url : ', video_url);49 50 screenrecorder.startRecording(video_url);51 // To just automatically save the video to the Camera Roll, leave out the video url 52 // eg: screenrecorder.startRecording();53 label.text = 'recording';54 55 }56 isRecording = !isRecording;57});58screenrecorder.addEventListener('success', function(e){59 console.log('screen recording done! : ', e);60 // Saved video is at e.nativePath (if a video_url was set)61});62// Just something to record... 63var wv = Ti.UI.createWebView({64 url : 'http://www.bbc.co.uk/news',65 width: Ti.UI.FILL,66 height: Ti.UI.FILL,67 backgroundColor: '#eee',68 zIndex: 169});70win.add(wv);71win.add(btn_rec);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async () => {7 const client = await remote(opts);8 await client.startRecordingScreen();9 await client.pause(5000);10 const video = await client.stopRecordingScreen();11 await client.deleteSession();12})();13const { remote } = require('webdriverio');14const opts = {15 capabilities: {16 }17};18(async () => {19 const client = await remote(opts);20 await client.startRecordingScreen({21 });22 await client.pause(5000);23 const video = await client.stopRecordingScreen();24 await client.deleteSession();25})();26const { remote } = require('webdriverio');27const opts = {28 capabilities: {29 }30};31(async () => {32 const client = await remote(opts);33 await client.startRecordingScreen({34 videoFilter: 'scale=iw*min(480/iw\,480/ih):ih*min(480/iw\,480/ih),pad=480:480:(480-iw)/2:(480-ih)/2

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Client } = require('appium-xcuitest-driver');2const opts = {3 videoFilter: 'scale=iw*min(480/iw\,320/ih):ih*min(480/iw\,320/ih),pad=480:320:(480-iw*min(480/iw\,320/ih))/2:(320-ih*min(480/iw\,320/ih))/2',4};5const client = new Client(opts);6client.startRecordingScreen();7client.stopRecordingScreen();

Full Screen

Using AI Code Generation

copy

Full Screen

1var screenRecorder = driver.getScreenRecorder();2screenRecorder.start({videoType: 'h264', videoFps: 10, videoScale: '1280x720', videoFilter: 'yadif', videoCodec: 'libx264', audioCodec: 'aac', audioChannels: 2, audioSampleRate: 44100, audioQuality: 0, videoBitrate: '1000k', audioBitrate: '128k'});3var screenRecorder = driver.getScreenRecorder();4screenRecorder.stop();5var screenRecorder = driver.getScreenRecorder();6var base64EncodedVideo = screenRecorder.getBase64EncodedVideo();7var screenRecorder = driver.getScreenRecorder();8screenRecorder.saveVideo('/path/to/video.mp4');9var screenRecorder = driver.getScreenRecorder();10var video = screenRecorder.getVideo();11var screenRecorder = driver.getScreenRecorder();12var isRecording = screenRecorder.isRecording();13var screenRecorder = driver.getScreenRecorder();14var videoSize = screenRecorder.getVideoSize();15var screenRecorder = driver.getScreenRecorder();16var videoCodec = screenRecorder.getVideoCodec();17var screenRecorder = driver.getScreenRecorder();18var videoFps = screenRecorder.getVideoFps();19var screenRecorder = driver.getScreenRecorder();20var videoBitrate = screenRecorder.getVideoBitrate();21var screenRecorder = driver.getScreenRecorder();22var audioCodec = screenRecorder.getAudioCodec();

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var screenRecorder = driver.startRecordingScreen({3});4driver.pause(10000);5var video = screenRecorder.stop();6fs.writeFileSync('video.mp4', video);7var fs = require('fs');8var screenRecorder = driver.startRecordingScreen({9});10driver.pause(10000);11var video = screenRecorder.stop();12fs.writeFileSync('video.mp4', video);13var fs = require('fs');14var screenRecorder = driver.startRecordingScreen({15});16driver.pause(10000);17var video = screenRecorder.stop();18fs.writeFileSync('video.mp4', video);19var fs = require('fs');20var screenRecorder = driver.startRecordingScreen({21});22driver.pause(10000);23var video = screenRecorder.stop();24fs.writeFileSync('video.mp4', video);25var fs = require('fs');26var screenRecorder = driver.startRecordingScreen({27});28driver.pause(10000);29var video = screenRecorder.stop();30fs.writeFileSync('video.mp4', video);31var fs = require('fs');32var screenRecorder = driver.startRecordingScreen({

Full Screen

Using AI Code Generation

copy

Full Screen

1await driver.startRecordingScreen({2});3await driver.stopRecordingScreen();4await driver.stopRecordingScreen();5let video = await driver.getRecordingScreen();6let video = await driver.getRecordingScreen();7let video = await driver.getRecordingScreen();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful