Skip to content

Commit

Permalink
Add wait-for-property-false command
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 27, 2024
1 parent 8783863 commit 82d021c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const ORDERS = {
'wait-for-position': commands.parseWaitForPosition,
'wait-for-position-false': commands.parseWaitForPositionFalse,
'wait-for-property': commands.parseWaitForProperty,
'wait-for-property-false': commands.parseWaitForPropertyFalse,
'wait-for-size': commands.parseWaitForSize,
'wait-for-text': commands.parseWaitForText,
'wait-for-window-property': commands.parseWaitForWindowProperty,
Expand Down Expand Up @@ -158,6 +159,7 @@ const FATAL_ERROR_COMMANDS = [
'wait-for-count',
'wait-for-count-false',
'wait-for-property',
'wait-for-property-false',
'wait-for-text',
'write',
'write-into',
Expand Down
1 change: 1 addition & 0 deletions src/commands/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module.exports = {
'parseWaitForPosition': wait.parseWaitForPosition,
'parseWaitForPositionFalse': wait.parseWaitForPositionFalse,
'parseWaitForProperty': wait.parseWaitForProperty,
'parseWaitForPropertyFalse': wait.parseWaitForPropertyFalse,
'parseWaitForSize': wait.parseWaitForSize,
'parseWaitForText': wait.parseWaitForText,
'parseWaitForWindowProperty': wait.parseWaitForWindowProperty,
Expand Down
23 changes: 21 additions & 2 deletions src/commands/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,17 @@ ${indentString(incr, 1)}
//
// * ("selector", {"property name": "expected property value"})
function parseWaitForProperty(parser) {
return parseWaitForPropertyInner(parser, false);
}

// Possible inputs:
//
// * ("selector", {"property name": "expected property value"})
function parseWaitForPropertyFalse(parser) {
return parseWaitForPropertyInner(parser, true);
}

function parseWaitForPropertyInner(parser, waitFalse) {
const identifiers = ['ALL', 'CONTAINS', 'ENDS_WITH', 'NEAR', 'STARTS_WITH'];
const ret = validator(parser, {
kind: 'tuple',
Expand Down Expand Up @@ -895,10 +906,17 @@ the check will be performed on the element itself`);
warnings.push(`Special checks (${k.join(', ')}) will be ignored for \`null\``);
}

let comp = '===';
let errorMessage = '"The following properties still don\'t match: [" + props + "]"';
if (waitFalse) {
comp = '!==';
errorMessage = '"All properties still match"';
}

const [init, looper] = waitForElement(selector, varName, {checkAll: enabledChecks.has('ALL')});
const incr = incrWait(`\
const props = nonMatchingProps.join(", ");
throw new Error("The following properties still don't match: [" + props + "]");`);
throw new Error(${errorMessage});`);

const instructions = `\
async function checkPropForElem(elem) {
Expand Down Expand Up @@ -940,7 +958,7 @@ ${init}
while (true) {
${indentString(looper, 1)}
${indentString(checker, 1)}
if (nonMatchingProps.length === 0) {
if (nonMatchingProps.length ${comp} 0) {
break;
}
${indentString(incr, 1)}
Expand Down Expand Up @@ -1283,6 +1301,7 @@ module.exports = {
'parseWaitForPosition': parseWaitForPosition,
'parseWaitForPositionFalse': parseWaitForPositionFalse,
'parseWaitForProperty': parseWaitForProperty,
'parseWaitForPropertyFalse': parseWaitForPropertyFalse,
'parseWaitForText': parseWaitForText,
'parseWaitForWindowProperty': parseWaitForWindowProperty,
'parseWaitForWindowPropertyFalse': parseWaitForWindowPropertyFalse,
Expand Down

0 comments on commit 82d021c

Please sign in to comment.