Need to skip hooks binding in specific scenarios

181 views
Skip to first unread message

anfas...@gmail.com

unread,
Oct 19, 2020, 9:55:40 AM10/19/20
to SpecFlow
Hi,

I need to quit the execution thread in [BeforeTest] after checking a specific condition. 

  [BeforeTestRun]
        public static void SettingsBeforeRun()
        {
            try
            {
                switch (RunStatus)
                {
                    case "Initial":
                        // continue execution
                        break;
                    case "Repeat":
                        // need to quit test execution without moving to BeforeScenario,                                            AfterScenario and AfterTest
                        break;
                }

Please help me if there is any possibility.

Thanks 
Anfas

liam harries

unread,
Oct 19, 2020, 10:16:16 AM10/19/20
to SpecFlow
Calling this will set your test to ignored, it's not perfect but it works.

protected void IgnoreTest()
{
    IUnitTestRuntimeProvider unitTestRuntimeProvider = (IUnitTestRuntimeProvider)
    ScenarioContext
        .GetBindingInstance(typeof(IUnitTestRuntimeProvider));
    unitTestRuntimeProvider.TestIgnore("ignored");

Andreas Willich

unread,
Oct 19, 2020, 10:49:57 AM10/19/20
to SpecFlow
That will not work, as you need a ScenarioContext which is not available in a BeforeTestRun hook.

Why do you start the test execution at all, if you want to cancel it already in the BeforeTestRun? Why do you not check for it outside of the test execution and don't start the execution at all?

-------

Please use for new conversation our new Community Forum at: https://support.specflow.org/hc/en-us/community/topics





--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/specflow/7dfde918-54bf-4477-809a-f0f2cb4e22c6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages