Skip to content

Commit

Permalink
feat(quiet/verbose): add --quiet and --verbose flags to control t…
Browse files Browse the repository at this point in the history
…he level of output

I added the `--quiet` flag for cases like:
`webdriver-manager start --detach; ./tests.sh; webdriver-manager shutdown`
where currently the selenium server output will get mixed in with other output.

I also added the `--verbose` flag for `webdriver-manager update` in case you *really* wanted to
see all the output which gets eaten by using `--android-accept-licenses`.
  • Loading branch information
sjelin committed Nov 18, 2016
1 parent 3ee3e1a commit 5a6f267
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
25 changes: 16 additions & 9 deletions lib/cmds/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ const noop = () => {};

// Make a function which configures a child process to automatically respond
// to a certain question
function respondFactory(question: string, answer: string): Function {
function respondFactory(question: string, answer: string, verbose: boolean): Function {
return (child: ChildProcess) => {
(<any>child.stdin).setDefaultEncoding('utf-8');
child.stdout.on('data', (data: Buffer | String) => {
if (data != null) {
if (verbose) {
process.stdout.write(data as string);
}
if (data.toString().indexOf(question) != -1) {
child.stdin.write(answer + '\n');
}
Expand Down Expand Up @@ -59,12 +62,13 @@ function runAndroidSDKCommand(

// Download updates via the android SDK
function downloadAndroidUpdates(
sdkPath: string, targets: string[], search_all: boolean, auto_accept: boolean): q.Promise<any> {
sdkPath: string, targets: string[], search_all: boolean, auto_accept: boolean,
verbose: boolean): q.Promise<any> {
return runAndroidSDKCommand(
sdkPath, 'update',
['sdk', '-u'].concat(search_all ? ['-a'] : []).concat(['-t', targets.join(',')]),
auto_accept ? 'pipe' : 'inherit',
auto_accept ? respondFactory('Do you accept the license', 'y') : noop);
auto_accept ? respondFactory('Do you accept the license', 'y', verbose) : noop);
}

// Setup hardware acceleration for x86-64 emulation
Expand Down Expand Up @@ -216,29 +220,32 @@ function configureAVDHardware(sdkPath: string, desc: AVDDescriptor): q.Promise<a
}

// Make an android virtual device
function makeAVD(sdkPath: string, desc: AVDDescriptor, version: string): q.Promise<any> {
function makeAVD(
sdkPath: string, desc: AVDDescriptor, version: string, verbose: boolean): q.Promise<any> {
return runAndroidSDKCommand(sdkPath, 'delete', ['avd', '--name', desc.avdName(version)])
.then(noop, noop)
.then(() => {
return runAndroidSDKCommand(
sdkPath, 'create',
['avd', '--name', desc.avdName(version), '--target', desc.api, '--abi', desc.abi],
'pipe', respondFactory('Do you wish to create a custom hardware profile', 'no'));
'pipe',
respondFactory('Do you wish to create a custom hardware profile', 'no', verbose));
});
}

// Initialize the android SDK
export function android(
sdkPath: string, apiLevels: string[], architectures: string[], platforms: string[],
acceptLicenses: boolean, version: string, oldAVDs: string[], logger: Logger): void {
acceptLicenses: boolean, version: string, oldAVDs: string[], logger: Logger,
verbose: boolean): void {
let avdDescriptors: AVDDescriptor[];
let tools = ['platform-tool', 'tool'];
if ((os.type() == 'Darwin') || (os.type() == 'Windows_NT')) {
tools.push('extra-intel-Hardware_Accelerated_Execution_Manager');
}

logger.info('android-sdk: Downloading additional SDK updates');
downloadAndroidUpdates(sdkPath, tools, false, acceptLicenses)
downloadAndroidUpdates(sdkPath, tools, false, acceptLicenses, verbose)
.then(() => {
return setupHardwareAcceleration(sdkPath);
})
Expand All @@ -249,7 +256,7 @@ export function android(
return downloadAndroidUpdates(
sdkPath, ['build-tools-24.0.0'].concat(
getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)),
true, acceptLicenses);
true, acceptLicenses, verbose);
})
.then(() => {
return getAVDDescriptors(sdkPath);
Expand All @@ -264,7 +271,7 @@ export function android(
.then(() => {
return sequentialForEach(avdDescriptors, (descriptor: AVDDescriptor) => {
logger.info('android-sdk: Setting up virtual device "' + descriptor.name + '"');
return makeAVD(sdkPath, descriptor, version);
return makeAVD(sdkPath, descriptor, version, verbose);
});
})
.then(() => {
Expand Down
4 changes: 4 additions & 0 deletions lib/cmds/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const AVD_USE_SNAPSHOTS = 'avd-use-snapshots';
export const STARTED_SIGNIFIER = 'started-signifier';
export const SIGNAL_VIA_IPC = 'signal-via-ipc';
export const DETACH = 'detach';
export const QUIET = 'quiet';
export const VERBOSE = 'verbose';

/**
* The options used by the commands.
Expand Down Expand Up @@ -108,5 +110,7 @@ opts[DETACH] = new Option(
DETACH,
'Once the selenium server is up and running, return control to the parent process and continue running the server in the background.',
'boolean', false);
opts[VERBOSE] = new Option(VERBOSE, 'Extra console output', 'boolean', false);
opts[QUIET] = new Option(QUIET, 'Minimal console output', 'boolean', false);

export var Opts = opts;
18 changes: 11 additions & 7 deletions lib/cmds/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let prog = new Program()
.addOption(Opts[Opt.AVD_USE_SNAPSHOTS])
.addOption(Opts[Opt.STARTED_SIGNIFIER])
.addOption(Opts[Opt.SIGNAL_VIA_IPC])
.addOption(Opts[Opt.QUIET])
.addOption(Opts[Opt.DETACH]);

if (os.type() === 'Darwin') {
Expand Down Expand Up @@ -72,6 +73,7 @@ function start(options: Options) {
}

let osType = os.type();
let stdio = options[Opt.QUIET].getBoolean() ? 'pipe' : 'inherit';
let binaries = FileManager.setupBinaries();
let seleniumPort = options[Opt.SELENIUM_PORT].getString();
let appiumPort = options[Opt.APPIUM_PORT].getString();
Expand Down Expand Up @@ -176,13 +178,13 @@ function start(options: Options) {
let avds = options[Opt.AVDS].getString();
startAndroid(
outputDir, binaries[AndroidSDK.id], avds.split(','),
options[Opt.AVD_USE_SNAPSHOTS].getBoolean(), avdPort);
options[Opt.AVD_USE_SNAPSHOTS].getBoolean(), avdPort, stdio);
} else {
logger.warn('Not starting android because it is not installed');
}
}
if (downloadedBinaries[Appium.id] != null) {
startAppium(outputDir, binaries[Appium.id], binaries[AndroidSDK.id], appiumPort);
startAppium(outputDir, binaries[Appium.id], binaries[AndroidSDK.id], appiumPort, stdio);
}

// log the command to launch selenium server
Expand All @@ -200,7 +202,7 @@ function start(options: Options) {
}
logger.info('java' + argsToString);

let seleniumProcess = spawn('java', args, 'inherit');
let seleniumProcess = spawn('java', args, stdio);
if (options[Opt.STARTED_SIGNIFIER].getString()) {
signalWhenReady(
options[Opt.STARTED_SIGNIFIER].getString(), options[Opt.SIGNAL_VIA_IPC].getBoolean(),
Expand All @@ -225,7 +227,8 @@ function start(options: Options) {
}

function startAndroid(
outputDir: string, sdk: Binary, avds: string[], useSnapshots: boolean, port: number): void {
outputDir: string, sdk: Binary, avds: string[], useSnapshots: boolean, port: number,
stdio: string): void {
let sdkPath = path.resolve(outputDir, sdk.executableFilename(os.type()));
if (avds[0] == 'all') {
avds = <string[]>require(path.resolve(sdkPath, 'available_avds.json'));
Expand Down Expand Up @@ -257,7 +260,7 @@ function startAndroid(
if (emuBin !== 'emulator') {
emuArgs = emuArgs.concat(['-qemu', '-enable-kvm']);
}
androidProcesses.push(spawn(path.resolve(sdkPath, 'tools', emuBin), emuArgs, 'inherit'));
androidProcesses.push(spawn(path.resolve(sdkPath, 'tools', emuBin), emuArgs, stdio));
});
}

Expand All @@ -271,14 +274,15 @@ function killAndroid() {
// Manage appium process
let appiumProcess: ChildProcess;

function startAppium(outputDir: string, binary: Binary, androidSDK: Binary, port: string) {
function startAppium(
outputDir: string, binary: Binary, androidSDK: Binary, port: string, stdio: string) {
logger.info('Starting appium server');
if (androidSDK) {
process.env.ANDROID_HOME = path.resolve(outputDir, androidSDK.executableFilename(os.type()));
}
appiumProcess = spawn(
path.resolve(outputDir, binary.filename(), 'node_modules', '.bin', 'appium'),
port ? ['--port', port] : []);
port ? ['--port', port] : [], stdio);
}

function killAppium() {
Expand Down
4 changes: 3 additions & 1 deletion lib/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let prog = new Program()
.command('update', 'install or update selected binaries')
.action(update)
.addOption(Opts[Opt.OUT_DIR])
.addOption(Opts[Opt.VERBOSE])
.addOption(Opts[Opt.IGNORE_SSL])
.addOption(Opts[Opt.PROXY])
.addOption(Opts[Opt.ALTERNATE_CDN])
Expand Down Expand Up @@ -98,6 +99,7 @@ function update(options: Options): void {
}
let ignoreSSL = options[Opt.IGNORE_SSL].getBoolean();
let proxy = options[Opt.PROXY].getString();
let verbose = options[Opt.VERBOSE].getBoolean();

// setup versions for binaries
let binaries = FileManager.setupBinaries(options[Opt.ALTERNATE_CDN].getString());
Expand Down Expand Up @@ -166,7 +168,7 @@ function update(options: Options): void {
initializeAndroid(
path.resolve(outputDir, binary.executableFilename(os.type())), android_api_levels,
android_architectures, android_platforms, android_accept_licenses,
binaries[AndroidSDK.id].versionCustom, JSON.parse(oldAVDList), logger);
binaries[AndroidSDK.id].versionCustom, JSON.parse(oldAVDList), logger, verbose);
});
}
if (ios) {
Expand Down

0 comments on commit 5a6f267

Please sign in to comment.