我使用 Coded UI Test Builder 创建了一个录制的操作,将用户凭据输入到登录窗口中。此初始记录将加密密码硬编码到测试方法使用的 Params 对象的公共字段中,如下所示:
[GeneratedCode("Coded UITest Builder", "10.0.40219.1")]
public class StartOccUIParams
{
#region Fields
/// <summary>
/// Type 'username' in 'usernameBox' text box
/// </summary>
public string UIUsernameBoxEditText = "username";
/// <summary>
/// Type '{Tab}' in 'usernameBox' text box
/// </summary>
public string UIUsernameBoxEditSendKeys = "{Tab}";
/// <summary>
/// Type '********' in 'passwordBox' text box
/// </summary>
public string UIPasswordBoxEditSendKeys = "9927b9lJLxdZrqR1G+zHC2MA==";
#endregion
}
这很好用,但我需要从 CSV 数据源中检索用户名和密码来测试失败条件。问题是,如何将从 CSV 检索到的密码转换为可与密码框一起使用的加密形式?我查看了 SecureString,但它没有公开获取加密字符串的 API,我怀疑它的格式是否正确。
var loginParams = UIMap.StartOccUiParams;
loginParams.UIUsernameBoxEditText = TestContext.DataRow["User"].ToString();
var password= TestContext.DataRow["Password"].ToString();
// how do I encrypt password to use below ?
loginParams.UIPasswordBoxEditSendKeys = "encrypted password";