jediwhale / fitsharp

Functional testing tools for .NET
http://fitsharp.github.io
Other
152 stars 73 forks source link

Abandon Story on first exception #171

Closed LodewijkSioen closed 4 years ago

LodewijkSioen commented 4 years ago

We're using FitSharp to automate Selenium scenario's. The problem is that when one step fails, Fit will continue with the following steps. This will cause Selenium to search for elements on a page that is in an invalid state in the next steps. Selenium will timeout when the element is not found, but this causes the tests to run extremely slow when something is wrong.

I see that there is an AbandonStoryTestException, but I have no hook to throw this exception.

What I would like is to abandon the story test on the first exception thrown. Is this possible?

jediwhale commented 4 years ago

Can you write wrapper functions to throw AbandonStoryTestException? e.g.

public void Something(some parameters...) {
    try {
        Selenium.Something(some parameters);
    }
    catch (Exception e) {
        throw new AbandonStoryTestException(e.Message());
    }
}
LodewijkSioen commented 4 years ago

That would mean hundreds of wrapper functions. All my fixtures inherit DoFixture, so I was able to do the following:

public override void DoTable(Parse table)
 {
    base.DoTable(table);

    if (TestStatus.Counts.GetCount("error") > 0)
    {
        TestBrowser.CloseBrowser();
        throw new AbandonStoryTestException("An error occured during this StoryTest. Abandoning test to avoid stale state.");
    }
}

Seems a bit hackish, but it does the job as long as there are not too many rows in a table. Is there a better function that I can override this way?

jediwhale commented 4 years ago

Looks like a good solution