Skip to content

OI-1063 web.findElement / findElements - if element not found throws … #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/errors/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ERROR_CODES = {
STALE_ELEMENT_REFERENCE: 'STALE_ELEMENT_REFERENCE',
ELEMENT_NOT_VISIBLE: 'ELEMENT_NOT_VISIBLE',
ELEMENT_NOT_INTERACTABLE: 'ELEMENT_NOT_INTERACTABLE',
ELEMENT_INTERACTABLE: 'ELEMENT_INTERACTABLE',
LOCATOR_MATCHES_MULTIPLE_ELEMENTS: 'LOCATOR_MATCHES_MULTIPLE_ELEMENTS',
ELEMENT_STILL_EXISTS: 'ELEMENT_STILL_EXISTS',
BROWSER_JS_EXECUTE_ERROR: 'BROWSER_JS_EXECUTE_ERROR',
Expand Down
5 changes: 5 additions & 0 deletions src/ox_modules/module-mob.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ export default class MobileModule extends WebDriverModule {
this.helpers.assertContext = modUtils.assertContext;
this.helpers.contextList = modUtils.contextList;
this.helpers.getLogTypes = modUtils.getLogTypes;
this.helpers.assertUnableToFindElement = modUtils.assertUnableToFindElement;
this.helpers.assertNotVisible = modUtils.assertNotVisible;
this.helpers.throwNotInteractable = modUtils.throwNotInteractable;
this.helpers.throwInteractable = modUtils.throwInteractable;
this.helpers.verify = modUtils.verify;
}

async deleteSession() {
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/assertText.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = async function(locator, pattern, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

const el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

let text;
try {
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/assertValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = async function(locator, pattern, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

const el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

var text;
var actualError;
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

try {
await el.clearValue();
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

// if the element is outside the viewport - check interactability and try to scroll it into the view first
if (await this.isWebViewContext() && !(await el.isClickable())) {
Expand Down
2 changes: 2 additions & 0 deletions src/ox_modules/module-mob/commands/clickHidden.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = async function(locator, clickParent) {
await this.helpers.assertContext(this.helpers.contextList.hybrid, this.helpers.contextList.web);

var el = await this.helpers.getElement(locator);
this.helpers.assertUnableToFindElement(el, locator);

// NOTE: adding comments inside the passed function is not allowed!
/*global document*/
var ret = await this.driver.execute(function (domEl, clickParent) {
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/clickLong.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = async function(locator, duration, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

await el.touchAction([
'press',
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/clickMultipleTimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = async function(locator, taps, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

var actions = [];
for (var i = 0; i < taps; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/dragAndDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = async function(locator, xoffset, yoffset, timeout) {
await this.helpers.assertContext(this.helpers.contextList.android, this.helpers.contextList.ios);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

await el.touchAction([
'press',
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/getLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
return await el.getLocation();
};
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/getText.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, true, timeout);
this.helpers.assertUnableToFindElement(el, locator);
var text = await el.getText();
if (text) {
return text.trim().replace(/\s+/g, ' ');
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/getValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

try {
var text = await el.getValue();
Expand Down
8 changes: 7 additions & 1 deletion src/ox_modules/module-mob/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ export {default as type} from './type';
export {default as unlockPattern} from './unlockPattern';
export {default as waitForExist} from './waitForExist';
export {default as waitForVisible} from './waitForVisible';
export {default as waitForInteractable} from './waitForInteractable';
export {default as waitForNotVisible} from './waitForNotVisible';
export {default as waitForInteractable} from './waitForInteractable';
export {default as waitForNotInteractable} from './waitForNotInteractable';
export {default as verifyAlert} from './verifyAlert';
export {default as verifyText} from './verifyText';
export {default as verifyTitle} from './verifyTitle';
export {default as verifyValue} from './verifyValue';
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/isCheckable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ module.exports = async function(locator, timeout) {
await this.helpers.assertContext(this.helpers.contextList.android);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
return await el.getAttribute('checkable') == 'true';
};
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/isChecked.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ module.exports = async function(locator, timeout) {
await this.helpers.assertContext(this.helpers.contextList.android);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
return await el.getAttribute('checked') == 'true';
};
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/isClickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ module.exports = async function(locator, timeout) {
await this.helpers.assertContext(this.helpers.contextList.android);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
return await el.getAttribute('clickable') == 'true';
};
4 changes: 2 additions & 2 deletions src/ox_modules/module-mob/commands/isExist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

try {
await this.helpers.getElement(locator, false, timeout);
return true;
const el = await this.helpers.getElement(locator, false, timeout);
return !!el;
} catch (e) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/isSelected.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ module.exports = async function(locator, timeout) {
await this.helpers.assertContext(this.helpers.contextList.android, this.helpers.contextList.hybrid, this.helpers.contextList.web);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
return await el.getAttribute('selected') == 'true';
};
4 changes: 2 additions & 2 deletions src/ox_modules/module-mob/commands/isVisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

try {
await this.helpers.getElement(locator, true, timeout);
return true;
const el = await this.helpers.getElement(locator, true, timeout);
return !!el;
} catch (e) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ox_modules/module-mob/commands/scrollIntoElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = async function(scrollElmLocator, findElmLocator, xoffset = 0, y
await this.helpers.assertContext(this.helpers.contextList.android, this.helpers.contextList.ios);

var scrollElm = await this.helpers.getElement(scrollElmLocator, false, timeout);
this.helpers.assertUnableToFindElement(el, scrollElmLocator);

var retry = 0;

Expand All @@ -42,6 +43,7 @@ module.exports = async function(scrollElmLocator, findElmLocator, xoffset = 0, y
var err = false;
try {
var el = await this.helpers.getElement(findElmLocator, true, 1000);
this.helpers.assertUnableToFindElement(el, findElmLocator);
} catch (e) {
err = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/scrollIntoView.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ module.exports = async function(locator, options = true, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');
await this.helpers.assertContext(this.helpers.contextList.hybrid, this.helpers.contextList.web);
var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
await el.scrollIntoView(options);
};
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async function(selectLocator, optionLocator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(selectLocator, false, timeout);
this.helpers.assertUnableToFindElement(el, selectLocator);

try {
if (optionLocator.indexOf('value=') === 0) {
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/selectFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = async function(frameLocator) {
for (var i = 0; i < arguments.length; i++) {
var locator = arguments[i];
var el = await this.helpers.getElement(locator);
this.helpers.assertUnableToFindElement(el, locator);
await this.driver.switchToFrame(el);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async function(locator, xoffset = 0, yoffset = 30, timeout, dur
await this.helpers.assertContext(this.helpers.contextList.android, this.helpers.contextList.ios);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

const location = await el.getLocation();

Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/swipeElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async function(locator, xoffset = 0, yoffset = 30, timeout, dur
await this.helpers.assertContext(this.helpers.contextList.android, this.helpers.contextList.ios);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

const location = await el.getLocation();

Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = async function(locator, value, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');

var el = await this.helpers.getElement(locator, true, timeout);
this.helpers.assertUnableToFindElement(el, locator);

try {

Expand Down
1 change: 1 addition & 0 deletions src/ox_modules/module-mob/commands/unlockPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = async function(locator, cols, rows, pattern, timeout) {
await this.helpers.assertContext(this.helpers.contextList.android);

var el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

var loc = await el.getLocation();
var locX = loc.x;
Expand Down
26 changes: 26 additions & 0 deletions src/ox_modules/module-mob/commands/verifyAlert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2015-present CloudBeat Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

/**
* @summary Verify whether alert matches the specified pattern and dismisses it.
* @description Text pattern can be any of the supported
* string matching patterns(on the top of page).
* @function verifyAlert
* @for web
* @param {String} pattern - Text pattern.
* @param {Number=} timeout - Timeout in milliseconds. Default is 60 seconds.
* @example <caption>[javascript] Usage example</caption>
* mob.init(caps);//Starts a mobile session and opens app from desired capabilities
* mob.click("id=Submit");// Clicks an element and opens an alert.
* mob.verifyAlert("Your Alert's text");// Verify the alert's text.
*/

module.exports = async function(...args) {
return await this.helpers.verify(this.assertAlert, this, ...args);
};
27 changes: 27 additions & 0 deletions src/ox_modules/module-mob/commands/verifyText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2015-present CloudBeat Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

/**
* @summary Verify element's inner text.
* @description Text pattern can be any of the supported
* string matching patterns (on the top of page).
* If the element is not interactable, then it will allways return empty string as its text.
* @function verifyText
* @param {String|Element} locator - Element locator.
* @param {String} pattern - Assertion text or pattern.
* @param {Number=} timeout - Timeout in milliseconds. Default is 60 seconds.
* @for android, ios, hybrid, web
* @example <caption>[javascript] Usage example</caption>
* mob.init(caps);//Starts a mobile session and opens app from desired capabilities
* mob.verifyText("id=UserName","John Doe");// Verify if an element’s text is as expected.
*/

module.exports = async function(...args) {
return await this.helpers.verify(this.assertText, this, ...args);
};
24 changes: 24 additions & 0 deletions src/ox_modules/module-mob/commands/verifyTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2015-present CloudBeat Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/**
* @summary Verify the page title.
* @description Assertion pattern can be any of the supported
* string matching patterns(on the top of page).
* @function verifyTitle
* @param {String} pattern - Assertion text or pattern.
* @param {Number=} timeout - Timeout in milliseconds. Default is 60 seconds.
* @for hybrid, web
* @example <caption>[javascript] Usage example</caption>
* mob.init(caps);//Starts a mobile session and opens app from desired capabilities
* mob.verifyTitle("Your websites title!");// Verify if the title of the page.
*/

module.exports = async function(...args) {
return await this.helpers.verify(this.assertTitle, this, ...args);
};
23 changes: 23 additions & 0 deletions src/ox_modules/module-mob/commands/verifyValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2015-present CloudBeat Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/**
* @summary Verify element's value.
* @function verifyValue
* @param {String|Element} locator - Element locator.
* @param {String} pattern - Value pattern.
* @param {Number=} timeout - Timeout in milliseconds. Default is 60 seconds.
* @for android, ios, hybrid, web
* @example <caption>[javascript] Usage example</caption>
* mob.init(caps);//Starts a mobile session and opens app from desired capabilities
* mob.verifyValue("id=UserName", "John Doe");// Verify if the value of an element.
*/

module.exports = async function(...args) {
return await this.helpers.verify(this.assertValue, this, ...args);
};
3 changes: 2 additions & 1 deletion src/ox_modules/module-mob/commands/waitForExist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
*/
module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');
await this.helpers.getElement(locator, false, timeout);
const el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);
};
4 changes: 3 additions & 1 deletion src/ox_modules/module-mob/commands/waitForInteractable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');
const el = await this.helpers.getElement(locator, false, timeout);
this.helpers.assertUnableToFindElement(el, locator);

try {
await this.driver.waitUntil(async() => {
Expand All @@ -31,6 +32,7 @@ module.exports = async function(locator, timeout) {
},
{ timeout: (timeout ? timeout : this.waitForTimeout) });
} catch (e) {
throw new this.OxError(this.errHelper.errorCode.ELEMENT_NOT_INTERACTABLE, `Element ${locator} is not interactable`);
await this.helpers.restoreTimeoutImplicit();
this.helpers.throwNotInteractable(locator);
}
};
Loading