-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate selectors to use css selector instead of xpath
* #1334 update image selector Signed-off-by: NivedhaSenthil <[email protected]> * #1334 make link use css selector Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update listitem to use css selector Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update button selector to use css selector Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update button selector to use css selector Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update button Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update selectors to use css - fileField - range - color - dropdown Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update radio button Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update checkbox Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update timeField Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update textbox Signed-off-by: NivedhaSenthil <[email protected]> * #1334 fix tests Signed-off-by: NivedhaSenthil <[email protected]> * #1334 update tabel cells Signed-off-by: NivedhaSenthil <[email protected]> * #1334 fix test Signed-off-by: NivedhaSenthil <[email protected]> * #1334 move checkbox logic to relavant wrapper Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup filefield Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup button Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup textbox Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup radiobutton Signed-off-by: NivedhaSenthil <[email protected]> * #1334 clean up dropdown Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup range and colot Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup timefield Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup dollar,li,link,image Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup text Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup tabel cell Signed-off-by: NivedhaSenthil <[email protected]> * fix tests #1334 Signed-off-by: NivedhaSenthil <[email protected]> * Merge branch 'master' into migrate_selectors Signed-off-by: NivedhaSenthil <[email protected]> * Revert "Merge branch 'master' into migrate_selectors" This reverts commit 199e40d8b1363598deb4ba57f38c3eea0c97dc94. Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup tests Signed-off-by: NivedhaSenthil <[email protected]> * #1334 cleanup imports Signed-off-by: NivedhaSenthil <[email protected]> * #1334 remove console log Signed-off-by: NivedhaSenthil <[email protected]> * #1334 support node10 Signed-off-by: NivedhaSenthil <[email protected]> * #1334 revert tablecell to use xpath Signed-off-by: NivedhaSenthil <[email protected]> * #1343 cleanup element wrapper factory Signed-off-by: NivedhaSenthil <[email protected]> * Bump version to 1.0.14 Signed-off-by: NivedhaSenthil <[email protected]> Co-authored-by: Vinay Shankar Shukla <[email protected]>
- Loading branch information
1 parent
5480a4a
commit 7949551
Showing
38 changed files
with
912 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const { $function, match } = require('../elementSearch'); | ||
const ElementWrapper = require('./elementWrapper'); | ||
const { getElementGetter, desc } = require('./helper'); | ||
|
||
function getButtonElementWithLabel(label) { | ||
const buttons = []; | ||
const inputTypes = ['button', 'submit', 'reset', 'image']; | ||
function checkAndPushElement(elem) { | ||
if ( | ||
(elem.tagName && elem.tagName.toLowerCase() === 'button') || | ||
(elem.tagName && | ||
elem.tagName.toLowerCase() == 'input' && | ||
elem.type && | ||
inputTypes.includes(elem.type.toLowerCase())) | ||
) { | ||
buttons.push(elem); | ||
} | ||
} | ||
const matchingLabels = [...document.querySelectorAll('label')].filter((labelElem) => { | ||
return labelElem.innerText.toLowerCase().includes(label.toLowerCase()); | ||
}); | ||
for (let matchingLabel of matchingLabels) { | ||
const labelFor = matchingLabel.getAttribute('for'); | ||
if (labelFor) { | ||
//check label with attribute for | ||
const labelForElement = document.getElementById(labelFor); | ||
checkAndPushElement(labelForElement); | ||
} else { | ||
// check child node of label tag | ||
matchingLabel.childNodes.forEach((elem) => { | ||
checkAndPushElement(elem); | ||
}); | ||
} | ||
} | ||
// check inputs matching types and value | ||
const matchingValues = document.querySelectorAll( | ||
`input[type="submit"][value*="${label}"],input[type="image"][value*="${label}"],input[type="reset"][value*="${label}"],input[type="button"][value*="${label}"]`, | ||
); | ||
return buttons.concat([...matchingValues]); | ||
} | ||
class ButtonWrapper extends ElementWrapper { | ||
constructor(attrValuePairs, _options, ...args) { | ||
super('Button', 'label', attrValuePairs, _options, ...args); | ||
|
||
this.getByButton = getElementGetter( | ||
this.selector, | ||
async () => match(this.selector.label, this.options).elements('button', 0, 0), | ||
'button', | ||
this.options.selectHiddenElements, | ||
); | ||
|
||
this.getByInput = getElementGetter( | ||
this.selector, | ||
async () => | ||
await $function( | ||
getButtonElementWithLabel, | ||
this.selector.label, | ||
this.options.selectHiddenElements, | ||
), | ||
'input[type="submit"],input[type="reset"],input[type="button"],input[type="image"]', | ||
this.options.selectHiddenElements, | ||
); | ||
this._get = async () => { | ||
const input = await this.getByInput(); | ||
if (input.length) { | ||
return input; | ||
} | ||
return this.getByButton(); | ||
}; | ||
} | ||
} | ||
module.exports = ButtonWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { $$xpath, $$ } = require('../elementSearch'); | ||
const { handleRelativeSearch } = require('../proximityElementSearch'); | ||
const ElementWrapper = require('./elementWrapper'); | ||
|
||
class DollarWrapper extends ElementWrapper { | ||
constructor(attrValuePairs, _options, ...args) { | ||
super('CustomSelector', 'query', attrValuePairs, _options, ...args); | ||
this._get = async () => { | ||
return await handleRelativeSearch( | ||
await (this.selector.label.startsWith('//') || this.selector.label.startsWith('(') | ||
? $$xpath(this.selector.label, this.options.selectHiddenElements) | ||
: $$(this.selector.label, this.options.selectHiddenElements)), | ||
this.selector.args, | ||
); | ||
}; | ||
} | ||
} | ||
module.exports = DollarWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.