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?
I've used 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...
ExpectedConditions.visibilityOf()
orExpectedConditions.elementToBeClickable()
the test will not fail if these functions timeout before the element is visible in the DOM or becomes clickable. It just throws a timeout error and moves on the the next step. Looking for some ideas on how to explicitly fail if something like that happens that could be reused for multiple scenarios. Maybe I'm overthinking it. I don't know. Just having a hard time picturing how this would work.TimeoutException
? If something like this is thrown, the test fails and results in anerror
. Unless the second test is dependent on the first one, it should not matter, if it is then this is what should be fixed as making test dependent on each other is bad practice.