toBeElementsArrayOfSize seems to alter the array it's check for a moment
await browser.url("https://the-internet.herokuapp.com/checkboxes");
const checkboxes = await $$('input[type="checkbox"]').getElements();
console.log(`Length before: ${checkboxes.length}`);
await expect(checkboxes).toBeElementsArrayOfSize(2);
const firstCheckbox = checkboxes[0];
console.log(`Length after: ${checkboxes.length}`);
await browser.pause(2000);
console.log(`Length after a pause: ${checkboxes.length}`);
await expect(checkboxes).toBeElementsArrayOfSize(2);
console.log(`Checkbox: ${firstCheckbox}`);
try {
await firstCheckbox.click();
} catch (e) {
console.error(`can't click ${e}`);
}
Output
[0-0] Length before: 2
[0-0] Length after: 0
[0-0] Length after a pause: 0
[0-0] Checkbox: undefined
[0-0] can't click TypeError: Cannot read properties of undefined (reading 'click')
I'm assuming this is an expect-webdriverio thing and not a @wdio thing
@brickfungus can you verify you are using the latest version? Also can you provide a reproducible example?
Yes i'm on latest version of all, and i posted an example in the original post
@mathew-jithin mind taking a look, I think this is related to your recent change in #1665.
Hi @christian-bromann Let me have a check on this today.
i mean... i guess the updated instructions
**Note:** This matcher will update the passed array with the latest elements if the assertion passes. However, if you've reassigned the variable, you'll need to fetch the elements again.
says it. Feel like this should've been a major release then, since this broke tests for us
@brickfungus Yes, this was the change done in the previous PR.
@christian-bromann Can you please help me with a suggestion on the expected workflow to be changed to? Will do accordingly.
I am particularly concerned about this part:
await browser.url("https://the-internet.herokuapp.com/checkboxes");
const checkboxes = await $$('input[type="checkbox"]').getElements();
console.log(`Length before: ${checkboxes.length}`);
await expect(checkboxes).toBeElementsArrayOfSize(2);
const firstCheckbox = checkboxes[0];
which logs:
[0-0] Length before: 2
[0-0] Length after: 0
The await expect(checkboxes).toBeElementsArrayOfSize(2); assertion should not remove the items of the array, instead it should add them when they were 0 before. This would be the expected behavior if the assertion would be await expect(checkboxes).not.toBeElementsArrayOfSize(2);
Sure. Let me check on this and see what happened.
Any progress on this? I'm having to rewrite a lot of tests to accommodate this
@brickfungus see the "help wanted" label, any contributions are welcome!
I think I figured it out. Will have a PR soon
Sorry guys for the messup. I am actually travelling and is away from my laptop, so was not able to make the change. Thanks a lot 🥲
Best Regards, Jithin Mathew Connect with me on LinkedIn https://in.linkedin.com/in/mathewjithin
On Sat, 9 Nov 2024 at 5:24 AM, Christian Bromann @.***> wrote:
Closed #1679 https://github.com/webdriverio/expect-webdriverio/issues/1679 as completed via #1706 https://github.com/webdriverio/expect-webdriverio/pull/1706.
— Reply to this email directly, view it on GitHub https://github.com/webdriverio/expect-webdriverio/issues/1679#event-15228538346, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDUP2YKPL24CQNEEC3ZJEDZ7U2ZLAVCNFSM6AAAAABPTH5SBCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJVGIZDQNJTHAZTINQ . You are receiving this because you were mentioned.Message ID: @.*** com>