sqlnewbie
sqlnewbie

Reputation: 867

How to handle abort window in Coded UI test

I have a scenario like below:

--Green path 1) Open a form 2) give path to a file 3) run the process 4) generates output 5) sucesss messages written to a screen on the form and then 6) Close button enabled.

-- automated above workflow via Coded UI test.

--Red path 1) Open a form 2) give path to a file 3) run the process 4) doesn't generates output 5) ABORT window popped up (need to close it before Close button enabled) 6) Close enabled

However to handle above Red path case, I'm unable to use the Automated Coded UI test written for Green path, is there a way to handlde ABORT window in the Green path Coded UI test?

Thanks.

    [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));
    }

Upvotes: 0

Views: 1262

Answers (1)

stoj
stoj

Reputation: 679

Have you tried doing something like this? You will of course have to move the code out of the designer file.

   [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));
}

Upvotes: 1

Related Questions