locked
Microsoft.VisualStudio.TeamTest.UITesting?? RRS feed

  • Question

  • I am working on NUnit enhancement to support run Coded UI test cases... After load the Coded UI test assembly successfully in NUnit, I encountered null reference exception in replay Coded UI test case just like the problem illustrated in following link:

    http://oweng.net/Visual-Studio-2010/Coded-UI-Fitnesse/integrating-coded-ui-and-fitnesse-fitsharp-slim-4.aspx

    <<quoted>>

    Of course a different CUIT, targetting different an app with different technology, might require a different set. Running the Fitness test now came up with a new error, the standard 'System.NullReferenceException: Object reference not set to an instance of an object'. Was able to trace it back to the first UI interaction in the Coded UI Test, a Mouse.Click, where the HtmlInputButton control was null. Some research led to the need for initiating Playback manually in situations where one needs access to methods in Microsoft.VisualStudio.TeamTest.UITesting namespace when coding within the Coded UI framework, but not within the [TestMethod] itself.

    <<quoted>>

    What confused me is the Microsoft.VisualStudio.TeamTest.UITesting namespace, did I miss any dll or other to avoid the null reference exception in running Coded UI test case via NUnit?? 



    totta wang
    Thursday, October 28, 2010 7:20 AM

Answers

  • Thanks for your quick updates. I have figured out my problem and it wasn't related to Microsoft.VS.TT.UITesting namespace..

    The null reference exception happened in running Coded UI test case via NUnit was because some UI replay code was outside of test method and Playback.Initialize was not invoked. I did some change in my Coded UI test case and framework, now it works.

    I am still trying to understand the run difference between NUnit and MSTest.. as original code can works well without null reference exception, but i think it's not a big deal and easier to figure out.


    totta wang
    • Marked as answer by totta wang Thursday, October 28, 2010 9:14 AM
    Thursday, October 28, 2010 9:14 AM

All replies

  • let me see if I understood your question properly. Are you asking which dll contains Microsoft.VS.TT.UITesting namespace? If so, it is Microsoft.VisualStudio.TestTools.UITesting.dll. If it is something else that you are asking. please let me know.


    Please mark the post as answered if this answers your question. ThejK
    Thursday, October 28, 2010 8:49 AM
  • Thanks for your quick updates. I have figured out my problem and it wasn't related to Microsoft.VS.TT.UITesting namespace..

    The null reference exception happened in running Coded UI test case via NUnit was because some UI replay code was outside of test method and Playback.Initialize was not invoked. I did some change in my Coded UI test case and framework, now it works.

    I am still trying to understand the run difference between NUnit and MSTest.. as original code can works well without null reference exception, but i think it's not a big deal and easier to figure out.


    totta wang
    • Marked as answer by totta wang Thursday, October 28, 2010 9:14 AM
    Thursday, October 28, 2010 9:14 AM
  • Totta,

    Merry Chirstmas and Happy New Year!

    You may have the answer to what I'm running into.  We want to avoid using the recorder as we can hand-code much simpler ourselves.  We got some hand coded TestMethods to work within a solution originally made as a full Coded UI Test.  Being ecstatic we decided to copy this code into a fresh solution and do it ourselves.  We got the null exception you've hit.

    When you solved the issue, exactly what code did you use?  Can you put in exactly what you did as I'm having a hard time figuring out how to modify my code?

    Here is what works within the original solution but is not working in a fresh non-coded UI solution.  Note, all the references, using directives, etc. needed are present in our new file.  The [CodedUITest] and [TestMethod] attributes exist, etc.

    BrowserWindow

     

    win = BrowserWindow.Launch("url removed before posting");

     

    //Refreshes Browser Window to make sure sidebar js runs fully

     

    //Reopens Options Sidebar

     

    //OpenOptionsMenu(win);

    win.Refresh();

     

    HtmlImage image_options = new HtmlImage(win.CurrentDocumentWindow);

     

    HtmlImage.PropertyNames.Id] = "img_options";

     

    Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly; <-- We tried several different things to see if it was just a "wait" issue.  it isn't.  I think you've got the answer.

     

    Mouse.Click(image_options); <-- The null exception happens right here.  It is the Mouse.Click that is null, not (image_options).

    Totta, it would be great to see exactly how you solved this.  The structure of the solution I have is just the one file that holds this code.  How did you implement your code to handle this?

    Thanks,

    Mike


    Michael Durthaler

     

     

    image_options.SearchProperties[

     

    • Edited by SACSgtMike Friday, December 17, 2010 4:08 PM removed customer url
    Friday, December 17, 2010 3:58 PM
  • Here is the workaround I'm doing to resolve this pesky and non-sensical Null exception.

    After trying wait for control ready actions, etc. here's what I did, which is from a blog on how to create a containing test for other tests:

    1. Create a Test Proect Solution
    2. Delete the default UnitTest1.cs file (I just do this if I'm never going to use it)
    3. Add a new Coded UI Test to the project
    4. Accept the defaults
    5. When the recorder runs up, don't record any actions anywhere, just generate the code
    6. Close out the recorder
    7. Copy in your hand-written code and it will work whereas with all references, using directives, etc. Mouse.Click actions were themselves Null.

    My guess is there's an entry in the .csproj file for a CodedUITest that doesn't exist in a regular solution .csproj file.  I would resolve this fully by comparing the 2 different .csproj files between any working and non-working solutions and something should jump out at you.

    But until then ... do the above and it will work.

    Mike


    Michael Durthaler
    • Proposed as answer by SACSgtMike Friday, December 17, 2010 4:27 PM
    Friday, December 17, 2010 4:27 PM