-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#547) Updated toShow to support full search parameters, added the po…
…ssibility to pass a region to directly specify a search region instead of the whole screen
- Loading branch information
Showing
1 changed file
with
36 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
import { FindInput, ScreenClass } from "../../screen.class"; | ||
import { OptionalSearchParameters } from "../../optionalsearchparameters.class"; | ||
import { isRegion, Region } from "../../region.class"; | ||
import { screen } from "../../../index"; | ||
|
||
export const toShow = async ( | ||
received: ScreenClass, | ||
export const toShow = async <PROVIDER_DATA>( | ||
received: ScreenClass | Region, | ||
needle: FindInput, | ||
confidence?: number | ||
parameters?: OptionalSearchParameters<PROVIDER_DATA>, | ||
) => { | ||
let locationParams; | ||
if (confidence) { | ||
locationParams = new OptionalSearchParameters(); | ||
locationParams.confidence = confidence; | ||
} | ||
const identifier = (await needle).id; | ||
try { | ||
await received.find(needle, locationParams); | ||
return { | ||
message: () => `Expected screen to not show ${identifier}`, | ||
pass: true, | ||
}; | ||
} catch (err) { | ||
return { | ||
message: () => `Screen is not showing ${identifier}: ${err}`, | ||
pass: false, | ||
}; | ||
if (isRegion(received)) { | ||
if (parameters != null) { | ||
parameters.searchRegion = received; | ||
} else { | ||
parameters = { searchRegion: received }; | ||
} | ||
try { | ||
await screen.find(needle, parameters); | ||
return { | ||
message: () => `Expected screen to not show ${identifier}`, | ||
pass: true, | ||
}; | ||
} catch (err) { | ||
return { | ||
message: () => `Screen is not showing ${identifier}: ${err}`, | ||
pass: false, | ||
}; | ||
} | ||
} else { | ||
try { | ||
await received.find(needle, parameters); | ||
return { | ||
message: () => `Expected screen to not show ${identifier}`, | ||
pass: true, | ||
}; | ||
} catch (err) { | ||
return { | ||
message: () => `Screen is not showing ${identifier}: ${err}`, | ||
pass: false, | ||
}; | ||
} | ||
} | ||
}; |