如何获取SimpleImpersonation库以其他用户身份打开chrome

时间:2020-09-08 17:27:30

标签: c# .net impersonation

我正在尝试以其他用户身份运行硒测试用例。我看到了一篇关于SimpleImpersonation库的堆栈溢出文章。我以管理员身份运行Visual Studio,但我需要使用常规凭据在Chrome浏览器之外运行chrome。我已经成功地以非管理员身份模拟,但是当我通过Visual Studio运行google chrome时,它仍然以我的管理员帐户运行。任何帮助或建议,将不胜感激。

var credentials = new UserCredentials("VT", "joeclark", "Blah");
            Impersonation.RunAsUser(credentials, LogonType.Interactive, () =>
            {
                // do whatever you want as this user.
                FinanceTestCore.GetDriver = testHelpers.StartBrowser(runningLocal);
            });

这是打开Web浏览器的代码

public ChromeDriver StartBrowser(bool runningOnDevMachine = true, ChromeOptions options = null)
        {
            if (options == null)
            {
                options = new ChromeOptions();
            }
            options.AddArguments("start-maximized");

            //if this is running on dev machine then dont run headless
            if (!runningOnDevMachine)
            {
                options.AddArgument("--headless");
                options.AddArgument("--window-size=1920x1080"); 
            }

            //return new ChromeDriver("C:\\TFS\\Net", options);
            return new ChromeDriver("\\\\localhost\\TFS.NET", options); 
        }

0 个答案:

没有答案