Selenium/C#:隐藏自动化测试密码的最佳方式?

Selenium/C#: Best way to hide passwords for automation tests?

我正在寻找一种方式或方法来隐藏我在 visual studio C# 中进行 selenium 自动化测试的密码。

目前,我在我的 C# 代码中硬编码了密码。

正在 youtube 上或此处的 Whosebug 中搜索教程,但没有找到任何有用的内容。

有些人在 C#/Selenium 教程中谈论加密,但据我所知,当有人知道如何编码时,找出密码并不难。我错了吗?

我的同事也在使用自动化测试,所以他们应该也可以在隐藏密码的情况下运行自动化测试。

有什么方法可以隐藏密码,但将其用于 selenium 自动化测试吗?

(如果需要代码,将不胜感激)

SecureString Class

    // Instantiate the secure string.
    SecureString securePwd = new SecureString();
    ConsoleKeyInfo key;

    Console.Write("Enter password: ");
    do {
       key = Console.ReadKey(true);
       
       // Ignore any key out of range.
       if (((int) key.Key) >= 65 && ((int) key.Key <= 90)) {
          // Append the character to the password.
          securePwd.AppendChar(key.KeyChar);
          Console.Write("*");
       }   
    // Exit if Enter key is pressed.
    } while (key.Key != ConsoleKey.Enter);
    Console.WriteLine();

您可以将您的密码设置为环境参数并通过如下方式获取:

string password = Environment.GetEnvironmentVariable("seleniumPassword");

要设置环境变量,您可以使用:

string setEnv = Environment.SetEnvironmentVariable("seleniumPassword", 123456);

123456这里是密码

通过环境变量传递机密是可行的方法。这个答案 有一个很棒的想法,即创建一个 .cmd(对于 Linux 可以很容易地成为一个 .sh)来获取命令参数来设置环境变量。