【问题标题】:How can I access the list of Steps in my Scenario in a SpecFlow [AfterScenario]?如何在 SpecFlow [AfterScenario] 中访问我的场景中的步骤列表?
【发布时间】:2017-05-18 12:43:02
【问题描述】:

在我的 SpecFlow [AfterScenario] 步骤中,我通过他们的 api 将结果推送到 TestRails。我想发布在 cmets 中执行的步骤列表,但我确实看到了访问该信息的任何方法。

【问题讨论】:

    标签: bdd specflow testrail


    【解决方案1】:

    我最终添加了一个BeforeStep 来记录我想要的步骤信息。

        [BeforeStep()]
        public void RecordStep()
        {
            var stepContext = ScenarioContext.Current.StepContext;
            var scenarioTitle = ScenarioContext.Current.ScenarioInfo.Title;
    
            List<string> steps;
            if (!this.scenarioSteps.TryGetValue(scenarioTitle, out steps))
            {
                steps = new List<string>();
                this.scenarioSteps[scenarioTitle] = steps;
            }
    
            steps.Add($"{stepContext.StepInfo.StepDefinitionType} {stepContext.StepInfo.Text}");
        }
    

    【讨论】:

    • 感谢您的建议!我最终更改了“scenarioSteps”变量范围并将其包含在 FeatureContext 中,这样我就可以在并行执行测试时在静态 [AfterFeature] 方法中访问所有这些信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    相关资源
    最近更新 更多