【发布时间】:2015-11-04 10:10:30
【问题描述】:
作为 SharePoint 自动化测试的一部分,我尝试使用 System.Diagnostics.Process 以其他用户身份打开 Internet Explorer。下面是 C# 代码
System.Diagnostics.Process p = new System.Diagnostics.Process();
// Domain and User Name:
p.StartInfo.Domain = "MYDOMAIN";
p.StartInfo.UserName = "myusername";
// Command to execute and arguments:
p.StartInfo.FileName = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";
p.StartInfo.Arguments = "http://url/AllItems.aspx";
// Build the SecureString password...
System.String rawPassword = "thepassword";
System.Security.SecureString encPassword = new System.Security.SecureString();
foreach (System.Char c in rawPassword)
{
encPassword.AppendChar(c);
}
p.StartInfo.Password = encPassword;
// The UseShellExecute flag must be turned off in order to supply a password:
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.Start();
当我运行这个自动化测试时,Visual Studio 返回通知我测试成功,但是 Internet Explorer 没有打开。
为了让窗口出现,我的代码中是否缺少某些内容?在运行测试之前没有运行 iexplore 进程。
【问题讨论】:
标签: c# automation