具有大量控件的页面的 Specflow

Specflow for a page with a lot of controls

我使用 Specflow 进行测试自动化,我需要测试用户是否可以注册。

问题是注册的字段很多,30个左右

我的脚本看起来像这样:

And user is adding <value1> in the TextBox1 field
And user is adding <value2> in the TextBox2 field
...
And user is adding <value3> in the TextBox3 field

Outline scenario

<value1> <value2> <value3>

这在 Specflow 中是一个好方法还是我应该像这样压缩所有内容:

And the user registers by filling in all the fields

避免使用用户界面术语来表述您的步骤。而是专注于注册用户的业务流程。对于大型表格,我发现一步中的垂直数据表格非常清晰和简洁。您没有包含太多关于用户注册过程的信息,所以我会补上一些内容,也许您可​​以推断到您的特定应用程序。

When the user registers with the following information:
    | Field      | Value |
    | First Name | ...   |
    | Last Name  | ...   |
    | Username   | ...   |
    | Address    | ...   |
    | City       | ...   |
    | State      | ...   |

填写大型表格的复杂性在步骤定义中得到处理,或许还有一个知道如何与注册页面交互的“页面模型”class。使用 Table.CreateInstance<T> 扩展方法将 table 参数映射到 C# 中的强类型对象。

[When(@"the user registers with the following information:")]
public void WhenTheUserRegistersWithTheFollowingInformation(Table table)
{
    var data = table.CreateInstance<RegisterUserDataRow>();
    var registrationPage = new RegistrationPage(driver); // pass Selenium driver object

    registrationPage.RegisterNewUser(username: data.Username,
                                     firstName: data.FirstName,
                                     lastName: data.LastName,
                                     address: data.Address,
                                     city: data.City,
                                     state: data.State);
}

page model class:

public class RegistrationPage
{
    public void RegisterNewUser(string username, string firstName, string lastName, string address, string city, string state)
    {
        UsernameField.SendKeys(username);
        FirstNameField.SendKeys(firstName);
        ...
        RegisterButton.Click();
    }
}