编码 UI 测试无法打开隐私模式

Coded UI Test Unable to Open Private Mode

我在 VS 2015 中生成的编码 ui 测试如下所示:

    [GeneratedCode("Coded UITest Builder", "14.0.23107.0")]
    public class UINewtabInternetExplorWindow : BrowserWindow
    {



  public UINewtabInternetExplorWindow()
    {
        #region Search Criteria
        this.SearchProperties[UITestControl.PropertyNames.Name] = "New tab";
        this.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
        this.WindowTitles.Add("New tab");
        this.WindowTitles.Add("Certificate Error: Navigation Blocked");
        this.WindowTitles.Add("Home - Select Service");
        this.WindowTitles.Add("Sign in to your account");
        this.WindowTitles.Add("Home");
        #endregion
    }

    public void LaunchUrl(System.Uri url)
    {
        this.CopyFrom(BrowserWindow.Launch(url)); // Can't Add -private
    }

我知道if you pass the "-private" parameter to the launch function您可以在隐私模式下打开 IE。但是我不能!!!

我不能,因为启动函数没有这样的重载函数。有什么办法可以让我每次都只在私人模式下测试我的 UI。请帮忙。谢谢

好吧,我没有直接的方法。但是这个黑客应该帮助你得到你想要的..

// Start the Browser As Process to start in Private mode 
        Process browserProcess = new Process();
        browserProcess.StartInfo.FileName = "iexplore.exe";            
        browserProcess.StartInfo.Arguments = "-private";
        browserProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;

        // Start browser
        browserProcess.Start();
        // Get Process (Browser) Handle 
        Int64 browserHandle =  browserProcess.Handle.ToInt64();


        // Create a new Browser Instance & Assign the browser created as process using the window Handle
        BrowserWindow browserFormHandle = new BrowserWindow();
        browserFormHandle.SearchProperties.Add(BrowserWindow.PropertyNames.WindowHandle, browserFormHandle.ToString());

        browserFormHandle.NavigateToUrl(new Uri("http://www.google.com"));