質問

I have the following code:

public void Method1()
{
    try
    {
        this.UIMap.abc(TestContext.DataRow["xxx"].ToString());
        this.UIMap.xyz(TestContext.DataRow["zzz"].ToString());
    }
    catch (Exception ex)
    {
        Image pic = this.UIMap.UItestingWindow.CaptureImage();
        pic.Save(@"C:\result.bmp");
        TestContext.AddResultFile(@"C:\result.bmp");
    }

How can I take an image of an Exception with "No messageBox"? If an error occurs, Method2() should be called.

役に立ちましたか?

解決

I'm not sure I'm helping, but here's how you can throw an exception and take an image of the the dialog box.

[TestMethod]
    public void CodedUITestMethod1()
    {
        WinWindow window = new WinWindow();
        window.SearchProperties[WinWindow.PropertyNames.Name] = "Error Window";
        WinButton okButton = new WinButton(window);
        okButton.SearchProperties[WinButton.PropertyNames.Name] = "OK";

        try
        {
            throw new Exception("Coded UI is throwing an exception.  No idea about the Internet explorer state.");
        }
        catch(Exception ex)
        {
            Task.Run(() =>
                {
                    MessageBox.Show(ex.Message, "Error Window");
                }).Start();
            throw new Exception("An unexpected exception occurred in Coded UI",ex);
        }
        finally
        {
            Image pic = window.CaptureImage();
            pic.Save(@"C:\result.bmp");
            Mouse.Click(okButton);
        }


    }

他のヒント

The whole desktop including the wanted message box can be obtained with:

Image pic = UITestControl.Desktop.CaptureImage(); 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top