0

The application is running and the window of the application is visible on the screen, but the coded ui test always gets a NullReferenceException:

  • sampling = application
  • sampling.Window = main window of the application

Code:

if(object.ReferenceEquals(sampling, null)) // sampling is not a null reference (debug output)
if(sampling == null) //  sampling is not null
if(object.ReferenceEquals(sampling.Window, null)) //  sampling.Window is not a null reference
if(sampling.Window == null) //  sampling.Window is not null
if (sampling.Window.Exists) //  sampling.Window exists? True
if(sampling.Window.TryGetClickablePoint(out pt)) //  Got clickable point? False  Point = {X=0,Y=0}

if(object.ReferenceEquals(sampling.Window.BoundingRectangle, null)) //  Exception: object reference not set to an instance of an object.
if(object.ReferenceEquals(sampling.Window.ControlType, null)) //  Exception: object reference not set to an instance of an object.
if(object.ReferenceEquals(sampling.Window.Name, null)) //  Exception: object reference not set to an instance of an object.
if(object.ReferenceEquals(sampling.Window.ClassName, null)) //  Exception: object reference not set to an instance of an object.
if(sampling.Window.BoundingRectangle == null) //   Exception: object reference not set to an instance of an object.
if(sampling.Window.ControlType == null) //   Exception: object reference not set to an instance of an object.
if(sampling.Window.Name == null) //   Exception: object reference not set to an instance of an object.
if(sampling.Window.ClassName == null) //   Exception: object reference not set to an instance of an object.
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • You need to format your question better. Code should be formatted, exception stacks should be block quotes. You should also tag the question with what language you're using. – mason Jul 10 '14 at 14:18
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jul 10 '14 at 14:20

1 Answers1

0

If sampling.Window itself is not null, yet stuff like sampling.Window.Name == null leads to a NullReferenceException, I suspect the exception comes from inside the get accessor of the property Name.

Have you compiled this without optimizations (in "Debug" mode) and tried running it with the debugger of Visual Studio attached? It should halt execution when the exception occurs, and you should be able to see just which reference is null. It might be in the line just above the line Visual Studio highlights with a color.

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
  • Yes, I have compiled it in "debug" mode and debugged it several times . The problem is that there is no null reference. The problem seems to be the launsching of the application: root = ApplicationUnderTest.Launch(Settings.Default.SamplingAppUrl); The properties of root (ApplicationUnderTest object) e.g. HasTitleBar, Maximized etc. all throw a NullReferenceException. – user3801450 Jul 11 '14 at 13:06