我有下面提到的功能文件,我需要使用步骤定义作为通用方法进行验证,以便它可以重复使用。
| FieldName | IsFieldMandatory | IsFieldEnabled | ErrorMessage | ControlType |
| first name: | Mandatory | Enabled | enter a valid first name | TexBox |
| second name: | Mandatory | Enabled | enter a valid second name | TexBox |
| account name: | Mandatory | Enabled | enter a valid account | TexBox |
| broker name: | Mandatory | Enabled | enter a valid broker | TexBox |
步骤定义如下,每次使用每个元素Id字符串在字符串数组中进行硬编码。
我可以通过仅使用功能文件数据来制作此通用,而不将ID字符串调用到组件文件
public void PageContainsTheFollowingFieldsAsDefault(IList<ModelData> inputData)
{
foreach (int i=0;i<inputData.count();i++)
{ string[] elementIdArray = {ContactFnameId, ContactSurnameId,ContactEmailId, AccountnameId};
componentclass _control = new componentclass(elementIdArray[i],_webDriver)
Assert.AreEqual(inputData[i].FieldName, _control.LabelText());
Assert.AreEqual(GenericHelper.IsRequiredToBoolean(inputData[i].IsFieldMandatory), _control.MandatoryFieldCheck());
Assert.AreEqual(GenericHelper.StringToBoolean(inputData[i].IsFieldEnabled), _control.IsEnabled());
//As account Name doesn't have any error message validation
if (inputData[i].FieldName != "Accountant name:")
{
Assert.AreEqual(inputData[i].FieldErrorMessage, _control.ValidateErrorMessage());
}
}
}