How to clear these tests?
It looks like your definition of cleanup is that you start by starting with a fresh listing element, and this dialog does not open. Since you delete last item, each of your tests starts with an empty list.
i.e. you want to start over.
After hacking, it can help and make sure that they are very clean, but can slow down your tests.
browser.get('<your root URL>');
If this is βtoo much cleanupβ for you, then your afterEach option is actually not bad, but you end up checking your use case for βdeleteβ as you encoded.
//note I have not run this snipped this so it is not syntax free listing=element.all(By.id("listing")) listing.innerHTML = '';//or whatever should be the default OR listing.removeChild(listing.last());
About the dialog box that opens.
It seems strange that element(By.id("create_btn")).click() does not close the dialog, but what I know about the use case.
To remove a dialog box, you can follow similar DOM manipulation methods and simply delete that DOM, otherwise you will also test another use case.
source share