Search code examples
visual-studio-2010coded-ui-tests

How to retrive the data displayed in Message box for Coded Ui testing


Scenario: After clicking on the submit button,a message box appears with the ticket number. I want to save the ticket number to a string parameter for future purposes. Is it possible in Coded Ui?


Solution

  • Use the Assertion tool to select the textbox and name it "CaptureText()" (Do this to use the tool to capture the object). Once you've done this, transfer the code from the UIMap Designer File to the Coded File. Inside your Coded UIMap File you should see something like this:

    public void CaptureText()
    {
    HtmlCustom uIItemCustom = this.Window.Foo.Bar.UIItem;
    //Comment this out
    //Assert.IsNull(uIItemCustom); 
    //Change it to
    var foo = uIItemCustom.InnerText;
    }
    

    Now the 'foo' variable contains the value of the label / textbox.