Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate an element is gone using webdriverIO, Mocha and Chai

I'm working on some automated tests, using webdriverIO, Mocha and Chai. I keep running into the same problem when I want to verify if an element is deleted.

I'm working with a shoppingbasket where i delete an item and then verify that it is gone. It takes a while for the item to be gone though, so if I immediately go to the expect, the item is still there.

I have solved this by doing this:

browser.waitForExist(deletedProduct, 5000, true)
expect (boodschappenLijstPage.isProductPresent(SKU), 'the removed item was still there' ).to.equal(false)

The webdriverIO waitfor command waits for the product to dissapear, and after that the chai expect checks if it is gone.

The problem I have with this is that the expect will never fail. If the product is not properly deleted the waitfortimeout will throw an error before I get to the expect part, meaning that the expect part is only reached if the product is gone

I have read through the docs for chai, but I can't seem to find a way of doing this.

Can anyone show be a way of waiting for the product to be gone, without missing the expect (I don't want to use browser.pause for obvious reasons)

like image 848
Martijn Avatar asked Aug 31 '25 15:08

Martijn


1 Answers

Refer this

webElement.waitForDisplayed({ reverse: true });
like image 108
Julian Kolodzey Avatar answered Sep 03 '25 01:09

Julian Kolodzey