expect-webdriverio icon indicating copy to clipboard operation
expect-webdriverio copied to clipboard

toBeElementsArrayOfSize seems to alter the array it's check for a moment

Open brickfungus opened this issue 1 year ago • 8 comments

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 avatar Oct 08 '24 22:10 brickfungus

@brickfungus can you verify you are using the latest version? Also can you provide a reproducible example?

christian-bromann avatar Oct 08 '24 22:10 christian-bromann

Yes i'm on latest version of all, and i posted an example in the original post

brickfungus avatar Oct 08 '24 23:10 brickfungus

@mathew-jithin mind taking a look, I think this is related to your recent change in #1665.

christian-bromann avatar Oct 08 '24 23:10 christian-bromann

Hi @christian-bromann Let me have a check on this today.

mathew-jithin avatar Oct 09 '24 02:10 mathew-jithin

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 avatar Oct 09 '24 14:10 brickfungus

@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.

mathew-jithin avatar Oct 09 '24 19:10 mathew-jithin

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);

christian-bromann avatar Oct 09 '24 19:10 christian-bromann

Sure. Let me check on this and see what happened.

mathew-jithin avatar Oct 09 '24 19:10 mathew-jithin

Any progress on this? I'm having to rewrite a lot of tests to accommodate this

brickfungus avatar Nov 07 '24 16:11 brickfungus

@brickfungus see the "help wanted" label, any contributions are welcome!

christian-bromann avatar Nov 07 '24 20:11 christian-bromann

I think I figured it out. Will have a PR soon

brickfungus avatar Nov 07 '24 20:11 brickfungus

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>

mathew-jithin avatar Nov 08 '24 22:11 mathew-jithin