Search code examples
visual-studiocsvcoded-ui-testsdata-entry

Coded UI test failing in Visual Studio 2013 when entering a blank value from a csv into a WPF data grid


I am running a coded ui test in Visual Studio 2013 into a WPF data grid using values from a csv file. When I have a blank value in the csv file eg ,, it is working fine for input fields but when it comes to entering the empty string into a field on the data grid the coded ui test fails with the following error:

An exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualStudio.TestTools.UITesting.dll but was not handled in user code Additional information: Value cannot be null.

When I run the test manually I can submit the form without this value so I know it is not mandatory on the UI, the code just seems to be falling over if a value is not sent. If I enter a value on the csv the test will run but I deliberately want the field to be empty.

Has anyone come across this problem before and if so is there a way I could either adapt the csv or the code to get this to work? I have also tried ,"", and this did not work either.

Thanks


Solution

  • I think the way you're doing it (using the isNullOrWhiteSpace method to determine if you should skip entering the value) is the right way. If you don't want to write that each time you're entering values into the field, you could write an extension method instead:

    public static void EnterValue(UITestControl control, string inputString)
    {
        if (!String.IsNullOrWhiteSpace(inputString)
            Keyboard.SendKeys(control, inputString);
    }
    

    And then just call that when you want to enter text:

    string csvValue = /*value from the .csv file*/
    StaticUtilityClass.EnterValue(myControl, csvValue);
    

    Not a ground breaking change, but it would cut down on the number of times you have to write that if-statement.