Fix setting alert text for W3C protocol
MODIFY
lib/protocol/routes.js
lib/protocol/routes.js
@@ -178,21 +178,20 @@ const METHOD_MAP = {
GET: {command: 'getText'}
},
'/wd/hub/session/:sessionId/element/:elementId/value': {
- POST: {command: 'setValue', payloadParams: {
- validate: (jsonObj) => {
- return (!jsonObj.value && !jsonObj.text) &&
- 'we require one of "text" or "value" params';
- },
+ POST: {
+ command: 'setValue',
+ payloadParams: {
+ validate: (jsonObj) => (!util.hasValue(jsonObj.value) && !util.hasValue(jsonObj.text)) &&
+ 'we require one of "text" or "value" params',
optional: ['value', 'text'],
- makeArgs: (jsonObj) => {
// override the default argument constructor because of the special
// logic here. Basically we want to accept either a value (old JSONWP)
// or a text (new W3C) parameter, but only send one of them to the
// command (not both). Prefer 'value' since it's more
// backward-compatible.
- return [jsonObj.value || jsonObj.text];
+ makeArgs: (jsonObj) => [jsonObj.value || jsonObj.text],
+ }
}
- }}
},
'/wd/hub/session/:sessionId/keys': {
POST: {command: 'keys', payloadParams: {required: ['value']}}
@@ -573,7 +572,16 @@ const METHOD_MAP = {
// https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts
'/wd/hub/session/:sessionId/alert/text': {
GET: {command: 'getAlertText'},
- POST: {command: 'setAlertText', payloadParams: {required: ['text']}}
+ POST: {
+ command: 'setAlertText',
+ payloadParams: {
+ validate: (jsonObj) => (!util.hasValue(jsonObj.value) && !util.hasValue(jsonObj.text)) &&
+ 'either "text" or "value" must be set',
+ optional: ['value', 'text'],
+ // Prefer 'value' since it's more backward-compatible.
+ makeArgs: (jsonObj) => [jsonObj.value || jsonObj.text],
+ }
+ }
},
'/wd/hub/session/:sessionId/alert/accept': {
POST: {command: 'postAcceptAlert'}

MODIFY
test/protocol/routes-specs.js
test/protocol/routes-specs.js
@@ -40,7 +40,7 @@ describe('Protocol', function () {
}
let hash = shasum.digest('hex').substring(0, 8);
// Modify the hash whenever the protocol has intentionally been modified.
- hash.should.equal('034668ae');
+ hash.should.equal('9e59ddee');
});
});

Fix setting alert text for W3C protocol (#254)