Skip to content

Commit

Permalink
Modify the implementation of location commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Dec 5, 2022
1 parent dae559d commit d5929a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
13 changes: 10 additions & 3 deletions lib/api/client-commands/setGeolocation.js
Expand Up @@ -4,6 +4,10 @@ const {Logger} = require('../../utils');
/**
* Mock the geolocation of the browser. Call without any arguments to reset the geolocation back to original.
*
* This command also supports mocking the geolocation of mobile devices (when automated using Appium), with a few caveats:
* - It accepts `{latitude: number, longitude: number, altitude: number}` as the first argument with `altitude` as optional.
* - Calling the command without any argument does not reset the geolocation of the mobile device.
*
* @example
* describe('mock geolocation', function() {
* it('sets the geolocation to Tokyo, Japan and then resets it', () => {
Expand All @@ -22,16 +26,19 @@ const {Logger} = require('../../utils');
* });
*
* @method setGeolocation
* @syntax .setGeolocation({latitude, longitude, accuracy}, [callback])
* @param {object} [coordinates] Latitude, longitude, and accuracy.
* @syntax .setGeolocation({latitude, longitude, accuracy|altitude}, [callback])
* @param {object} [coordinates] `latitude` and `longitude` are required; `accuracy` is optional for desktop browsers, and `altitude` is optional for mobile devices.
* @param {function} [callback] Callback function to be called when the command finishes.
* @api protocol.cdp
* @since 2.2.0
* @moreinfo nightwatchjs.org/guide/network-requests/mock-geolocation.html
*/
class SetGeolocation extends ClientCommand {

performAction(callback) {
// TODO: use better predicate to find out if Appium is being used.
if (this.api.browserName === null) {
return this.transportActions.setDeviceGeolocation(this.coordinates, callback);
}

if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('The command .setGeolocation() is only supported in Chrome and Edge drivers');
Expand Down
@@ -1,15 +1,15 @@
const ProtocolAction = require('./_base-action.js');

/**
* Get the current geo-location of the mobile device.
* Get the current geolocation of the mobile device. Getting the current geolocation for desktop browsers is not supported.
*
* This command is a part of old [JSON Wire Protocol](https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidlocation), and works with Appium v1 only.
*
* @syntax browser.getDeviceGeolocation([callback])
* @method getDeviceGeolocation
* @syntax .getGeolocation([callback])
* @method getGeolocation
* @param {function} [callback] Callback function which is called with the result value.
* @returns {object} The current geo-location: `{latitude: number, longitude: number, altitude: number}`.
* @see setDeviceGeolocation
* @returns {object} The current geolocation: `{latitude: number, longitude: number, altitude: number}`.
* @see setGeolocation
* @api protocol.mobile
*/
module.exports = class Session extends ProtocolAction {
Expand Down
19 changes: 0 additions & 19 deletions lib/api/protocol/setDeviceGeolocation.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/transport/selenium-webdriver/method-mappings.js
Expand Up @@ -948,7 +948,7 @@ module.exports = class MethodMappings {
return {
method: 'POST',
path: '/location',
data: location
data: {location}
};
},

Expand Down

0 comments on commit d5929a1

Please sign in to comment.