Skip to content

Commit

Permalink
Fixes #4017 – Add appium reset command
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester authored Feb 16, 2024
1 parent 40be23a commit fb4b0f2
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 97 deletions.
29 changes: 29 additions & 0 deletions lib/api/protocol/appium/resetApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const ProtocolAction = require('../_base-action.js');

/**
* Reset the app during the test.
*
* More info here: https://appium.io/docs/en/2.3/commands/base-driver/#reset
*
* @example
* module.exports = {
* 'reset the app': function (app) {
* app
* .appium.resetApp();
* },
* };
*
* @syntax .appium.resetApp([callback])
* @method resetApp
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api protocol.appium
*/
module.exports = class Session extends ProtocolAction {
static get isTraceable() {
return true;
}

command(callback) {
return this.transportActions.resetApp(callback);
}
};
27 changes: 17 additions & 10 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = class MethodMappings {

Object.assign(returnValue.value, {
get getId() {
return function() {
return function () {
return elementId;
};
}
Expand Down Expand Up @@ -504,7 +504,7 @@ module.exports = class MethodMappings {
const element = this.getWebElement(webElement);

// eslint-disable-next-line
/* istanbul ignore next */const fn = function(e,a,v){try{if(e&&typeof e.setAttribute=='function'){e.setAttribute(a,v);}return true;}catch(err){return{error:err.message,message:err.name+': '+err.message};}};
/* istanbul ignore next */const fn = function (e, a, v) { try { if (e && typeof e.setAttribute == 'function') { e.setAttribute(a, v); } return true; } catch (err) { return { error: err.message, message: err.name + ': ' + err.message }; } };
const elementId = await element.getId();

const result = await this.driver.executeScript('var passedArgs = Array.prototype.slice.call(arguments,0); ' +
Expand Down Expand Up @@ -619,7 +619,7 @@ module.exports = class MethodMappings {

async sendKeysToElement(webElementOrId, value) {
if (Array.isArray(value)) {
if (value.includes(undefined) || value.includes(null)){
if (value.includes(undefined) || value.includes(null)) {
throw TypeError('each key must be a number or string; got ' + value);
}
value = value.join('');
Expand Down Expand Up @@ -676,7 +676,7 @@ module.exports = class MethodMappings {
},

async getFirstElementChild(webElementOrId) {
return await this.getElementByJs(function(element) {
return await this.getElementByJs(function (element) {
return element && element.firstElementChild;
}, webElementOrId);
},
Expand All @@ -685,26 +685,26 @@ module.exports = class MethodMappings {
* @param {WebElement} webElement
*/
inspectInDevTools(webElement, content = 'Element') {
return this.driver.executeScript(function(element, content) {
return this.driver.executeScript(function (element, content) {
// eslint-disable-next-line no-console
console.log(content + ':', element);
}, webElement, content);
},

async getLastElementChild(webElementOrId) {
return await this.getElementByJs(function(element) {
return await this.getElementByJs(function (element) {
return element && element.lastElementChild;
}, webElementOrId);
},

async getNextSibling(webElementOrId) {
return await this.getElementByJs(function(element) {
return await this.getElementByJs(function (element) {
return element && element.nextElementSibling;
}, webElementOrId);
},

async getPreviousSibling(webElementOrId) {
return await this.getElementByJs(function(element) {
return await this.getElementByJs(function (element) {
return element && element.previousElementSibling;
}, webElementOrId);
},
Expand All @@ -717,7 +717,7 @@ module.exports = class MethodMappings {
},

async elementHasDescendants(webElementOrId) {
const count = await this.runScriptForElement(function(element) {
const count = await this.runScriptForElement(function (element) {
return element ? element.childElementCount : null;
}, webElementOrId);

Expand Down Expand Up @@ -870,7 +870,7 @@ module.exports = class MethodMappings {
},

async dragElement(source, destination) {
source = this.getWebElement(source);
source = this.getWebElement(source);

//destination could be webElementId or {x,y} offset
if (typeof destination === 'string') {
Expand Down Expand Up @@ -1032,6 +1032,13 @@ module.exports = class MethodMappings {
return '/appium/device/is_keyboard_shown';
},

resetApp() {
return {
method: 'POST',
path: '/appium/app/reset'
};
},

///////////////////////////////////////////////////////////////////////////
// Selenium Webdriver
///////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 3 additions & 2 deletions test/apidemos/appium/appiumTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ describe('appium api demo', function () {
'isKeyboardShown',
'getContexts',
'getContext',
'setContext'
'setContext',
'resetApp'
];

it('test appium available API commands', async function () {
Expand All @@ -29,7 +30,7 @@ describe('appium api demo', function () {
});
});

it('Search for Nightwatch', async function() {
it('Search for Nightwatch', async function () {
app // available globally
.waitForElementPresent({selector: 'Search Wikipedia', locateStrategy: 'accessibility id'})
.click('accessibility id', 'Search Wikipedia')
Expand Down
18 changes: 18 additions & 0 deletions test/src/api/protocol/testResetApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const assert = require('assert');
const Globals = require('../../../lib/globals.js');

describe('App reset command', function () {
before(function () {
Globals.protocolBefore();
});

it('testResetApp', function () {
return Globals.protocolTest({
assertion: function (opts) {
assert.strictEqual(opts.path, '/session/1352110219202/appium/app/reset');
},
commandName: 'appium.resetApp',
args: []
});
});
});
Loading

0 comments on commit fb4b0f2

Please sign in to comment.