In SpecFlow how can I share data between steps/features?

前端 未结 6 708
情深已故
情深已故 2020-12-05 01:54

I have 2 features that use a common \'When\' step but have different \'Then\' steps in different classes.

How do I access, for example, the ActionResult from my MVC

6条回答
  •  一个人的身影
    2020-12-05 02:50

    I have a helper class which lets me write

    Current.Value = pageObject;
    

    which is a wrapper over the ScenarioContext. It works off the type name, so it would need to be extended a bit if you need to access two variables of the same type

     public static class Current where T : class
     {
         internal static T Value 
         {
             get { 
                   return ScenarioContext.Current.ContainsKey(typeof(T).FullName)
                   ? ScenarioContext.Current[typeof(T).FullName] as T : null;
                 }
             set { ScenarioContext.Current[typeof(T).FullName] = value; }
         }
     }
    

    2019 edit: I would use @JoeT's answer nowadays, it looks like you get the same benefits without needing to define an extension

提交回复
热议问题