作为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进程。
谢谢你的建议Gread和Sudhakar。我试图实现的是以另一个用户的身份打开Internet Explorer,以便我可以运行一些CodedUI来批准工作流程。 – Nicola1234