【发布时间】:2020-01-29 15:07:42
【问题描述】:
我有一个使用测试报告框架的测试套件,我需要通过一个基类运行该框架,一切正常,但是对于我运行的每个场景,[BeforeScenario] 被调用 10 次,我的每个功能被调用 1 次套件,奇怪的是拆解只运行一次。
这是我的基类的样子:
[Binding]
public class BaseStep : AllureReport
{
public DriverSupport _support;
public BaseStep(DriverSupport support)
{
_support = support;
}
[BeforeScenario]
public void Setup(FeatureContext context)
{
_support.startDriver();
AllureLifecycle.Instance.RunStep(() =>
{
TestContext.Progress.WriteLine(
$"Test \"{TestExecutionContext.CurrentContext.CurrentTest.FullName}\" is starting...");
});
}
[AfterScenario, Order(0)]
private void TearDown()
{
AllureLifecycle.Instance.RunStep(() =>
{
TestContext.Progress.WriteLine(
$"Test {TestExecutionContext.CurrentContext.CurrentTest.FullName}\" is stopping...");
});
}
这就是我的功能步骤文件的样子(其中有 10 个)
[Binding]
public class TestSteps1:BaseStep
{
public TestSteps1(DriverSupport support) : base(suppprt)
{
}
[Given(@"user goes to (.*)")]
public void GivenUserGoesTo(string p0)
{
_support.driver.GoToUrl(p0)
}
当我自己在一个特性中运行一个场景时,它会打印启动驱动程序并打印“test xxx is starting...”10 次,对于我拥有的每个特性一次,我只希望它运行一次。
我曾考虑将 beforescenario 移至 step 类本身,但我的许多功能使用来自多个 step 文件的 step,所以我认为这将是一个问题。有没有办法让它在每个场景中只运行一次 BeforeScenario?
【问题讨论】: