1

This may sound rather crazy, but I cannot find a solution to automate taking screenshots on a cordova application.

I know I can take and save a screenshot of the emulator using

adb shell /system/bin/screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png screenshot.png

in the terminal, my crazy question is. Can I trigger these commands from a nodeJS automation script? or is this too far fetched and a terrible idea?

1 Answer 1

2

Simplest way to execute terminal commands from node.js would be to use child_process.exec

const exec = require('child_process').exec;
exec('adb shell /system/bin/screencap -p /sdcard/screenshot.png', (error, stdout, stderr) => {
   if (error) {
     console.error(`exec error: ${error}`);
     return;
   }
   console.log(`stdout: ${stdout}`);
   console.log(`stderr: ${stderr}`);
});

The built-in child_process module in node.js provides many functions such child_process.spawn, child_process.exec, child_process.execFile which can be used to execute terminal commands or other script files (.sh, .bat).

Sign up to request clarification or add additional context in comments.

1 Comment

you sir are a genius, thank you very much. I have been stuck on this problem for awhile!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.