Skip to content

Commit

Permalink
Case insensitive selectors for radioButton, textBox and checkbox getg…
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielpeixinho committed Mar 20, 2020
1 parent 8edf61f commit 0366193
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 210 deletions.
5 changes: 5 additions & 0 deletions lib/elementSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ async function containsTextNode(textToTranslate, translateTo, xpathText, selectH
);
}

function typeEqual(type) {
return `translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='${type}'`;
}

async function matchValueOrType(
tagName,
textToTranslate,
Expand Down Expand Up @@ -306,4 +310,5 @@ module.exports = {
isSelector,
isElement,
getIfExists,
typeEqual,
};
48 changes: 31 additions & 17 deletions lib/taiko.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ const runtimeHandler = require('./handlers/runtimeHandler');
const browserHandler = require('./handlers/browserHandler');
const emulationHandler = require('./handlers/emulationHandler');
const { logEvent } = require('./logger');
const { match, $$, $$xpath, findElements, findFirstElement } = require('./elementSearch');
const {
match,
$$,
$$xpath,
findElements,
findFirstElement,
typeEqual,
} = require('./elementSearch');
const { handleRelativeSearch, RelativeSearchElement } = require('./proximityElementSearch');
const Element = require('./elements/element');
const { BrowserContext } = require('./browserContext');
Expand Down Expand Up @@ -2359,7 +2366,11 @@ function textBox(attrValuePairs, ...args) {
const { selector } = prepareParameters(attrValuePairs, ...args);
let get;
const inputTypesExps = [
'input[@type="text" or @type="password" or @type="search" or @type="number" or @type="email" or @type="tel" or @type="url"]',
`input[${typeEqual('text')} or ${typeEqual('password')} or ${typeEqual(
'search',
)} or ${typeEqual('number')} or ${typeEqual('email')} or ${typeEqual('tel')} or ${typeEqual(
'url',
)}]`,
'input[not(@type)]',
];
if (!selector.attrValuePairs && !selector.label) {
Expand Down Expand Up @@ -2479,16 +2490,16 @@ module.exports.checkBox = (attrValuePairs, _options, ...args) => {
selector,
async () =>
await $$xpath(
`//input[@type='checkbox'][@id=(//label[contains(string(), ${xpath(
selector.label,
)})]/@for)] | //label[contains(string(), ${xpath(
`//input[${typeEqual('checkbox')}][@id=(//label[contains(string(), ${xpath(
selector.label,
)})]/input[@type='checkbox'] | //input[@type='checkbox'][following-sibling::text()[position() = 1 and contains(., ${xpath(
selector.label,
)})]]`,
)})]/@for)] | //label[contains(string(), ${xpath(selector.label)})]/input[${typeEqual(
'checkbox',
)}] | //input[${typeEqual(
'checkbox',
)}][following-sibling::text()[position() = 1 and contains(., ${xpath(selector.label)})]]`,
options.selectHiddenElement,
),
'//input[@type="checkbox"]',
`//input[${typeEqual('checkbox')}]`,
options.selectHiddenElement,
);

Expand All @@ -2515,20 +2526,23 @@ module.exports.checkBox = (attrValuePairs, _options, ...args) => {
module.exports.radioButton = (attrValuePairs, _options, ...args) => {
validate();
const { selector, options } = prepareParameters(attrValuePairs, _options, ...args);

const get = getElementGetter(
selector,
async () =>
await $$xpath(
`//input[@type='radio'][@id=(//label[contains(string(), ${xpath(
selector.label,
)})]/@for)] | //label[contains(string(), ${xpath(
selector.label,
)})]/input[@type='radio'] | //input[@type='radio'][following-sibling::text()[position() = 1 and contains(., ${xpath(
selector.label,
)})]]`,
`//input
[${typeEqual('radio')}]
[@id=( //label[contains(string(), ${xpath(selector.label)})]/@for)]
| //label[contains(string(), ${xpath(selector.label)})]/input[${typeEqual(
'radio',
)}]
| //input[${typeEqual('radio')}]
[following-sibling::text()[position() = 1
and contains(., ${xpath(selector.label)})]]`,
options.selectHiddenElement,
),
'//input[@type="radio"]',
`//input[${typeEqual('radio')}]`,
options.selectHiddenElement,
);

Expand Down
Loading

0 comments on commit 0366193

Please sign in to comment.