Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appium-uiauto

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appium-uiauto - npm Package Compare versions

Comparing version 1.4.4 to 1.5.0

uiauto/lib/status.js

2

package.json
{
"name": "appium-uiauto",
"version": "1.4.4",
"version": "1.5.0",
"description": "appium uiauto ios driver",

@@ -5,0 +5,0 @@ "main": "lib/main.js",

@@ -6,3 +6,3 @@ /* globals env, alerts, commands */

#import "lib/env.js"
#import "lib/errors.js"
#import "lib/status.js"
#import "lib/mechanic-ext/index.js"

@@ -9,0 +9,0 @@ #import "lib/element-patch/index.js"

@@ -13,3 +13,3 @@ // The message route is the following:

/* globals $, errors, env */
/* globals $, STATUS, env */

@@ -62,2 +62,3 @@ var commands;

var stringResult = JSON.stringify(result);
$.debug('responding with:' + stringResult.substring(300));
if (stringResult.length < BIG_DATA_THRESHOLD){

@@ -103,2 +104,69 @@ // regular small results

function buildOkResult(rawRes) {
// Type return mapping is the following:
// - UIAElement (excluding UIAElementArray and UIAElementNil)
// --> return a single element id
// - UIAElementNil, null, undefined --> ''
// - UIAElementArray, mechanic wrap, Elements Arrays
// --> return array of element ids
// - else --> return result as it is
// converting UIAElementArray to mechanic wrap
if (rawRes instanceof UIAElementArray){
rawRes = $.smartWrap(rawRes);
}
// converting array of UIAElement to mechanic wrap
if (Array.isArray(rawRes) && rawRes.length > 0){
try {
rawRes = $.smartWrap(rawRes);
} catch (ign) {
// not an array of elements, ignoring
}
}
// build result object
if (rawRes === UIAElementNil || rawRes instanceof UIAElementNil ||
rawRes === null || rawRes === undefined) {
return {
status: STATUS.Success.code,
value: ''
};
} else if (rawRes instanceof UIAElement) {
var elid = $.getId(rawRes);
return {
status: STATUS.Success.code,
value: {'ELEMENT': elid }
};
} else if (rawRes.isMechanic === true) {
var elIds = [];
$(rawRes).each(function (idx, el) {
var elid = $.getId(el);
elIds.push({'ELEMENT': elid });
});
return {
status: STATUS.Success.code,
value: elIds
};
} else {
return {
status: STATUS.Success.code,
value: rawRes
};
}
}
function buildErrorResult (err) {
$.error('Error during eval: ' + err.stack);
if (err.isAppium) {
return {
status: err.code,
value: err.message
};
} else {
return {
status: STATUS.JavaScriptError.code
, value: err.message
};
}
}
commands.startProcessing = function () {

@@ -112,47 +180,19 @@ // let server know we're alive and get first command

$.debug("Got new command " + curAppiumCmdId + " from instruments: " + cmd);
try {
if (cmd === MORE_COMMAND) {
result = {
status: errors.Success.code,
type: 'chunk',
};
} else {
/* jshint evil:true */
try {
$.debug('evaluating ' + cmd);
try {
result = eval(cmd);
} catch (err) {
$.error('Error during eval: ' + err.stack);
throw err;
}
$.debug('evaluation finished');
} catch (possStaleEl) {
if (possStaleEl.message === errors.StaleElementReference.code) {
result = {
status: errors.StaleElementReference.code,
value: errors.StaleElementReference.summary
};
} else {
throw possStaleEl;
}
}
}
} catch (e) {
if (cmd === MORE_COMMAND) {
result = {
status: errors.JavaScriptError.code
, value: e.message
status: STATUS.Success.code,
type: 'chunk',
};
} else {
/* jshint evil:true */
try {
$.debug('evaluating ' + cmd);
var rawRes = eval(cmd);
$.debug('evaluation finished');
result = buildOkResult(rawRes);
} catch (err) {
$.error(err.toString());
result = buildErrorResult(err);
}
}
if (typeof result === "undefined" || result === null) {
result = '';
$.debug("Command executed without response");
}
if (typeof result.status === "undefined" || typeof result.status === "object") {
$.debug("Result is not protocol compliant, wrapping");
result = {
status: errors.Success.code,
value: result
};
}
cmd = sendResultAndGetNext(result);

@@ -159,0 +199,0 @@ } else {

@@ -1,3 +0,1 @@

/* globals errors */
(function () {

@@ -19,6 +17,2 @@

this.flickInsideWithOptions(options);
return {
status: errors.Success.code,
value: null
};
};

@@ -64,6 +58,2 @@

this.dragInsideWithOptions(options);
return {
status: errors.Success.code,
value: null
};
};

@@ -76,6 +66,2 @@

this.flickInsideWithOptions(options);
return {
status: errors.Success.code,
value: null
};
};

@@ -82,0 +68,0 @@

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, STATUS */

@@ -104,30 +104,17 @@ (function () {

UIAElement.prototype.getElementLocation = function () {
return {
status: errors.Success.code,
value: this.rect().origin
};
return this.rect().origin;
};
UIAElement.prototype.getElementSize = function () {
return {
status: errors.Success.code,
value: this.rect().size
};
return this.rect().size;
};
UIAElement.prototype.isDisplayed = function () {
return {
status: errors.Success.code,
value: this.isVisible() === 1
};
return this.isVisible() === 1;
};
UIAElement.prototype.isSelected = function () {
return {
status: errors.Success.code,
value: this.value() === 1
};
return this.value() === 1;
};
})();

@@ -14,3 +14,3 @@ /* globals $ */

weighting, true);
return $._returnFirstElem($(elems));
return $.smartWrap(elems).dedup()[0];
};

@@ -22,3 +22,3 @@

predicate, weighting, true, onlyVisible);
return $._returnFirstElem($(elems));
return $.smartWrap(elems).dedup()[0];
};

@@ -29,3 +29,3 @@

var elems = this._elementOrElementsWithPredicateWeighted(predicate, weighting, false, onlyVisible);
return $._returnElems($(elems));
return $.smartWrap(elems).dedup();
};

@@ -32,0 +32,0 @@

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, ERROR */

@@ -10,21 +10,15 @@ (function () {

if (alert.isNil()) {
return {
status: errors.NoAlertOpenError.code,
value: null
};
throw new ERROR.NoAlertOpenError();
}
var textRes = this.getElementsByType('text', alert);
var texts = this.getElementsByType('text', alert);
// If an alert does not have a title, alert.name() is null, use empty string
var text = alert.name() || "";
if (textRes.value.length > 1) {
if (texts.length > 1) {
// Safari alerts have the URL as a title
if (text.indexOf('http') === 0 || text === "") {
textId = textRes.value[textRes.value.length - 1].ELEMENT;
text = this.getElement(textId).name();
text = texts.last().name();
} else {
var textId = textRes.value[textRes.value.length - 2].ELEMENT;
text = this.getElement(textId).name();
textId = textRes.value[textRes.value.length - 1].ELEMENT;
var subtext = this.getElement(textId).name();
text = texts[texts.length - 2].name();
var subtext = texts.last().name();
if (subtext !== null) {

@@ -35,6 +29,3 @@ text = text + ' ' + subtext;

}
return {
status: errors.Success.code,
value: text
};
return text;
}

@@ -44,15 +35,9 @@

var alert = $.mainApp().alert();
var boxRes = this.getElementByType('textfield', alert);
if (boxRes.status === errors.Success.code) {
var el = this.getElement(boxRes.value.ELEMENT);
var el = this.getElementByType('textfield', alert);
if (el) {
el.setValueByType(text);
return {
status: errors.Success.code,
value: true
};
} else {
throw new ERROR.ElementNotVisible(
"Tried to set text of an alert that wasn't a prompt");
}
return {
status: errors.ElementNotVisible.code,
value: "Tried to set text of an alert that wasn't a prompt"
};
}

@@ -69,9 +54,4 @@

}
acceptButton.tap();
this.waitForAlertToClose(alert);
return {
status: errors.Success.code,
value: null
};
} else {

@@ -81,11 +61,4 @@ var ios7AlertButtons = this._getElementsByXpath("actionsheet/button");

ios7AlertButtons[0].tap();
return {
status: errors.Success.code,
value: null
};
} else {
return {
status: errors.UnknownError.code,
value: null
};
throw new ERROR.UnknownError();
}

@@ -96,6 +69,3 @@ }

, alertIsPresent: function () {
return {
status: errors.Success.code,
value: !$.mainApp().alert().isNil()
};
return !$.mainApp().alert().isNil();
}

@@ -108,13 +78,5 @@

this.waitForAlertToClose(alert);
return {
status: errors.Success.code,
value: null
};
} else if (!alert.isNil() && alert.buttons().length > 0) {
alert.buttons()[0].tap(); // first button is dismiss
this.waitForAlertToClose(alert);
return {
status: errors.Success.code,
value: null
};
} else {

@@ -124,6 +86,2 @@ var ios7AlertButtons = this._getElementsByXpath("actionsheet/button");

ios7AlertButtons[ios7AlertButtons.length - 1].tap();
return {
status: errors.Success.code,
value: null
};
} else {

@@ -130,0 +88,0 @@ return this.acceptAlert();

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, ERROR */

@@ -22,12 +22,5 @@ (function () {

} catch (e) {
return {
status: errors.UnknownError.code,
value: "Back button is null and can't be tapped."
};
throw new ERROR.UnknownError("Back button is null and can't be tapped.");
}
}
return {
status: errors.Success.code,
value: null
};
}

@@ -34,0 +27,0 @@

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, ERROR */

@@ -9,6 +9,4 @@ (function () {

var element = this.getElement(elementId);
var errObj = {
status: errors.UnknownError.code,
value: 'elementId ' + elementId + ' could not be tapped'
};
var errObj = new ERROR.UnknownError(
'elementId ' + elementId + ' could not be tapped');
if (element !== null) {

@@ -23,17 +21,11 @@ try {

} catch (e2) {
return errObj;
throw errObj;
}
} else {
return errObj;
throw errObj;
}
}
return {
status: errors.Success.code,
value: null
};
} else {
return {
status: errors.UnknownError.code,
value: 'elementId ' + elementId + ' is null and can\'t be tapped.'
};
throw new ERROR.UnknownError(
'elementId ' + elementId + ' is null and can\'t be tapped.');
}

@@ -84,32 +76,16 @@ }

$.target().dragFromToForDuration(coords[0], coords[1], duration);
return {
status: errors.Success.code,
value: null
};
}
, scrollFirstView: function (direction) {
var viewRes = this.getElementByType('scrollview');
var doScroll = function (elId) {
var el = this.getElement(elId);
var doScroll = function (el) {
var method = 'scroll' + direction[0].toUpperCase() + direction.slice(1);
el[method]();
return {
status: errors.Success.code,
value: true
};
}.bind(this);
if (viewRes.status === errors.Success.code) {
return doScroll(viewRes.value.ELEMENT);
} else {
viewRes = this.getElementByType('tableview');
if (viewRes.status === errors.Success.code) {
return doScroll(viewRes.value.ELEMENT);
}
try {
var viewEl = this.getElementByType('scrollview');
return doScroll(viewEl);
} catch (err) {
viewEl = this.getElementByType('tableview');
return doScroll(viewEl);
}
return {
status: errors.NoSuchElement.code,
value: null
};
}

@@ -121,6 +97,2 @@

$.target().flickFromTo(coords[0], coords[1]);
return {
status: errors.Success.code,
value: null
};
}

@@ -133,6 +105,2 @@

$.target().pinchCloseFromToForDuration(coords[0], coords[1], duration);
return {
status: errors.Success.code,
value: null
};
}

@@ -145,6 +113,2 @@

$.target().pinchOpenFromToForDuration(coords[0], coords[1], duration);
return {
status: errors.Success.code,
value: null
};
}

@@ -204,6 +168,2 @@

$.target().flickFromTo(opts[0], opts[1]);
return {
status: errors.Success.code,
value: null
};
}

@@ -219,6 +179,2 @@

$.target().dragFromToForDuration(opts[0], opts[1], 1);
return {
status: errors.Success.code,
value: null
};
}

@@ -225,0 +181,0 @@

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, ERROR */

@@ -12,6 +12,2 @@ (function () {

}
return {
status: errors.Success.code,
value: null
};
}

@@ -33,6 +29,2 @@

}
return {
status: errors.Success.code,
value: null
};
}

@@ -72,6 +64,4 @@

} catch (e) {
return {
status: errors.NoSuchElement.code,
value: "Could not find the '" + keyName + "' key."
};
throw new ERROR.NoSuchElement(
"Could not find the '" + keyName + "' key.");
}

@@ -78,0 +68,0 @@ $.delay(1000);

@@ -1,2 +0,2 @@

/* globals errors, $ */
/* globals ERROR, $ */

@@ -39,7 +39,6 @@ (function () {

if (this.cache[name].isNil()) {
throw new Error(errors.StaleElementReference.code);
throw new Error.StaleElementReference();
}
return this.cache[name];
}
return null;

@@ -101,3 +100,3 @@ }

var exact = $.mainApp().getFirstWithPredicateWeighted(exactPred);
if (exact && exact.status === 0) {
if (exact) {
return exact;

@@ -115,35 +114,6 @@ } else {

, elemForAction: function (elem, idx) {
// mock out action functions to respond with the error
var errRet = function () { return elem; };
var noElemMock = {};
var actions = ["tap", "isEnabled", "isValid", "isVisible", "value",
"name", "label", "setValue"];
for (var i = 0; i < actions.length; i++) {
noElemMock[actions[i]] = errRet;
}
if (elem.status === errors.Success.code) {
if (typeof elem.value.ELEMENT === "undefined") {
// we have an array of elements
if (typeof elem.value[idx] === "undefined") {
return {
status: errors.NoSuchElement.code
, value: null
};
} else {
return this.getElement(elem.value[idx].ELEMENT);
}
} else {
return this.getElement(elem.value.ELEMENT);
}
} else {
return noElemMock;
}
}
, _getElementsByType: function (type, ctx) {
var selector = this.convertSelector(type);
var elems = this.lookup(selector, ctx);
return elems;
return $.smartWrap(elems);
}

@@ -153,4 +123,3 @@

var elems = this._getElementsByType(type, ctx);
return this._returnElems($(elems));
return $.smartWrap(elems).dedup();
}

@@ -160,4 +129,3 @@

var elems = this._getElementsByType(type, ctx);
return this._returnFirstElem($(elems));
return $.smartWrap(elems).dedup()[0];
}

@@ -171,7 +139,8 @@

var elems = this._getElementsByUIAutomation(selectorCode, ctx);
return this._returnFirstElem($(elems));
return $.smartWrap(elems).dedup()[0];
}
, getElementsByUIAutomation: function (selectorCode, ctx) {
var elems = this._getElementsByUIAutomation(selectorCode, ctx);
return this._returnElems($(elems));
elems = $.smartWrap(elems);
return elems.dedup();
}

@@ -195,13 +164,4 @@ , _getElementsByUIAutomation: function (selectorCode, ctx) {

var elems = eval("rootElement" + selectorCode);
if (elems instanceof UIAElementNil) {
return [];
} else if (elems instanceof UIAElementArray) {
//tricky: UIAutomation returns UIElementArray objects, not standard js array. Mechanic.js expects objects of type Array
return elems.toArray();
} else {
return [elems];
}
return $.smartWrap(elems);
}
});

@@ -230,6 +190,3 @@

if (elemFocused === true || elemFocused === 1) {
return {
status: errors.Success.code,
value: {ELEMENT: key}
};
return $.cache[key];
}

@@ -240,13 +197,6 @@ }

if (foundElement) {
var varName = $(foundElement).name();
return {
status: errors.Success.code,
value: {ELEMENT: varName}
};
return foundElement;
} else {
throw new ERROR.NoSuchElement();
}
return {
status: errors.NoSuchElement.code,
value: null,
};
}

@@ -253,0 +203,0 @@ });

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, ERROR */

@@ -26,11 +26,5 @@ (function () {

if (value !== null) {
return {
status: errors.Success.code,
value: value
};
return value;
} else {
return {
status: errors.UnknownError.code,
value: 'Unsupported Orientation: ' + orientation
};
throw new ERROR.UnknownError('Unsupported Orientation: ' + orientation);
}

@@ -45,6 +39,3 @@ }

} else {
return {
status: errors.UnknownError.code,
value: 'Unsupported orientation: ' + orientation
};
throw new ERROR.UnknownError('Unsupported orientation: ' + orientation);
}

@@ -55,3 +46,3 @@ var newOrientation;

while (!success && i < 20) {
newOrientation = this.getScreenOrientation().value;
newOrientation = this.getScreenOrientation();
success = newOrientation === orientation;

@@ -62,12 +53,6 @@ $.system().performTaskWithPathArgumentsTimeout("/bin/sleep", ['0.1'], 1);

if (success) {
return {
status: errors.Success.code
, value: newOrientation
};
return newOrientation;
} else {
return {
status: errors.UnknownError.code
, value: "Orientation change did not take effect: expected " +
orientation + " but got " + newOrientation
};
throw new ERROR.UnknownError("Orientation change did not take effect: expected " +
orientation + " but got " + newOrientation);
}

@@ -78,6 +63,3 @@ }

var size = $.target().rect().size;
return {
status: errors.Success.code
, value: size
};
return size;
}

@@ -84,0 +66,0 @@

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, STATUS */

@@ -17,40 +17,2 @@ (function () {

, _returnFirstElem: function (elems) {
var el;
$.each(elems, function (i, _el) {
if (!_el.isDuplicate()) {
el = _el;
return false;
}
});
if (el) {
var elid = this.getId(el);
return {
status: errors.Success.code,
value: {'ELEMENT': elid }
};
} else {
return {
status: errors.NoSuchElement.code,
value: errors.NoSuchElement.summary
};
}
}
, _returnElems: function (elems) {
var results = [];
elems.each(function (e, el) {
if (!el.isDuplicate()){
var elid = this.getId(el);
results.push({ELEMENT: elid});
}
}.bind(this));
return {
status: errors.Success.code,
value: results
};
}
, convertSelector: function (selector) {

@@ -116,13 +78,44 @@ // some legacy: be backwards compatible, mechanic.js

$.debug("WARNING: Waited for indicators to become non-visible but they never did, moving on");
return {
status: errors.UnknownError.code,
value: "Timed out waiting on activity indicator."
};
throw new STATUS.UnknownError("Timed out waiting on activity indicator.");
}
return {
status: errors.Success.code,
value: null
};
}
, smartWrap: function (obj) {
if (obj === null || typeof obj === 'undefined' ) {
return $([]);
} else if (obj.isMechanic === true) {
return obj;
} else if (obj === UIAElementNil || obj instanceof UIAElementNil) {
return $([]);
} else if (obj instanceof UIAElementArray) {
return $(obj.toArray());
} else if (obj instanceof UIAElement) {
return $(obj);
} else if (Array.isArray(obj)) {
var allUIA = true;
$.each(obj, function (idx, el) {
allUIA = allUIA && el instanceof UIAElement;
return allUIA;
});
if (allUIA) return $(obj);
} else {
throw new Error('smartWrap failed,');
}
}
});
$.extend($.fn, {
isMechanic: true,
dedup: function () {
var results = [];
this.each(function (idx, el) {
if (!el.isDuplicate()){
results.push(el);
}
});
return $.smartWrap(results);
}
});
})();

@@ -1,2 +0,2 @@

/* globals $, errors */
/* globals $, ERROR */

@@ -135,6 +135,3 @@ (function () {

if (xpObj === false) {
return {
status: errors.XPathLookupError.code
, value: null
};
throw new ERROR.XPathLookupError();
} else {

@@ -192,3 +189,4 @@ $.target().pushTimeout(0);

, getElementsByXpath: function (xpath, ctx) {
return this._returnElems(this._getElementsByXpath(xpath, ctx));
var elems = this._getElementsByXpath(xpath, ctx);
return $.smartWrap(elems).dedup();
}

@@ -200,21 +198,13 @@

if (results.value === null || results.value.length < 1) {
return {
status: errors.NoSuchElement.code,
value: null
};
if (results.length < 1) {
throw new ERROR.NoSuchElement();
} else {
var result = results.value[0];
for (var a = 0, len = results.value.length; a < len; a++) {
var elId = results.value[a].ELEMENT;
var elVis = this.getElement(elId).isVisible();
if (elVis === 1) {
result = results.value[a];
var result = results[0];
for (var a = 0, len = results.length; a < len; a++) {
if (results[a].isVisible()) {
result = results[a];
break;
}
}
return {
status: errors.Success.code,
value: result
};
return result;
}

@@ -245,13 +235,6 @@ }

if (err.message.indexOf("Could not find") !== -1) {
return {
status: many ?
errors.StaleElementReference.code :
errors.NoSuchElement.code,
value: err.message
};
throw many ? new ERROR.StaleElementReference(err.message) :
ERROR.NoSuchElement(err.message);
} else {
return {
status: errors.UnknownError.code,
value: err.message
};
throw ERROR.UnknownError(err.message);
}

@@ -265,3 +248,3 @@ }

var elem = this._getElementByIndexPath(path, ctx);
ret = this._returnFirstElem($([elem]));
ret = $(elem).dedup()[0];
} catch (err) {

@@ -290,3 +273,3 @@ ret = this._handleIndexPathError(err, false);

});
ret = this._returnElems($(elems));
ret = $.smartWrap(elems).dedup();
}

@@ -293,0 +276,0 @@ $.target().popTimeout();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc