Skip to content

(#324) Updated assert to handle valid find parameter types #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/assert.class.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
import {LocationParameters} from "./locationparameters.class";
import {Region} from "./region.class";
import {ScreenClass} from "./screen.class";
import {FirstArgumentType} from "./typings";

export class AssertClass {
constructor(private screen: ScreenClass) {
}

public async isVisible(pathToNeedle: string, searchRegion?: Region, confidence?: number) {
public async isVisible(needle: FirstArgumentType<typeof ScreenClass.prototype.find>, searchRegion?: Region, confidence?: number) {
const identifier = (typeof needle === "string") ? needle : (await needle).id;

try {
await this.screen.find(
pathToNeedle,
needle,
{searchRegion, confidence} as LocationParameters,
);
} catch (err) {
if (searchRegion !== undefined) {
throw new Error(
`Element '${pathToNeedle}' not found in region ${searchRegion.toString()}. Reason: ${err}`,
`Element '${identifier}' not found in region ${searchRegion.toString()}. Reason: ${err}`,
);
} else {
throw new Error(`Element '${pathToNeedle}' not found. Reason: ${err}`);
throw new Error(`Element '${identifier}' not found. Reason: ${err}`);
}
}
}

public async notVisible(pathToNeedle: string, searchRegion?: Region, confidence?: number) {
public async notVisible(needle: FirstArgumentType<typeof ScreenClass.prototype.find>, searchRegion?: Region, confidence?: number) {
const identifier = (typeof needle === "string") ? needle : (await needle).id;

try {
await this.screen.find(
pathToNeedle,
needle,
{searchRegion, confidence} as LocationParameters,
);
} catch (err) {
return;
}
throw new Error(`'${pathToNeedle}' is visible`);
throw new Error(`'${identifier}' is visible`);
}
}