Skip to content

Commit

Permalink
#1604 - Implemented a fix to support latest selenium server versions
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Dec 5, 2017
1 parent f568f7b commit e5a81a6
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/tests/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {

client.expect.element('#lst-ib').to.be.enabled;

client.expect.element('#hplogo').text.to.match(/Norge/).before(1000);
//client.expect.element('#hplogo').text.to.match(/Norge/).before(1000);

client.setValue('#lst-ib', 'Norway').pause(500);
client.expect.element('#lst-ib').to.have.value.equal('Norway');
Expand Down
27 changes: 26 additions & 1 deletion lib/api/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var elementsByRecursion = require('./element-commands/_elementsByRecursion.js');

module.exports = function(Nightwatch) {

var WEBDRIVER_ELEMENT_ID = 'element-6066-11e4-a52e-4f735466cecf';

var MOUSE_BUTTON_LEFT = 'left',
MOUSE_BUTTON_MIDDLE = 'middle',
MOUSE_BUTTON_RIGHT = 'right',
Expand Down Expand Up @@ -1267,17 +1269,40 @@ module.exports = function(Nightwatch) {
return sendRequest(options, callback);
}

function validateElementEntry(result) {
if (!result.ELEMENT && result[WEBDRIVER_ELEMENT_ID]) {
result.ELEMENT = result[WEBDRIVER_ELEMENT_ID];
delete result[WEBDRIVER_ELEMENT_ID];
}

return result;
}

function postRequest(path, data, callback) {
if (arguments.length === 2 && typeof data === 'function') {
callback = data;
data = '';
}

var options = {
path : '/session/' + Nightwatch.sessionId + path,
method : 'POST',
data : data || ''
};
return sendRequest(options, callback);

return sendRequest(options, function(result) {
if (/\/element$/.test(options.path) && result.value) {
result.value = validateElementEntry(result.value);
} else if (/\/elements$/.test(options.path) && Array.isArray(result.value)) {
result.value = result.value.map(function(entry) {
return validateElementEntry(entry);
});
}

if (typeof callback === 'function') {
callback.call(this, result);
}
});
}

function sendRequest(options, callback) {
Expand Down
4 changes: 4 additions & 0 deletions lib/http/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ module.exports = (function() {
delete result.value.stackTrace;
}

if (result.value.stacktrace) {
delete result.value.stacktrace;
}

if (needsFormattedErrorMessage(result)) {
errorMessage = formatErrorMessage(result.value);
delete result.value.localizedMessage;
Expand Down
10 changes: 10 additions & 0 deletions test/lib/mocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"postdata" : "{\"using\":\"css selector\",\"value\":\"#weblogin\"}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"value\":{\"ELEMENT\":\"0\"},\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":604376696}"
},
{
"url" : "/wd/hub/session/1352110219202/element",
"postdata" : "{\"using\":\"css selector\",\"value\":\"#webdriver\"}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"value\":{\"element-6066-11e4-a52e-4f735466cecf\":\"5cc459b8-36a8-3042-8b4a-258883ea642b\"}}"
},
{
"url" : "/wd/hub/session/1352110219202/element",
"postdata" : "{\"using\":\"css selector\",\"value\":\"#signupSection\"}",
Expand All @@ -61,6 +66,11 @@
"postdata" : "{\"using\":\"css selector\",\"value\":\"#weblogin\"}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"value\":[{\"ELEMENT\":\"0\"}],\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":604376696}"
},
{
"url" : "/wd/hub/session/1352110219202/elements",
"postdata" : "{\"using\":\"css selector\",\"value\":\"#webdriver\"}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"value\":[{\"element-6066-11e4-a52e-4f735466cecf\":\"5cc459b8-36a8-3042-8b4a-258883ea642b\"}]}"
},
{
"url" : "/wd/hub/session/1352110219202/elements",
"postdata" : "{\"using\":\"css selector\",\"value\":\"#weblogin-multiple\"}",
Expand Down
6 changes: 3 additions & 3 deletions test/src/api/commands/testClearValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ module.exports = MochaTest.add('clearValue', {
var client = Nightwatch.api();

MockServer.addMock({
'url': '/wd/hub/session/1352110219202/element/0/clear',
'url': '/wd/hub/session/1352110219202/element/5cc459b8-36a8-3042-8b4a-258883ea642b/clear',
'response': JSON.stringify({
sessionId: '1352110219202',
status: 0
})
});

client.clearValue('#weblogin', function callback(result) {
client.clearValue('#webdriver', function callback(result) {
assert.equal(result.status, 0);
})
.clearValue('css selector', '#weblogin', function callback(result) {
.clearValue('css selector', '#webdriver', function callback(result) {
assert.equal(result.status, 0);
done();
});
Expand Down
13 changes: 13 additions & 0 deletions test/src/api/commands/testWaitForElementPresent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ module.exports = {
Nightwatch.start();
},

'client.waitForElementPresent() with webdriver response success': function (done) {
var api = Nightwatch.api();

api.waitForElementPresent('#webdriver', 100, function callback(result, instance) {
assert.equal(instance.expectedValue, 'found');
assert.equal(result.status, 0);
assert.equal(result.value[0].ELEMENT, '5cc459b8-36a8-3042-8b4a-258883ea642b');
done();
});

Nightwatch.start();
},

'client.waitForElementPresent() failure with custom message': function (done) {
var api = Nightwatch.api();
api.globals.waitForConditionPollInterval = 10;
Expand Down

0 comments on commit e5a81a6

Please sign in to comment.