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

Handle mobile: calls in non-native context #527

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions lib/commands/execute.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import _ from 'lodash';
import { errors } from 'appium-base-driver';
import { errors, BaseDriver } from 'appium-base-driver';
import logger from '../logger';

let extensions = {};

extensions.execute = async function execute (script, args) {
if (script.match(/^mobile:/)) {
logger.info(`Executing native command '${script}'`);
script = script.replace(/^mobile:/, '').trim();
return await this.executeMobile(script, _.isArray(args) ? args[0] : args);
}

throw new errors.NotImplementedError();
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
const endpoint = this.chromedriver.jwproxy.downstreamProtocol === BaseDriver.DRIVER_PROTOCOL.MJSONWP
? '/execute'
: '/execute/sync';
return await this.chromedriver.jwproxy.command(endpoint, 'POST', {
script,
args,
});
};

extensions.executeMobile = async function executeMobile (mobileCommand, opts = {}) {
Expand Down
2 changes: 2 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const NO_PROXY = [
['POST', new RegExp('^/session/[^/]+/touch/multi/perform')],
['POST', new RegExp('^/session/[^/]+/orientation')],
['GET', new RegExp('^/session/[^/]+/orientation')],
['POST', new RegExp('^/session/[^/]+/execute')],
['POST', new RegExp('^/session/[^/]+/execute/sync')],
];

class AndroidDriver extends BaseDriver {
Expand Down
8 changes: 6 additions & 2 deletions test/unit/driver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ describe('driver', function () {
});
it('should proxy screenshot if nativeWebScreenshot is off', async function () {
await driver.createSession({platformName: 'Android', deviceName: 'device', browserName: 'chrome', nativeWebScreenshot: false});
driver.getProxyAvoidList().should.have.length(8);
driver.getProxyAvoidList()
.some((x) => x[1].toString().includes('/screenshot'))
.should.be.false;
});
it('should not proxy screenshot if nativeWebScreenshot is on', async function () {
await driver.createSession({platformName: 'Android', deviceName: 'device', browserName: 'chrome', nativeWebScreenshot: true});
driver.getProxyAvoidList().should.have.length(9);
driver.getProxyAvoidList()
.some((x) => x[1].toString().includes('/screenshot'))
.should.be.true;
});
it('should set networkSpeed before launching app', async function () {
sandbox.stub(driver, 'isEmulator').returns(true);
Expand Down