I created a recorded action using the Coded UI Test Builder enters in user credentials into a login window. This initial recording hard coded an encrypted password into a public field of the Params object used by the test method, like this:
[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
}
This works well but I need to retrieve the username and password from a CSV data source to test failure conditions. Question is, how do I convert a password retrieved from the CSV into an encrypted form that can be used with the password box? I looked at SecureString but it does not expose an API to get the encrypted string, which I doubt will be in correct form.
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";