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

add support to set UiAutomator Congfigurator values #153

Closed
wants to merge 5 commits into from
Closed
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
16 changes: 14 additions & 2 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class AndroidDriver extends BaseDriver {
this.sessionChromedrivers = {};
this.jwpProxyActive = false;
this.jwpProxyAvoid = _.clone(NO_PROXY);
this.settings = new DeviceSettings({ignoreUnimportantViews: false},
this.onSettingsUpdate.bind(this));
this.settings = new DeviceSettings({ignoreUnimportantViews: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a little formatting work. first, let's do one key/value per line. second, we do key: value (with a space after colon. third, we do:

foo({
  new: 'line',
  before: 'keys/values'
});

to save horizontal space :-)

setWaitForIdleTimeout: 10000, setWaitForSelectorTimeout:10000,
setKeyInjectionDelay:0,
setActionAcknowledgmentTimeout:3000, setScrollAcknowledgmentTimeout:200
}, this.onSettingsUpdate.bind(this));
this.chromedriver = null;
this.apkStrings = {};
this.acceptSslCerts = !!opts.acceptSslCerts;
Expand Down Expand Up @@ -155,6 +158,9 @@ class AndroidDriver extends BaseDriver {
if (key === "ignoreUnimportantViews") {
await this.setCompressedLayoutHierarchy(value);
}
if (key === "configurator") {
await this.setConfiguratorConfig(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would configurator 'values' look like here? wouldn't they actually be a combination of key and value? are they supposed to be JSON objects?

}
}

async startAndroidSession () {
Expand Down Expand Up @@ -287,6 +293,12 @@ class AndroidDriver extends BaseDriver {
await this.bootstrap.sendAction("compressedLayoutHierarchy", {compressLayout: compress});
}

// Set UiAutomator Configurator related configurations
// value sould be like {"method":"setWaitForIdleTimeout","value":5000}
async setConfiguratorConfig (value) {
await this.bootstrap.sendAction("configurator", JSON.parse(value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes I see you're expecting JSON objects. I'd love to see a bit of nicer error handling, something like:

let param;
try {
  param = JSON.parse(value);
} catch (e) {
  log.errorAndThrow(`Configurator values must be valid JSON! Original error: ${e}`);
}
await this.bootstrap.sendAction("configurator", param);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be best to also check that it is a String before trying to parse it. I can see problems if an actual JSON object (rather than a stringified version) was passed in.

}

async deleteSession () {
log.debug("Shutting down Android driver");
await super.deleteSession();
Expand Down