Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update the way driver settings are updated #502

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all 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
35 changes: 5 additions & 30 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import log from '../logger';
import B from 'bluebird';
import { errors, BASEDRIVER_HANDLED_SETTINGS } from '@appium/base-driver';
import { errors } from '@appium/base-driver';
import { fs, tempDir } from '@appium/support';
import { APK_EXTENSION } from '../extensions';

Expand Down Expand Up @@ -231,39 +231,14 @@ commands.openNotifications = async function () {
};

commands.updateSettings = async function (settings) {
// we have some settings that are set on the settings object in the driver
// only, for example image finding settings. The uiauto2 server does not know
// what to do with them, so just set them on this driver's settings instance,
// and don't forward them to the server
let driverOnlySettings = {};
let serverSettings = {};
for (let [setting, value] of _.toPairs(settings)) {
if (BASEDRIVER_HANDLED_SETTINGS.includes(setting)) {
driverOnlySettings[setting] = value;
} else {
serverSettings[setting] = value;
}
}
if (!_.isEmpty(driverOnlySettings)) {
log.info(`Found some settings designed to be handled by BaseDriver: ` +
`${JSON.stringify(_.keys(driverOnlySettings))}. Not ` +
`sending these on to the UiAutomator2 server and instead ` +
`setting directly on the driver`);
await this.settings.update(driverOnlySettings);
}
if (!_.isEmpty(serverSettings)) {
log.info('Forwarding the following settings to the UiAutomator2 server: ' +
JSON.stringify(_.keys(serverSettings)));
await this.uiautomator2.jwproxy.command('/appium/settings', 'POST',
{settings: serverSettings});
}
await this.settings.update(settings);
await this.uiautomator2.jwproxy.command('/appium/settings', 'POST', {settings});
};

commands.getSettings = async function () {
// as above, we might have some driver-only settings to return as well
const driverOnlySettings = this.settings.getSettings();
const driverSettings = this.settings.getSettings();
const serverSettings = await this.uiautomator2.jwproxy.command('/appium/settings', 'GET');
return {...driverOnlySettings, ...serverSettings};
return {...driverSettings, ...serverSettings};
};

/**
Expand Down