如何在Coded UI测试中处理中止窗口

时间:2011-12-25 21:46:26

标签: c# visual-studio-2010 coded-ui-tests

我的情况如下:

- 绿色道路 1)打开表格 2)给出文件的路径 3)运行过程 4)生成输出 5)成功将消息写入表单上的屏幕然后 6)启用关闭按钮。

- 通过编码的UI测试自动化上述工作流程。

- 红色路径 1)打开表格 2)给出文件的路径 3)运行过程 4)不产生输出 5)弹出ABORT窗口(需要在关闭按钮启用前关闭它) 6)关闭启用

但是要处理上面的红色路径情况,我无法使用为绿色路径编写的自动编码UI测试,有没有办法在绿色路径编码UI测试中处理ABORT窗口?

感谢。

    [TestMethod]
    public void CodedUITestMethod1()
    {
        //my green path recording.
        this.UIMap.GreenPathCode();

        //my red path recodring.
        this.UIMap.RedPathCode();
    }


    public void GreenPathCode()
    {
        #region Variable Declarations
        WinEdit uITextBox1Edit = this.UIForm1Window.UITextBox1Window.UITextBox1Edit;
        WinButton uIButton1Button = this.UIForm1Window.UIButton1Window.UIButton1Button;
        WinButton uIButton2Button = this.UIForm1Window.UIButton2Window.UIButton2Button;
        #endregion

        // Type '1' in 'textBox1' text box
        uITextBox1Edit.Text = this.GreenPathCodeParams.UITextBox1EditText;

        // Click 'button1' button
        Mouse.Click(uIButton1Button, new Point(21, 10));

        // Click 'button2' button
        Mouse.Click(uIButton2Button, new Point(35, 8));
    }


    public void RedPathCode()
    {
        #region Variable Declarations
        WinEdit uITextBox1Edit = this.UIForm1Window.UITextBox1Window.UITextBox1Edit;
        WinButton uIButton1Button = this.UIForm1Window.UIButton1Window.UIButton1Button;
        WinButton uIAbortButton = this.UIErrorWindow.UIAbortWindow.UIAbortButton;
        WinButton uIButton2Button = this.UIForm1Window.UIButton2Window.UIButton2Button;
        #endregion

        // Type '2' in 'textBox1' text box
        uITextBox1Edit.Text = this.RedPathCodeParams.UITextBox1EditText;

        // Click 'button1' button
        Mouse.Click(uIButton1Button, new Point(35, 10));

        // Click '&Abort' button
        Mouse.Click(uIAbortButton, new Point(51, 12));

        // Click 'button2' button
        Mouse.Click(uIButton2Button, new Point(56, 16));
    }

1 个答案:

答案 0 :(得分:1)

你试过这样的事吗?您当然必须将代码移出设计器文件。

   [TestMethod]
public void CodedUITestMethod1()
{
    this.UIMap.RedPathCodeParams.UITextBox1EditText="1";
    this.UIMap.RedAndGreenPath();

    this.UIMap.RedPathCodeParams.UITextBox1EditText="2"
    this.UIMap.RedAndGreenPath();
}
 public void RedAndGreenPaths()
{
    #region Variable Declarations
    WinEdit uITextBox1Edit = this.UIForm1Window.UITextBox1Window.UITextBox1Edit;
    WinButton uIButton1Button = this.UIForm1Window.UIButton1Window.UIButton1Button;
    WinButton uIAbortButton = this.UIErrorWindow.UIAbortWindow.UIAbortButton;
    WinButton uIButton2Button = this.UIForm1Window.UIButton2Window.UIButton2Button;
    #endregion

    // Type '2' in 'textBox1' text box
    uITextBox1Edit.Text = this.RedPathCodeParams.UITextBox1EditText;

    // Click 'button1' button
    Mouse.Click(uIButton1Button, new Point(35, 10));

    // Click '&Abort' button
    if(this.RedPathCodeParams.UITextBox1EditText=="2") //You could also use uIAbortButton.Exists instead
    Mouse.Click(uIAbortButton, new Point(51, 12));

    // Click 'button2' button
    Mouse.Click(uIButton2Button, new Point(56, 16));
}