How to get the current executing step information in Specflow

前端 未结 3 2042
一向
一向 2021-01-12 11:10

We are trying to take screenshots for each step.

Everything works fine. But we are not able to correlate the screenshots to the steps which created them.

Wha

3条回答
  •  孤独总比滥情好
    2021-01-12 12:10

    Implementing your own LogTraceListener allows you to get the current Step Definition:

    public class LogTraceListener : ITraceListener
    {
        static public string LastGherkinMessage;
    
        public void WriteTestOutput(string message)
        {
            LastGherkinMessage = message;
    
            Console.WriteLine(message);
        }
    
        public void WriteToolOutput(string message)
        {
           Console.WriteLine(message);
        }
    }
    

    This needs to be registered in the SpecFlow section in App.Config:

    
        
        
    
    

    Having done this, the LastGherkinMessage property will contain the text of the Step Definition just entered. You can access this from within the Step Definition or from anywhere else.

提交回复
热议问题