Skip to content

Commit

Permalink
Revert "Add selector and error line for "staleElementReferenceError" (#…
Browse files Browse the repository at this point in the history
…4214)"

This reverts commit 23df1db.
  • Loading branch information
garg3133 authored Oct 25, 2024
1 parent 2fbeae3 commit d6cbeec
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 83 deletions.
16 changes: 0 additions & 16 deletions examples/tests/staleElementReferenceError.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/element/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class ElementCommand extends EventEmitter {
elementId = selector;
}

return this.transport.executeProtocolAction({actionName, args: [elementId, ...args, {selector: this.selector, stackTrace: this.stackTrace}], sessionId});
return this.transport.executeProtocolAction({actionName, args: [elementId, ...args], sessionId});
}

async complete(err, response) {
Expand Down
25 changes: 3 additions & 22 deletions lib/transport/selenium-webdriver/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const {error} = require('selenium-webdriver');

const {Logger, isObject, isFunction, isString} = require('../../utils');
const MethodMappings = require('./method-mappings.js');
const {filterStackTrace} = require('../../utils/stackTrace');

class TransportActions {
get transport() {
Expand Down Expand Up @@ -71,8 +70,7 @@ class TransportActions {

return this.makeResult(result);
} catch (err) {

const error = this.handleError(err, name, args);
const error = this.handleError(err, name);

return {
error,
Expand All @@ -98,7 +96,7 @@ class TransportActions {
return result;
}

handleError(err, commandName, args = undefined) {
handleError(err, commandName) {
let errorMsg = 'Unknown error';
try {
this.transport.handleErrorResponse(err);
Expand All @@ -125,24 +123,7 @@ class TransportActions {
const {shouldRegisterError} = this.transport;
const {lastError, retriesCount} = this;
if (shouldRegisterError(err) && (retriesCount < 1 || lastError && err.name !== lastError.name)) {
err.message = `Error while running .${commandName}() protocol action: ${errorMsg}\n`;

if (args && args.length > 0) {
const lastArg = args[args.length - 1];
if (lastArg && typeof lastArg === 'object' && !Array.isArray(lastArg)) {
const {selector = null, stackTrace = null} = lastArg;

if (selector) {
err.message += `Selector: ${selector}\n`;
}

if (stackTrace) {
err.stack = filterStackTrace(stackTrace);
}
}
}

Logger.error(err);
Logger.error(`Error while running .${commandName}() protocol action: ${errorMsg}\n`);
this.lastError = err;
}
if (this.lastError && err.name === this.lastError.name) {
Expand Down
23 changes: 11 additions & 12 deletions test/src/api/commands/element/testClickAndHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('.clickAndHold()', function() {

return Promise.resolve({
status: 0,
value: null
value:null
});
};
}

this.client.api.clickAndHold('#weblogin', function callback(result) {
assert.ok(clickAndHoldArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(clickAndHoldArgs.args, ['5cc459b8-36a8-3042-8b4a-258883ea642b'])
assert.strictEqual(result.status, 0);
assert.strictEqual(this, api);
});
Expand All @@ -39,16 +39,16 @@ describe('.clickAndHold()', function() {
clickAndHoldArgs = args;

return Promise.resolve({
status: 0,
status:0,
value: null
});
};
})
}

this.client.api.useXpath()
.clickAndHold('//weblogin', function callback(result) {
assert.ok(clickAndHoldArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(clickAndHoldArgs.args, ['5cc459b8-36a8-3042-8b4a-258883ea642b'])
assert.strictEqual(result.status, 0);
});
})


this.client.start(done);
Expand All @@ -60,22 +60,21 @@ describe('.clickAndHold()', function() {
let clickAndHoldArgs;
this.client.transport.Actions.session.pressAndHold = function(args) {
clickAndHoldArgs = args;

return Promise.resolve({
status: -1,
value: null,
error: new Error('Element could not be scrolled into view')
});
};
}

this.client.api.clickAndHold({
retryInterval: 50,
timeout: 100,
selector: '#weblogin'
}, function(result) {
assert.ok(clickAndHoldArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(clickAndHoldArgs.args,['5cc459b8-36a8-3042-8b4a-258883ea642b'])
assert.strictEqual(result.status, -1);
assert.strictEqual(result.value.error, 'An error occurred while running .clickAndHold() command on <#weblogin>: Element could not be scrolled into view');
assert.strictEqual(result.value.error,'An error occurred while running .clickAndHold() command on <#weblogin>: Element could not be scrolled into view')
});

this.client.start(done);
Expand Down
6 changes: 3 additions & 3 deletions test/src/api/commands/element/testDoubleClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('.doubleClick()', function() {

this.client.api.doubleClick('#weblogin', function callback(result) {
assert.strictEqual(result.status, 0);
assert.ok(doubleClickArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(doubleClickArgs.args, ['5cc459b8-36a8-3042-8b4a-258883ea642b']);
assert.strictEqual(this, api);
});

Expand All @@ -46,7 +46,7 @@ describe('.doubleClick()', function() {

this.client.api.useXpath()
.doubleClick('//weblogin', function callback(result) {
assert.ok(doubleClickArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(doubleClickArgs.args, ['5cc459b8-36a8-3042-8b4a-258883ea642b']);
assert.strictEqual(result.status, 0);
});
this.client.start(done);
Expand All @@ -70,7 +70,7 @@ describe('.doubleClick()', function() {
timeout: 100,
selector: '#weblogin'
}, function(result) {
assert.ok(doubleClickArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(doubleClickArgs.args, ['5cc459b8-36a8-3042-8b4a-258883ea642b']);
assert.strictEqual(result.status, -1);
assert.strictEqual(result.value.error, 'An error occurred while running .doubleClick() command on <#weblogin>: Element could not be scrolled into view');
});
Expand Down
6 changes: 2 additions & 4 deletions test/src/api/commands/element/testDragAndDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('moveToElement', function() {
};

this.client.api.dragAndDrop('css selector', '#weblogin', {x: 10, y: 10}, function(result) {
assert.deepEqual(dragArgs[0], '0');
assert.deepEqual(dragArgs[1], {x: 10, y: 10});
assert.deepStrictEqual(dragArgs, ['0', {x: 10, y: 10}]);
assert.strictEqual(result.status, 0);
});

Expand All @@ -40,8 +39,7 @@ describe('moveToElement', function() {
};

this.client.api.dragAndDrop('css selector', '#weblogin', '0', function(result) {
assert.deepEqual(dragArgs[0], '0');
assert.deepEqual(dragArgs[1], '0');
assert.deepStrictEqual(dragArgs, ['0', '0']);
assert.strictEqual(result.status, 0);
});

Expand Down
16 changes: 4 additions & 12 deletions test/src/api/commands/element/testMoveToElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,16 @@ describe('moveToElement', function() {
};

this.client.api.moveToElement('css selector', '#weblogin', null, null, function(result) {
assert.deepStrictEqual(moveToArgs[0], '0');
assert.deepStrictEqual(moveToArgs[1], null);
assert.deepStrictEqual(moveToArgs[2], null);
assert.deepStrictEqual(moveToArgs, ['0', null, null]);
assert.strictEqual(result.status, 0);
}).moveToElement('#weblogin', null, null, function(result) {
assert.deepStrictEqual(moveToArgs[0], '0');
assert.deepStrictEqual(moveToArgs[1], null);
assert.deepStrictEqual(moveToArgs[2], null);
assert.deepStrictEqual(moveToArgs, ['0', null, null]);
assert.strictEqual(result.status, 0);
}).moveTo('0', null, null, function(result) {
assert.deepStrictEqual(moveToArgs[0], '0');
assert.deepStrictEqual(moveToArgs[1], 0);
assert.deepStrictEqual(moveToArgs[2], 0);
assert.deepStrictEqual(moveToArgs, ['0', 0, 0]);
assert.strictEqual(result.status, 0);
}).moveToElement('#weblogin', 1, 1, function(result) {
assert.deepStrictEqual(moveToArgs[0], '0');
assert.deepStrictEqual(moveToArgs[1], 1);
assert.deepStrictEqual(moveToArgs[2], 1);
assert.deepStrictEqual(moveToArgs, ['0', 1, 1]);
assert.strictEqual(result.status, 0);
});

Expand Down
25 changes: 12 additions & 13 deletions test/src/api/commands/element/testRightClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ describe('.rightClick()', function() {
rightClickArgs = args;

return Promise.resolve({
status: 0,
status:0,
value: null
});
};
})
}

this.client.api.rightClick('#weblogin', function callback(result) {
assert.ok(rightClickArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(rightClickArgs.args,['5cc459b8-36a8-3042-8b4a-258883ea642b'])
assert.strictEqual(result.status, 0);
assert.strictEqual(this, api);
});
Expand All @@ -39,16 +39,16 @@ describe('.rightClick()', function() {
rightClickArgs = args;

return Promise.resolve({
status: 0,
status:0,
value: null
});
};
})
}

this.client.api.useXpath()
.rightClick('//weblogin', function callback(result) {
assert.ok(rightClickArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(rightClickArgs.args, ['5cc459b8-36a8-3042-8b4a-258883ea642b'])
assert.strictEqual(result.status, 0);
});
})

this.client.start(done);
});
Expand All @@ -57,22 +57,21 @@ describe('.rightClick()', function() {
let rightClickArgs;
this.client.transport.Actions.session.contextClick = function(args) {
rightClickArgs = args;

return Promise.resolve({
status: -1,
value: null,
error: new Error('Element could not be scrolled into view')
});
};
}

this.client.api.rightClick({
retryInterval: 50,
timeout: 100,
selector: '#weblogin'
}, function(result) {
assert.ok(rightClickArgs.args.includes('5cc459b8-36a8-3042-8b4a-258883ea642b'));
assert.deepStrictEqual(rightClickArgs.args,['5cc459b8-36a8-3042-8b4a-258883ea642b'])
assert.strictEqual(result.status, -1);
assert.strictEqual(result.value.error, 'An error occurred while running .rightClick() command on <#weblogin>: Element could not be scrolled into view');
assert.strictEqual(result.value.error,'An error occurred while running .rightClick() command on <#weblogin>: Element could not be scrolled into view')
});

this.client.start(done);
Expand Down

0 comments on commit d6cbeec

Please sign in to comment.