mirror of
https://github.com/appium/appium.git
synced 2026-10-28 20:31:51 +08:00
* add -image locator strategy and related logic * use appium-support jimp helper * handle find multiple elements by image * update staleness check variable name * ensure that a settings object always exists so we can rely on global settings always existing too * only fix template size if user requests it in settings * add note about implicit wait error handling * only automatically update image element position if user turns on an appropriate setting * add setting to control whether we check for image element staleness * add setting to determine the image element tap strategy (w3c or mjsonwp) * prefer single quotes * add setting to turn off screenshot resizing if not desired * add docstrings (except for cache class which we may not keep) * address additional review comments * add better jsdoc arg info * use lru-cache npm package instead of rolling our own * use new versino of appium-support * make sure the lru cache is checking element size correctly * give better names and tighten up logic around image el tap strategies * add some unit tests for image elements * ensure DeviceSettings has a default no-op update method * check that driver implements action strategies and fall back / throw as appropriate * finish out image element unit tests * have basedriver set noop onSettingsUpdate rather than doing it in DeviceSettings * move route avoidance detection from protocol to driver * handle proxying actions to downstream drivers during image tap * tighten up logic for deciding whether to proxy based on presence of image element * add find by image specs and fix issues that arose in the process * clean up regexes * don't try to be smart and proxy actions for drivers; let them set it up themselves to support image elements * change default match threshold based on experimentation * export which settings are handled by basedriver so downstream drivers can utilize this information * make sure to include a duration for the initial pointerMove action * add docstring to proxyRouteIsAvoided
113 lines
4.7 KiB
JavaScript
113 lines
4.7 KiB
JavaScript
// transpile:mocha
|
|
|
|
import '../..'; // NOTE: For some reason this file needs to be imported to prevent a babel error
|
|
import chai from 'chai';
|
|
import sinon from 'sinon';
|
|
import chaiAsPromised from 'chai-as-promised';
|
|
import { MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY, parseProtocol, driverShouldDoJwpProxy, IMAGE_ELEMENT_PREFIX } from '../../lib/protocol/protocol';
|
|
import BaseDriver from '../../lib/basedriver/driver';
|
|
|
|
chai.should();
|
|
chai.use(chaiAsPromised);
|
|
|
|
describe('Protocol', async function () {
|
|
|
|
describe('#parseProtocol', function () {
|
|
it('should parse {protocol: "MJSONWP"} as MJSONWP', function () {
|
|
parseProtocol({protocol: 'MJSONWP', value: undefined}).should.eql({isW3C: false, isMJSONWP: true, value: undefined});
|
|
});
|
|
it('should parse {protocol: "W3C"} as W3C', function () {
|
|
parseProtocol({protocol: 'W3C', value: undefined}).should.eql({isW3C: true, isMJSONWP: false, value: undefined});
|
|
});
|
|
it('should parse {protocol: "MJSONWP", value: false} as MJSONWP with value: false', function () {
|
|
parseProtocol({protocol: 'MJSONWP', value: false}).should.eql({isW3C: false, isMJSONWP: true, value: false});
|
|
});
|
|
it('should parse {protocol: "W3C", value: 0} as W3C with value: 0', function () {
|
|
parseProtocol({protocol: 'W3C', value: 0}).should.eql({isW3C: true, isMJSONWP: false, value: 0});
|
|
});
|
|
it('should parse {protocol: "MJSONWP", value: "string"}', function () {
|
|
parseProtocol({protocol: 'MJSONWP', value: "string"}).should.eql({isW3C: false, isMJSONWP: true, value: "string"});
|
|
});
|
|
it('should parse {protocol: "W3C", value: {obj}}', function () {
|
|
const value = {hello: 'world', goodbye: 'whirl'};
|
|
parseProtocol({protocol: 'MJSONWP', value}).should.eql({isW3C: false, isMJSONWP: true, value});
|
|
});
|
|
it('should throw if {protocol: "MJSONWP", error}', function () {
|
|
const error = new Error('some error');
|
|
parseProtocol({protocol: 'W3C', error}).error.should.equal(error);
|
|
});
|
|
});
|
|
|
|
describe('#driverShouldDoJwpProxy', function () {
|
|
it('should not proxy if an image element is found in request url', function () {
|
|
const d = new BaseDriver();
|
|
sinon.stub(d, 'proxyActive').returns(true);
|
|
sinon.stub(d, 'proxyRouteIsAvoided').returns(false);
|
|
const hasImageElements = [
|
|
`/wd/hub/session/:sessionId/element/${IMAGE_ELEMENT_PREFIX}bar`,
|
|
`/wd/hub/session/:sessionId/element/${IMAGE_ELEMENT_PREFIX}bar/click`,
|
|
`/wd/hub/session/:sessionId/element/${IMAGE_ELEMENT_PREFIX}bar/submit`,
|
|
`/wd/hub/session/:sessionId/screenshot/${IMAGE_ELEMENT_PREFIX}bar`,
|
|
];
|
|
const noImageElements = [
|
|
`/wd/hub/session/:sessionId/element/${IMAGE_ELEMENT_PREFIX}`,
|
|
`/wd/hub/session/:sessionId/screenshot/${IMAGE_ELEMENT_PREFIX}`,
|
|
`/wd/hub/session/:sessionId/element/bar${IMAGE_ELEMENT_PREFIX}`,
|
|
'/wd/hub/session/:sessionId/element/element123',
|
|
'/wd/hub/session/:sessionId/title',
|
|
`/wd/hub/session/:sessionId/notelement/${IMAGE_ELEMENT_PREFIX}bar`,
|
|
];
|
|
for (let testCase of hasImageElements) {
|
|
const req = {body: {}, params: {}, originalUrl: testCase};
|
|
driverShouldDoJwpProxy(d, req, null).should.be.false;
|
|
}
|
|
for (let testCase of noImageElements) {
|
|
const req = {body: {}, params: {}, originalUrl: testCase};
|
|
driverShouldDoJwpProxy(d, req, null).should.be.true;
|
|
}
|
|
});
|
|
it('should not proxy if an image element is found in request body', function () {
|
|
const d = new BaseDriver();
|
|
sinon.stub(d, 'proxyActive').returns(true);
|
|
sinon.stub(d, 'proxyRouteIsAvoided').returns(false);
|
|
const hasImageElements = [{
|
|
[W3C_ELEMENT_KEY]: `${IMAGE_ELEMENT_PREFIX}bar`,
|
|
}, {
|
|
[W3C_ELEMENT_KEY]: `${IMAGE_ELEMENT_PREFIX}foo`,
|
|
}, {
|
|
[MJSONWP_ELEMENT_KEY]: `${IMAGE_ELEMENT_PREFIX}bar`,
|
|
}];
|
|
const noImageElements = [{
|
|
[IMAGE_ELEMENT_PREFIX]: 'foo',
|
|
}, {
|
|
[W3C_ELEMENT_KEY]: `${IMAGE_ELEMENT_PREFIX}`,
|
|
}, {
|
|
[MJSONWP_ELEMENT_KEY]: `${IMAGE_ELEMENT_PREFIX}`,
|
|
}, {
|
|
foo: 'bar',
|
|
}, {
|
|
[W3C_ELEMENT_KEY]: 'bar',
|
|
}, {
|
|
[MJSONWP_ELEMENT_KEY]: 'bar',
|
|
}, {
|
|
foo: `${IMAGE_ELEMENT_PREFIX}bar`,
|
|
}, {
|
|
foo: `bar${IMAGE_ELEMENT_PREFIX}`
|
|
}, {
|
|
[W3C_ELEMENT_KEY]: `bar${IMAGE_ELEMENT_PREFIX}`
|
|
}, {
|
|
[MJSONWP_ELEMENT_KEY]: `bar${IMAGE_ELEMENT_PREFIX}`
|
|
}];
|
|
for (let testCase of hasImageElements) {
|
|
const req = {body: testCase, params: {}};
|
|
driverShouldDoJwpProxy(d, req, null).should.be.false;
|
|
}
|
|
for (let testCase of noImageElements) {
|
|
const req = {body: testCase, params: {}};
|
|
driverShouldDoJwpProxy(d, req, null).should.be.true;
|
|
}
|
|
|
|
});
|
|
});
|
|
});
|