仓库指标
- 星标
- (10,558 个星标)
- PR 合并指标
- (PR 指标待抓取)
描述
The Issue
While extending the toBeVisible expectation API to receive an optional parameter of visibility threshold, in response to a feature request (see issue), another missing feature was brought up for discussion, alongside some questions regarding the current API.
- The current API for visibility expectation (toBeVisible(pct?: number)) receives only integers within the range [1, 100], and checks whether the element is visible at least with the given visibility threshold, because of underlying constraints (espresso matchers) and therefore cannot be used to check whether the view has any visibility (
>0%visible), or whether is not visible at all. - Negating the expectation with
not, creates a confusing statement since it is quite nonintuitive what is the expected result (for example,not.toBeVisible(10), this expects the view to have less than 10% visibility). - The current API name for the expectation does not implies that the
pctargument is a threshold, and that the check includes the threshold as a valid visibility percentage (at-leastN%visible, and not greater-thanN%visible). - The default value of the visibility threshold is
75, which is also very nonintuitive or makes any sense.
Suggested Solution
Add new APIs for visibility expectations, to allow any kind of visibility check with more descriptive names, and to deprecated the current method.
(1) toHaveVisibility(): checks whether the element is visible at all (the visibility percent is greater than 0%).
(2) toHaveVisibilityGreaterThan(percent): checks whether the element visibility percent is greater than percent.
(3) toHaveVisibilityGreaterThanOrEqualTo(percent): checks whether the element visibility percent is greater than or equal to percent.
Also, if we want to achieve an even higher level of readability in the tests, we can also provide aliases for the negations of (2) and (3):
(4) toHaveVisibilityLowerThan(percent): checks whether the element visibility percent is lower than percent.
(5) toHaveVisibilityLowerThanOrEqualTo(percent): checks whether the element visibility percent is lower than or equal to percent.