From b70c09f2dd399744a3267be6b903f6e5e346d8ad Mon Sep 17 00:00:00 2001 From: dpgraham Date: Thu, 28 Mar 2019 15:28:56 -0700 Subject: [PATCH 1/2] Make proxy convert /property to /attribute --- .travis.yml | 1 + lib/jsonwp-proxy/protocol-converter.js | 12 +++++++++- test/jsonwp-proxy/protocol-converter-specs.js | 23 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9560c9ba..198f97beb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - "8" - "10" + - "11" addons: apt: sources: diff --git a/lib/jsonwp-proxy/protocol-converter.js b/lib/jsonwp-proxy/protocol-converter.js index b3c8565b9..505a8f660 100644 --- a/lib/jsonwp-proxy/protocol-converter.js +++ b/lib/jsonwp-proxy/protocol-converter.js @@ -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.*/, @@ -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; diff --git a/test/jsonwp-proxy/protocol-converter-specs.js b/test/jsonwp-proxy/protocol-converter-specs.js index 32697b3d0..9d3382e94 100644 --- a/test/jsonwp-proxy/protocol-converter-specs.js +++ b/test/jsonwp-proxy/protocol-converter-specs.js @@ -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'; @@ -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"); + }); + }); }); From 256922f220fdda3ffaea38780d461e460e66e3b6 Mon Sep 17 00:00:00 2001 From: dpgraham Date: Mon, 8 Apr 2019 11:03:47 -0700 Subject: [PATCH 2/2] PR fix --- .travis.yml | 1 - test/jsonwp-proxy/protocol-converter-specs.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 198f97beb..d9560c9ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: node_js node_js: - "8" - "10" - - "11" addons: apt: sources: diff --git a/test/jsonwp-proxy/protocol-converter-specs.js b/test/jsonwp-proxy/protocol-converter-specs.js index 9d3382e94..76415c7de 100644 --- a/test/jsonwp-proxy/protocol-converter-specs.js +++ b/test/jsonwp-proxy/protocol-converter-specs.js @@ -123,14 +123,14 @@ describe('Protocol Converter', function () { } }); it('should convert "property/value" to "attribute/value"', function () { - jsonwpConverter("/session/123/element/456/property/value").should.equal("/session/123/element/456/attribute/value"); + 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"); + 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"); + 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'); }); }); });