Skip to content

Commit c008a49

Browse files
committed
(#324) Updated assert to handle valid find parameter types
1 parent 719f27e commit c008a49

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Diff for: lib/assert.class.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
import {LocationParameters} from "./locationparameters.class";
22
import {Region} from "./region.class";
33
import {ScreenClass} from "./screen.class";
4+
import {FirstArgumentType} from "./typings";
45

56
export class AssertClass {
67
constructor(private screen: ScreenClass) {
78
}
89

9-
public async isVisible(pathToNeedle: string, searchRegion?: Region, confidence?: number) {
10+
public async isVisible(needle: FirstArgumentType<typeof ScreenClass.prototype.find>, searchRegion?: Region, confidence?: number) {
11+
const identifier = (typeof needle === "string") ? needle : (await needle).id;
12+
1013
try {
1114
await this.screen.find(
12-
pathToNeedle,
15+
needle,
1316
{searchRegion, confidence} as LocationParameters,
1417
);
1518
} catch (err) {
1619
if (searchRegion !== undefined) {
1720
throw new Error(
18-
`Element '${pathToNeedle}' not found in region ${searchRegion.toString()}. Reason: ${err}`,
21+
`Element '${identifier}' not found in region ${searchRegion.toString()}. Reason: ${err}`,
1922
);
2023
} else {
21-
throw new Error(`Element '${pathToNeedle}' not found. Reason: ${err}`);
24+
throw new Error(`Element '${identifier}' not found. Reason: ${err}`);
2225
}
2326
}
2427
}
2528

26-
public async notVisible(pathToNeedle: string, searchRegion?: Region, confidence?: number) {
29+
public async notVisible(needle: FirstArgumentType<typeof ScreenClass.prototype.find>, searchRegion?: Region, confidence?: number) {
30+
const identifier = (typeof needle === "string") ? needle : (await needle).id;
31+
2732
try {
2833
await this.screen.find(
29-
pathToNeedle,
34+
needle,
3035
{searchRegion, confidence} as LocationParameters,
3136
);
3237
} catch (err) {
3338
return;
3439
}
35-
throw new Error(`'${pathToNeedle}' is visible`);
40+
throw new Error(`'${identifier}' is visible`);
3641
}
3742
}

0 commit comments

Comments
 (0)