|
1 | 1 | import {LocationParameters} from "./locationparameters.class"; |
2 | 2 | import {Region} from "./region.class"; |
3 | 3 | import {ScreenClass} from "./screen.class"; |
| 4 | +import {FirstArgumentType} from "./typings"; |
4 | 5 |
|
5 | 6 | export class AssertClass { |
6 | 7 | constructor(private screen: ScreenClass) { |
7 | 8 | } |
8 | 9 |
|
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 | + |
10 | 13 | try { |
11 | 14 | await this.screen.find( |
12 | | - pathToNeedle, |
| 15 | + needle, |
13 | 16 | {searchRegion, confidence} as LocationParameters, |
14 | 17 | ); |
15 | 18 | } catch (err) { |
16 | 19 | if (searchRegion !== undefined) { |
17 | 20 | 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}`, |
19 | 22 | ); |
20 | 23 | } else { |
21 | | - throw new Error(`Element '${pathToNeedle}' not found. Reason: ${err}`); |
| 24 | + throw new Error(`Element '${identifier}' not found. Reason: ${err}`); |
22 | 25 | } |
23 | 26 | } |
24 | 27 | } |
25 | 28 |
|
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 | + |
27 | 32 | try { |
28 | 33 | await this.screen.find( |
29 | | - pathToNeedle, |
| 34 | + needle, |
30 | 35 | {searchRegion, confidence} as LocationParameters, |
31 | 36 | ); |
32 | 37 | } catch (err) { |
33 | 38 | return; |
34 | 39 | } |
35 | | - throw new Error(`'${pathToNeedle}' is visible`); |
| 40 | + throw new Error(`'${identifier}' is visible`); |
36 | 41 | } |
37 | 42 | } |
0 commit comments