문제

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