防止在 Specflow 报告中显示 Specflow 步骤参数,即 'password'

Prevent Specflow Step Parameter Displaying In Specflow Report i.e. 'password'

我有一堆使用 'Username' 和 'Password' 参数的 Specflow 步骤定义。

当步骤显示在 Specflow 报告中时,它会呈现传入的值。这通常不是问题,因为它在测试环境中 运行 并且报告仅通过电子邮件发送给选定的个人......但是,输出存储在本地,我想将其移动到更容易访问的位置(以防我' m 不可用)...因此需要隐藏值。

我希望能够在使用特定参数后对它们进行哈希处理。所以 Default Specflow 报告不显示实际值。

我已经有了一个潜在的解决方法,方法是使用存储在覆盖步骤参数的 JSON 文件中的值...从反复试验中我知道这种方法不会显示 JSON 值...相反,Specflow 报告保留了特征文件中最初使用的值。

功能场景示例:

Scenario: As a registered user I can log in with a valid email and password
Given I am on the Home page
When I click the Sign In option
Then The login page is displayed
When I enter valid login details and submit 'tester@test.co.uk', 'Password1!'
Then I am logged in
And The Sign In display name is displayed in the header 'Tester McTestFace'

步骤定义示例:

[When(@"I enter valid login details and submit '(.*)', '(.*)'")]
    public void WhenIEnterValidLoginDetailsAndSubmit(string email, string password)
    {
        PageAction.CompleteLoginForm(email, password);
    }

然后将其传递给 WebDriver 以执行适用的操作

我的 Json 覆盖方法是我目前唯一的选择,但希望有一些非常简单的内置 Specflow 功能可以散列值(尚未找到任何文档)。

将每个 e-mail 的密码放在 ScenarioContext 中,然后只引用场景中的 e-mail 地址。

您的步骤定义变为:

[Binding]
public class LoginSteps
{
    private readonly ScenarioContext scenario;

    public LoginSteps(ScenarioContext scenario)
    {
        this.scenario = scenario;

        scenario.Set("Password1", "email1");
        scenario.Set("Password2", "email2");
        ...
        scenario.Set("PasswordN", "emailN");
    }

    [When(@"I log in as '(.*)'")]
    public void WhenILogInAs(string email)
    {
        PageAction.CompleteLoginForm(email, scenario.Get(email));
    }
}

你的场景变成:

Scenario: As a registered user I can log in with a valid email and password
    Given I am on the Home page
    When I click the Sign In option
    Then The login page is displayed
    When I log in as 'tester@test.co.uk'
    Then I am logged in
    And The Sign In display name is displayed in the header 'Tester McTestFace'