Skip to content

Commit

Permalink
Add tests for 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 82d021c commit 0afaa70
Show file tree
Hide file tree
Showing 25 changed files with 1,120 additions and 1 deletion.
88 changes: 88 additions & 0 deletions tests/api-output/parseWaitForPropertyFalse/basic-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
instructions = [
"""async function checkPropForElem(elem) {
return await elem.evaluate(e => {
function checkObjectPaths(object, path, callback, notFoundCallback) {
const found = [];
for (const subPath of path) {
found.push(subPath);
if (object === undefined || object === null) {
notFoundCallback(found);
return;
}
object = object[subPath];
}
callback(object);
}
const nonMatchingProps = [];
const parseWaitForPropDict = [];
const nullProps = [];
for (const prop of nullProps) {
checkObjectPaths(e, prop, val => {
if (val !== undefined && val !== null) {
const p = prop.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Expected property `\" + p + \"` to not exist, found: `\" + val + \"`\");
return;
}
}, _notFound => {
});
}
for (const [parseWaitForPropKey, parseWaitForPropValue] of parseWaitForPropDict) {
checkObjectPaths(e, parseWaitForPropKey, val => {
if (val === undefined) {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
return;
}
if (val !== parseWaitForPropValue) {
nonMatchingProps.push(\"expected `\" + parseWaitForPropValue + \"` for property `\" + parseWaitForPropKey + \"`, found `\" + val + \"`\");
}
}, _notFound => {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
});
}
return nonMatchingProps;
});
}
const timeLimit = page.getDefaultTimeout();
const timeAdd = 50;
let allTime = 0;
let parseWaitForProp = null;
while (true) {
while (true) {
parseWaitForProp = await page.$$(\"a\");
if (parseWaitForProp.length !== 0) {
parseWaitForProp = parseWaitForProp[0];
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
throw new Error(\"The CSS selector \\\"a\\\" was not found\");
}
}
const nonMatchingProps = await checkPropForElem(parseWaitForProp);
if (nonMatchingProps.length !== 0) {
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
const props = nonMatchingProps.join(\", \");
throw new Error(\"All properties still match\");
}
}""",
]
wait = false
warnings = [
]
checkResult = true
88 changes: 88 additions & 0 deletions tests/api-output/parseWaitForPropertyFalse/basic-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
instructions = [
"""async function checkPropForElem(elem) {
return await elem.evaluate(e => {
function checkObjectPaths(object, path, callback, notFoundCallback) {
const found = [];
for (const subPath of path) {
found.push(subPath);
if (object === undefined || object === null) {
notFoundCallback(found);
return;
}
object = object[subPath];
}
callback(object);
}
const nonMatchingProps = [];
const parseWaitForPropDict = [[[\"x\"],\"1\"]];
const nullProps = [];
for (const prop of nullProps) {
checkObjectPaths(e, prop, val => {
if (val !== undefined && val !== null) {
const p = prop.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Expected property `\" + p + \"` to not exist, found: `\" + val + \"`\");
return;
}
}, _notFound => {
});
}
for (const [parseWaitForPropKey, parseWaitForPropValue] of parseWaitForPropDict) {
checkObjectPaths(e, parseWaitForPropKey, val => {
if (val === undefined) {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
return;
}
if (val !== parseWaitForPropValue) {
nonMatchingProps.push(\"expected `\" + parseWaitForPropValue + \"` for property `\" + parseWaitForPropKey + \"`, found `\" + val + \"`\");
}
}, _notFound => {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
});
}
return nonMatchingProps;
});
}
const timeLimit = page.getDefaultTimeout();
const timeAdd = 50;
let allTime = 0;
let parseWaitForProp = null;
while (true) {
while (true) {
parseWaitForProp = await page.$$(\"a\");
if (parseWaitForProp.length !== 0) {
parseWaitForProp = parseWaitForProp[0];
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
throw new Error(\"The CSS selector \\\"a\\\" was not found\");
}
}
const nonMatchingProps = await checkPropForElem(parseWaitForProp);
if (nonMatchingProps.length !== 0) {
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
const props = nonMatchingProps.join(\", \");
throw new Error(\"All properties still match\");
}
}""",
]
wait = false
warnings = [
]
checkResult = true
88 changes: 88 additions & 0 deletions tests/api-output/parseWaitForPropertyFalse/basic-3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
instructions = [
"""async function checkPropForElem(elem) {
return await elem.evaluate(e => {
function checkObjectPaths(object, path, callback, notFoundCallback) {
const found = [];
for (const subPath of path) {
found.push(subPath);
if (object === undefined || object === null) {
notFoundCallback(found);
return;
}
object = object[subPath];
}
callback(object);
}
const nonMatchingProps = [];
const parseWaitForPropDict = [[[\"x\"],\"1\"],[[\"y\"],\"2\"]];
const nullProps = [];
for (const prop of nullProps) {
checkObjectPaths(e, prop, val => {
if (val !== undefined && val !== null) {
const p = prop.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Expected property `\" + p + \"` to not exist, found: `\" + val + \"`\");
return;
}
}, _notFound => {
});
}
for (const [parseWaitForPropKey, parseWaitForPropValue] of parseWaitForPropDict) {
checkObjectPaths(e, parseWaitForPropKey, val => {
if (val === undefined) {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
return;
}
if (val !== parseWaitForPropValue) {
nonMatchingProps.push(\"expected `\" + parseWaitForPropValue + \"` for property `\" + parseWaitForPropKey + \"`, found `\" + val + \"`\");
}
}, _notFound => {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
});
}
return nonMatchingProps;
});
}
const timeLimit = page.getDefaultTimeout();
const timeAdd = 50;
let allTime = 0;
let parseWaitForProp = null;
while (true) {
while (true) {
parseWaitForProp = await page.$$(\"a\");
if (parseWaitForProp.length !== 0) {
parseWaitForProp = parseWaitForProp[0];
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
throw new Error(\"The CSS selector \\\"a\\\" was not found\");
}
}
const nonMatchingProps = await checkPropForElem(parseWaitForProp);
if (nonMatchingProps.length !== 0) {
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
const props = nonMatchingProps.join(\", \");
throw new Error(\"All properties still match\");
}
}""",
]
wait = false
warnings = [
]
checkResult = true
88 changes: 88 additions & 0 deletions tests/api-output/parseWaitForPropertyFalse/color-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
instructions = [
"""async function checkPropForElem(elem) {
return await elem.evaluate(e => {
function checkObjectPaths(object, path, callback, notFoundCallback) {
const found = [];
for (const subPath of path) {
found.push(subPath);
if (object === undefined || object === null) {
notFoundCallback(found);
return;
}
object = object[subPath];
}
callback(object);
}
const nonMatchingProps = [];
const parseWaitForPropDict = [[[\"color\"],\"blue\"]];
const nullProps = [];
for (const prop of nullProps) {
checkObjectPaths(e, prop, val => {
if (val !== undefined && val !== null) {
const p = prop.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Expected property `\" + p + \"` to not exist, found: `\" + val + \"`\");
return;
}
}, _notFound => {
});
}
for (const [parseWaitForPropKey, parseWaitForPropValue] of parseWaitForPropDict) {
checkObjectPaths(e, parseWaitForPropKey, val => {
if (val === undefined) {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
return;
}
if (val !== parseWaitForPropValue) {
nonMatchingProps.push(\"expected `\" + parseWaitForPropValue + \"` for property `\" + parseWaitForPropKey + \"`, found `\" + val + \"`\");
}
}, _notFound => {
const p = parseWaitForPropKey.map(p => `\"${p}\"`).join('.');
nonMatchingProps.push(\"Property `\" + p + \"` doesn't exist\");
});
}
return nonMatchingProps;
});
}
const timeLimit = page.getDefaultTimeout();
const timeAdd = 50;
let allTime = 0;
let parseWaitForProp = null;
while (true) {
while (true) {
parseWaitForProp = await page.$$(\"a\");
if (parseWaitForProp.length !== 0) {
parseWaitForProp = parseWaitForProp[0];
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
throw new Error(\"The CSS selector \\\"a\\\" was not found\");
}
}
const nonMatchingProps = await checkPropForElem(parseWaitForProp);
if (nonMatchingProps.length !== 0) {
break;
}
await new Promise(r => setTimeout(r, timeAdd));
if (timeLimit === 0) {
continue;
}
allTime += timeAdd;
if (allTime >= timeLimit) {
const props = nonMatchingProps.join(\", \");
throw new Error(\"All properties still match\");
}
}""",
]
wait = false
warnings = [
]
checkResult = true
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """expected a tuple, found nothing"""
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """expected a tuple, found `hello` (an ident)"""
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """expected a selector, found `1` (a number) (first element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-4.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """expected a selector, found `1` (a number) (first element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-5.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """expected a JSON dict, found `2` (a number) (second element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-6.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """type \"json\" (`{\"a\": 2}`) is not allowed as value in this JSON dict, allowed types are: [`ident`, `number`, `string`] (second element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseWaitForPropertyFalse/err-7.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """unexpected ident `a` (third element of the tuple). Allowed idents are: [`ALL`, `CONTAINS`, `ENDS_WITH`, `NEAR`, `STARTS_WITH`]"""
Loading

0 comments on commit 0afaa70

Please sign in to comment.