Skip to content

Commit

Permalink
clickWithTest (#2)
Browse files Browse the repository at this point in the history
clickWithTest helper function
  • Loading branch information
mohithg authored Aug 20, 2018
1 parent f93eeb0 commit 3c8d24f
Show file tree
Hide file tree
Showing 7 changed files with 820 additions and 1,359 deletions.
30 changes: 27 additions & 3 deletions build/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.logConsoleOutput = exports.findElementFromGroupWithText = exports.waitForElementToGo = exports.setValue = exports.click = exports.wait = exports.waitForUrl = exports.load = undefined;
exports.logConsoleOutput = exports.findElementFromGroupWithText = exports.waitForElementToGo = exports.setValue = exports.clickWithText = exports.click = exports.wait = exports.waitForUrl = exports.load = undefined;

var _lodash = require('lodash');

Expand Down Expand Up @@ -66,6 +66,24 @@ var click = exports.click = function click(selector) {
$$(selector)[index].click();
};

/**
* @function clickWithText
* @desc finds the selector with text and clicks and if there are multiple elememts with the same text, it will click based on the index. Note that it waits until selector appears in the DOM.
* @param {string} selector - Selector for the element.
* @param {string} text - The text element.
* @param {number} [index = 0] - index number
*/
var clickWithText = exports.clickWithText = function clickWithText(selector, text) {
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;

var element = findElementFromGroupWithText(selector, text, index);
if (element) {
click(element, index);
} else {
new Error('No Element with text found');
}
};

/**
* @function setValue
* @desc Set Value in any selector
Expand Down Expand Up @@ -105,17 +123,22 @@ var waitForElementToGo = exports.waitForElementToGo = function waitForElementToG
* @desc Finds and returns the element that matches the text from the group of selectors
* @param {string} groupSelector - The groupSelector element.
* @param {string} textToSearch - Enter the text to search in elements
* @param {number} [index = 0] - index number
* @return {element} element - The element which matches the textToSearch from group of groupSelector or returns null if nothing is found
*/
var findElementFromGroupWithText = exports.findElementFromGroupWithText = function findElementFromGroupWithText(groupSelector, textToSearch) {
var findElementFromGroupWithText = exports.findElementFromGroupWithText = function findElementFromGroupWithText(groupSelector, textToSearch, index) {
wait(groupSelector);
var group = $$(groupSelector);
var elements = [];
for (var i = 0; i < group.length; i++) {
var element = group[i];
if (element.getText().includes(textToSearch)) {
return element;
elements = _lodash2.default.concat(elements, element);
}
}
if (!_lodash2.default.isEmpty(elements)) {
return elements[index];
}
return null;
};

Expand All @@ -139,6 +162,7 @@ var logConsoleOutput = exports.logConsoleOutput = function logConsoleOutput(type

var Helpers = {
click: click,
clickWithText: clickWithText,
findElementFromGroupWithText: findElementFromGroupWithText,
load: load,
logConsoleOutput: logConsoleOutput,
Expand Down
Loading

0 comments on commit 3c8d24f

Please sign in to comment.