4
votes

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";
1
Never mind. Found Playback.EncryptText. - Klaus Nji
Ideally you post your solution as an answer to your question and accept it. It will be entering the questionlist as solved and not as open anymore. This will not only help people looking for open questions as well as people with the same issue looking for an answer. - AutomatedChaos
+1 because the this really helped me! I agree this solution should be posted as an answer. - pamphlet
Can you post your finding as your answer and accept it please then? - Noctis

1 Answers

4
votes

Use Playback.EncryptText

Encrypts a given text for passing to playback as password property.