I am currently using protractor but the idea would be similar for any flavor of Selenium. Right now, depending on which step the test is on, my current framework will wait for elements to be interactable before proceeding. What I would rather do is explicitly fail if the test encounters some unexpected behavior.
For example, let's say I am filling out a form and expected behavior is that when the form is submitted I am redirected to another page in the app. Typically, I will wait for the next element I want to interact with to be enabled in such a way for me to do that. Now, assume something went wrong with the form and instead of proceeding I get an error (i.e. red toast) and the form doesn't get submitted or the page doesn't redirect. The problem I've noticed in this scenario is that the test will wait for the element, hit the default timeout and throw an error, then it will attempt the next step in the test, hit the timeout and error, and so on. Instead of doing all this waiting I would rather explicitly fail and move on to the next test.
I'm looking for ideas on how to explicitly fail in this scenario and how to make the mechanism for failing reusable so it's not scattered all over my framework. Anyone done anything similar to this that worked well?
protractor-fail-fast before but I don't want to use that in this situation. That package will abort the entire test run on the first error/failure. In this case, I want the full suite of tests to run, I just want a specific test to immediately fail and move on to the next test when it encounters some unexpected behavior in my app. I know I will need a custom solution but I'm having trouble thinking through what that solution would looklike. Looking for ideas...