Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Make proxy convert /property to /attribute #311

Merged
merged 2 commits into from
Apr 8, 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
12 changes: 11 additions & 1 deletion lib/jsonwp-proxy/protocol-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY } from '../protocol/protocol';
const log = logger.getLogger('Protocol Converter');


const COMMAND_URLS_CONFLICTS = [
export const COMMAND_URLS_CONFLICTS = [
{
commandNames: ['execute', 'executeAsync'],
jsonwpConverter: (url) => url.replace(/\/execute.*/,
Expand Down Expand Up @@ -35,6 +35,16 @@ const COMMAND_URLS_CONFLICTS = [
: url.replace(/\/window_handles$/, '/window/handles');
},
},
{
commandNames: ['getProperty'],
jsonwpConverter: (w3cUrl) => {
const w3cPropertyRegex = /\/element\/([^/]+)\/property\/([^/]+)/;
const jsonwpUrl = w3cUrl.replace(w3cPropertyRegex, '/element/$1/attribute/$2');
log.info(`Converting W3C '${w3cUrl}' to '${jsonwpUrl}'`);
return jsonwpUrl;
},
w3cConverter: (jsonwpUrl) => jsonwpUrl // Don't convert JSONWP URL to W3C. W3C accepts /attribute and /property
}
];

const {MJSONWP, W3C} = BaseDriver.DRIVER_PROTOCOL;
Expand Down
23 changes: 22 additions & 1 deletion test/jsonwp-proxy/protocol-converter-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* global describe:true, it:true */

import _ from 'lodash';
import ProtocolConverter from '../../lib/jsonwp-proxy/protocol-converter';
import ProtocolConverter, {COMMAND_URLS_CONFLICTS} from '../../lib/jsonwp-proxy/protocol-converter';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import BaseDriver from '../../lib/basedriver/driver';
Expand Down Expand Up @@ -112,4 +112,25 @@ describe('Protocol Converter', function () {
});
});
});
describe('getProperty', function () {
let jsonwpConverter, w3cConverter;
before(function () {
for (let command of COMMAND_URLS_CONFLICTS) {
if (command.commandNames.includes('getProperty')) {
jsonwpConverter = command.jsonwpConverter;
w3cConverter = command.w3cConverter;
}
}
});
it('should convert "property/value" to "attribute/value"', function () {
jsonwpConverter('/session/123/element/456/property/value').should.equal('/session/123/element/456/attribute/value');
});
it('should convert "property/:somePropName" to "attribute/:somePropName"', function () {
jsonwpConverter('/session/123/element/456/property/somePropName').should.equal('/session/123/element/456/attribute/somePropName');
});
it('should not convert from JSONWP to W3C', function () {
w3cConverter('/session/123/element/456/attribute/someAttr').should.equal('/session/123/element/456/attribute/someAttr');
w3cConverter('/session/123/element/456/property/someProp').should.equal('/session/123/element/456/property/someProp');
});
});
});