-
-
Notifications
You must be signed in to change notification settings - Fork 59
feat: Support $$() with all element's matchers
#1990
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
Draft
dprevost-LMI
wants to merge
42
commits into
webdriverio:main
Choose a base branch
from
dprevost-LMI:fix-matchers-with-$$
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
8d487cb
Ensure mocks used represented wdio framework reality
dprevost-LMI 33349a8
fix bad command
dprevost-LMI 3e5d3c3
Working case of $$ aka ElementArray with `toBeDisplayed`
dprevost-LMI 0a75715
Use Promise.all for ElementArray instead of waiting one by one
dprevost-LMI dbc3d80
Add UTs for ElementArray and Element[]
dprevost-LMI 0696f38
Review after rebase + add awaited element case
dprevost-LMI 31e20ae
fix regression while trying to support Element[]
dprevost-LMI 7eae5be
Code review
dprevost-LMI f37d9da
Add assertions of `executeCommandBeWithArray` and `waitUntil`
dprevost-LMI 96667f5
All to be matchers now compliant with multiple elements + UTs
dprevost-LMI 5587393
fix rebase
dprevost-LMI f89d340
Fix ChainablePromiseElement/Array not correctly considered
dprevost-LMI 62a200b
Add coverage
dprevost-LMI dd1107e
Enhance toHaveText test cases
dprevost-LMI c058c1d
Working cases of toHaveWidth and toHaveHTML with $$()
dprevost-LMI 5048457
Ensure all test dans can run fast with `wait: 1`
dprevost-LMI b9a1846
Add coverage on `executeCommandWithArray` and support edge case
dprevost-LMI 6daeaa6
Review error message assertions and discover a problem
dprevost-LMI 1b9d738
Have failure messages better asserted
dprevost-LMI e0b5003
toHaveAttribute supporting $$() now
dprevost-LMI 485ac1a
Make all `toHave` matcher follow same code patterns
dprevost-LMI 69469dd
Remove `executeCommand` and simplify executeCommandWithArray + coverage
dprevost-LMI fc1bae9
Align typing with expected being an array + trim by default for arrays
dprevost-LMI 4fc12d6
Support of `toHaveHeigth`, `toHaveSize` & `toHaveWidth``
dprevost-LMI 4bea20d
Working support of `$$()` in all element matchers
dprevost-LMI 4932e4f
Deprecate `compareTextWithArray` & remove toHaveClassContaining
dprevost-LMI e32619a
fix possible regression around NumberOptions wait & internal not cons…
dprevost-LMI 7d6acee
Forget toHaveStyle + code review
dprevost-LMI eec4b23
Code review
dprevost-LMI e7123c1
better function naming
dprevost-LMI 60abeb1
Code review
dprevost-LMI 38f0a0b
Code review + remove `toHaveClass` deprecated since v1, 4 versions ago
dprevost-LMI 0817e3b
Support unknown type for `toHaveElementProperty` since example existed
dprevost-LMI 3878980
doc: official support of `$$()`
dprevost-LMI d890d7e
Review & add coverage + discover problem with isNot
dprevost-LMI f58f42c
fix for other PR, waitunitl + toBeerror - to revert later?
dprevost-LMI 086dfe6
fix `.not` cases
dprevost-LMI 31eec83
Finish matchers UT's refactor to be mocked and type safe
dprevost-LMI 25edfab
Missed some bind
dprevost-LMI 6d6414a
Review waitUntil + coverage
dprevost-LMI 1ab8f3d
Better documentation
dprevost-LMI 5a1ffe9
Code review
dprevost-LMI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Multiple Elements Support | ||
|
|
||
| All element matchers work with arrays of elements (e.g., `$$()` results). | ||
| - **Strict Length Matching**: If you provide an array of expected values, the number of values must match the number of elements found. A failure occurs if the lengths differ. | ||
| - **Index-based Matching**: When using an array of expected values, each element is compared to the value at the corresponding index. | ||
| - **Single Value Matching**: If you provide a single expected value, it is compared against *every* element in the array. | ||
| - **Asymmetric Matchers**: Asymmetric matchers can be used within the expected values array for more matching flexibility. | ||
| - If no elements exist, a failure occurs (except with `toBeElementsArrayOfSize`). | ||
| - Options like `StringOptions` or `HTMLOptions` apply to the entire array (except `NumberOptions`). | ||
| - The assertion passes only if **all** elements match the expected value(s). | ||
| - Using `.not` applies the negation to each element (e.g., *all* elements must *not* display). | ||
|
|
||
| **Note:** Strict length matching does not apply on `toHaveText` to preserve existing behavior. | ||
|
|
||
| ## Limitations | ||
| - An alternative to using `StringOptions` (like `ignoreCase` or `containing`) for a single expected value is to use RegEx (`/MyExample/i`) or Asymmetric Matchers (`expect.stringContaining('Example')`). | ||
| - Passing an array of "containing" values, as previously supported by `toHaveText`, is deprecated and not supported for other matchers. | ||
|
|
||
| ## Supported types | ||
|
|
||
| Any of the below element types can be passed to `expect`: | ||
| - `ChainablePromiseArray` (the non-awaited case) | ||
| - `ElementArray` (the awaited case) | ||
| - `Element[]` (the filtered case) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,23 +1,24 @@ | ||
| import { executeCommandBe, aliasFn } from '../../utils.js' | ||
| import { executeCommandBe } from '../../utils.js' | ||
| import { DEFAULT_OPTIONS } from '../../constants.js' | ||
| import type { WdioElementMaybePromise } from '../../types.js' | ||
| import type { WdioElementMaybePromise, WdioElementOrArrayMaybePromise } from '../../types.js' | ||
|
|
||
| export async function toExist( | ||
| received: WdioElementMaybePromise, | ||
| received: WdioElementOrArrayMaybePromise, | ||
| options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS | ||
| ) { | ||
| this.expectation = this.expectation || 'exist' | ||
| this.verb = this.verb || '' | ||
| this.matcherName = this.matcherName || 'toExist' | ||
|
|
||
| await options.beforeAssertion?.({ | ||
| matcherName: 'toExist', | ||
| matcherName: this.matcherName, | ||
| options, | ||
| }) | ||
|
|
||
| const result = await executeCommandBe.call(this, received, el => el?.isExisting(), options) | ||
|
|
||
| await options.afterAssertion?.({ | ||
| matcherName: 'toExist', | ||
| matcherName: this.matcherName, | ||
| options, | ||
| result | ||
| }) | ||
|
|
@@ -26,8 +27,14 @@ export async function toExist( | |
| } | ||
|
|
||
| export function toBeExisting(el: WdioElementMaybePromise, options?: ExpectWebdriverIO.CommandOptions) { | ||
| return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options) | ||
| this.verb = 'be' | ||
| this.expectation = 'existing' | ||
| this.matcherName = 'toBeExisting' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed bad matcher name |
||
| return toExist.call(this, el, options) | ||
| } | ||
| export function toBePresent(el: WdioElementMaybePromise, options?: ExpectWebdriverIO.CommandOptions) { | ||
| return aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options) | ||
| this.verb = 'be' | ||
| this.expectation = 'present' | ||
| this.matcherName = 'toBePresent' | ||
| return toExist.call(this, el, options) | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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,43 +1,37 @@ | ||
| import { executeCommandBe } from '../../utils.js' | ||
| import { DEFAULT_OPTIONS } from '../../constants.js' | ||
| import type { WdioElementOrArrayMaybePromise } from '../../types.js' | ||
|
|
||
| export async function toBeSelected( | ||
| received: ChainablePromiseElement | WebdriverIO.Element, | ||
| received: WdioElementOrArrayMaybePromise, | ||
| options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS | ||
| ) { | ||
| this.verb = this.verb || 'be' | ||
| this.expectation = this.expectation || 'selected' | ||
| this.matcherName = this.matcherName || 'toBeSelected' | ||
|
|
||
| await options.beforeAssertion?.({ | ||
| matcherName: 'toBeSelected', | ||
| matcherName: this.matcherName, | ||
| options, | ||
| }) | ||
|
|
||
| const result = await executeCommandBe.call(this, received, el => el?.isSelected(), options) | ||
|
|
||
| await options.afterAssertion?.({ | ||
| matcherName: 'toBeSelected', | ||
| matcherName: this.matcherName, | ||
| options, | ||
| result | ||
| }) | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| export async function toBeChecked (el: WebdriverIO.Element, options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS) { | ||
| export async function toBeChecked (received: WdioElementOrArrayMaybePromise, options: ExpectWebdriverIO.CommandOptions = DEFAULT_OPTIONS) { | ||
| this.verb = 'be' | ||
| this.expectation = 'checked' | ||
| this.matcherName = 'toBeChecked' | ||
|
|
||
| await options.beforeAssertion?.({ | ||
| matcherName: 'toBeChecked', | ||
| options, | ||
| }) | ||
|
|
||
| const result = await toBeSelected.call(this, el, options) | ||
|
|
||
| await options.afterAssertion?.({ | ||
| matcherName: 'toBeChecked', | ||
| options, | ||
| result | ||
| }) | ||
| const result = await toBeSelected.call(this, received, options) | ||
|
|
||
| return result | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting on merge of #1991