Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
commands.getContentSize = async function getContentSize (el) {
if (this.isWebContext()) {
throw new errors.NotYetImplementedError('Support for getContentSize for web context is not yet implemented. Please contact an Appium dev');
}
const type = await this.getAttribute('type', el);
if (type !== 'XCUIElementTypeTable' &&
type !== 'XCUIElementTypeCollectionView') {
throw new Error(`Can't get content size for type '${type}', only for ` +
`tables and collection views`);
}
let locator = '*';
if (type === 'XCUIElementTypeTable') {
// only find table cells, not just any children
locator = 'XCUIElementTypeCell';
}
let contentHeight = 0;
commands.endCoverage = async function endCoverage () { // eslint-disable-line require-await
throw new errors.NotYetImplementedError();
};
helpers.mobileScroll = async function mobileScroll (opts = {}) {
let direction = opts.direction;
let el = opts.element;
el = unwrapEl(el);
if (this.isWebContext()) {
// not implemented yet in web
throw new errors.NotYetImplementedError();
} else {
if (util.hasValue(el) && !util.hasValue(direction)) {
await this.scrollToElement(el);
return;
}
direction = _.capitalize(direction);
let command;
if (_.isNull(el) || _.isUndefined(el)) {
// By default, scroll the first scrollview.
command = `au.scrollFirstView('${direction}')`;
} else {
// if element is defined, call scrollLeft, scrollRight, scrollUp, and scrollDown on the element.
command = `au.getElement('${el}').scroll${direction}()`;
}
try {
await this.uiAutoClient.sendCommand(command);
commands.performMultiAction = async function performMultiAction (actions, /*el*/) {
if (this.isWebContext()) {
throw new errors.NotYetImplementedError();
}
// el = unwrapEl(el);
// TODO: why elementId is not used
let states = [];
let cycleThroughActions = async () => {
let action = actions.shift();
if (typeof action === 'undefined') {
let mergedStates = mergeStates(states);
if (this.isPinchAndZoom(mergedStates)) {
await this.handlePinchAndZoom(mergedStates);
return;
} else {
await this.uiAutoClient.sendCommand (`target.touch(${JSON.stringify(mergedStates)})`);
return;
helpers.clickCoords = async function clickCoords (coords) {
if (this.useRobot) {
// var tapUrl = this.args.robotUrl + "/tap";
// request.post({url:tapUrl, form: {x:coords.x, y:coords.y}}, cb);
/*TODO*/throw new errors.NotYetImplementedError();
} else {
let opts = coords;
opts.tapCount = 1;
opts.duration = 0.3;
opts.touchCount = 1;
let command = `au.complexTap(${JSON.stringify(opts)})`;
await this.uiAutoClient.sendCommand(command);
}
};
if (this.isWebContext()) {
let atomsElement = this.useAtomsElement(el);
await this.executeAtom('click', [atomsElement]);
await this.executeAtom('type', [atomsElement, value]);
} else {
if (value instanceof Array) {
value = value.join('');
}
if (typeof value !== 'string') {
value = value.toString();
}
value = util.escapeSpecialChars(value, "'");
// de-escape \n so it can be used specially
value = value.replace(/\\\\n/g, '\\n');
if (this.opts.useRobot) {
/* TODO */throw new errors.NotYetImplementedError();
} else {
let command = `au.getElement('${el}').setValueByType('${value}')`;
await this.uiAutoClient.sendCommand(command);
}
}
};
commands.getWindowSize = async function getWindowSize (windowHandle = 'current') {
if (windowHandle !== 'current') {
throw new errors.NotYetImplementedError('Currently only getting current window size is supported.');
}
if (!this.isWebContext()) {
return await this.getWindowSizeNative();
} else {
return await this.getWindowSizeWeb();
}
};
commands.performTouch = async function performTouch (gestures) {
if (this.isWebContext()) {
throw new errors.NotYetImplementedError();
}
if (gestures.length === 1 && gestures[0].action === 'tap') {
return await this.handleTap(gestures[0]);
} else if (this.isDrag(gestures)) {
return await this.handleDrag(gestures);
}
let touchStateObjects = await this.parseTouch(gestures);
await this.uiAutoClient.sendCommand(`target.touch(${JSON.stringify(touchStateObjects)})`);
};
commands.pullFolder = async function pullFolder (remotePath) {
logger.debug(`Pulling '${remotePath}' from sim`);
if (this.isRealDevice()) {
throw new errors.NotYetImplementedError();
}
let fullPath = await this.getSimFileFullPath(remotePath);
logger.debug(`Adding ${fullPath} to an in-memory zip archive`);
let buffer = await zip.toInMemoryZip(fullPath);
logger.debug('Converting in-memory zip file to base64 encoded string');
let data = buffer.toString('base64');
logger.debug('Returning in-memory zip file as base54 encoded string');
return data;
};
commands.pullFile = async function pullFile (remotePath) {
logger.debug(`Pulling ${remotePath} from sim`);
if (this.isRealDevice()) {
throw new errors.NotYetImplementedError();
}
let fullPath = await this.getSimFileFullPath(remotePath);
logger.debug(`Attempting to read ${fullPath}`);
let data = await fs.readFile(fullPath, {encoding: 'base64'});
return data;
};