我使用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";