1
votes

packages: .net core 3.1, Specflow 3.8.7

Solution Structure:

enter image description here

I have Step definitions in project UMW.Selenium.UI (A)

namespace UMW.Selenium.UI.Steps
{
    [Binding]
    public class CalculatorStepDefinitions : UIFramework
    {
        UIBrowser uiBrowser;

        public CalculatorStepDefinitions()
        {
            uiBrowser = new UIBrowser();
        }

        [Given(@"the first number is (.*)")]
        public void GivenTheFirstNumberIs(int p0)
        {
            uiBrowser.NavigateToURL("https://demoqa.com/browser-windows");
        }

    }
}

I have Hooks (BeforeTestRun, BeforeScenario etc.) in another project Selenium.UI.Framework (B).

namespace Selenium.UI.Framework.Framework.Utilities.ScenarioFactory
{
    using LogBuffer = List<string>;

    [Binding]
    [TestClass]
    public class SetupAndTearDown
    {
        internal readonly ScenarioContext _scenarioContext;
        internal readonly FeatureContext _featureContext;
        private readonly IObjectContainer _objectContainer;
        public SetupAndTearDown()
        {

        }

        public SetupAndTearDown(IObjectContainer objectContainer, FeatureContext featureContext, ScenarioContext scenarioContext)
        {
            this._objectContainer = objectContainer;
            _featureContext = featureContext;
            _scenarioContext = scenarioContext;
        }

        [BeforeTestRun]
        public static void InitializeTestSuite()
        {
            ReportsFactory.Report.StartTestSuite();
        }

        [BeforeScenario]
        public void InitializeTestScenario()
        {
            ReportsFactory.Report.StartTestCase();
            //_objectContainer.RegisterInstanceAs(Webdriver.Driver);
        }
    }
}

When I execute scenario from A, it does not call BeforeTestRun/BeforeScenario from B. Here project A uses functions from project B. The test runs successfully bypassing hooks.

1

1 Answers

0
votes

You need to declare bindings from an external assembly in specflow.json.

{
  "stepAssemblies": [
    {
      "assembly": "Selenium.UI.Framework"
    }
  ]
}

Note: the name of the assembly, not the namespace, is required with no file extension. You will need to double check the name of the DLL file created by the Selenium.UI.Framework project.