作爲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