This is a migrated thread and some comments may be shown as answers.

Find method: Object reference not set to an instance of an object

7 Answers 359 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andrey Cherepakha
Top achievements
Rank 1
Andrey Cherepakha asked on 13 Apr 2010, 04:01 PM

Hello!
I am new in WebAii and, to be honest, I am new in C# programming.


I try creating my own project or using a sampler (SilverlightHealthcareSample.cs). I have an error with message:

 

Test method QuickStarts_VSTS_CS.SilverlightHealthcareSample.HealthCareDemo threw exception:  System.NullReferenceException: Object reference not set to an instance of an object..

 

at ArtOfTest.Common.TreeCrawler`3.SearchUsingNonHierarchialMatch(ITargetElement startNode, IList`1 clauses, V expression, Boolean ignoreConstraints)

at ArtOfTest.Common.TreeCrawler`3.Find(T startNode, IList`1 clauses, V expression, Boolean includeRoot, Boolean ignoreContraints)

at ArtOfTest.Common.TreeCrawler`3.ByExpression(T startNode, V expression, Boolean includeRoot)

at ArtOfTest.Common.TreeCrawler`3.ByExpression(V expression)

at ArtOfTest.WebAii.Silverlight.VisualFind.ByName(String name)

at ArtOfTest.WebAii.Silverlight.SilverlightApp.FindName(String name)

at QuickStarts_VSTS_CS.SilverlightHealthcareSample.HealthCareDemo() in C:\..\UnitTest1.cs:line 155

 

Error is occurred when I try to use any Find method.

 

My code (only interesting lines, actually it is all from the sampler):

 

[TestInitialize()]

public void MyTestInitialize()

{

Settings settings = GetSettings();

settings.EnableSilverlight = true;

Initialize(settings, new TestContextWriteLine(this.TestContext.WriteLine));

SetTestMethod(this, (string)TestContext.Properties["TestName"]);

}

 

[TestMethod]

[Description("Automate a complex Silverlight application")]

public void HealthCareDemo()

{

Manager.Settings.ExecutionDelay = 10;

Manager.LaunchNewBrowser(BrowserType.InternetExplorer);

System.Drawing.Point loc = ActiveBrowser.Window.Location;

ActiveBrowser.NavigateTo("http://www.mscui.net/PatientJourneyDemonstrator/PrimaryCareAdmin.htm");

ActiveBrowser.Window.Move(new System.Drawing.Rectangle(loc, new System.Drawing.Size(1024, 768)), true);

 

//SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

// I have an error on the line above, but with line below works fine

SilverlightApp app = ActiveBrowser.SilverlightApps().First();

 

app.FindName("guideButton").User.Click(); // <= I have the error there

}

 

Also I tried to use construction like this:

            TextBox name1 = app.Find.ByName<TextBox>("name1");

            FrameworkElement ss = app.Find.ByName("name1");


I have the same error.

 

I tried to run that code with the latest version of WebAii 2.0 from ArtOfTest site. After that I uninstalled WebAii and installed WebAii (Testing Framework 2010.1.412.FREE_EDITION) from Telerik site. But the error is still present.

 

Could you please give me an advice to solve the issue? May be something wrong with my environment?

 

MS Win XP Professional SP 3 English

Visual Studio 2008

IE 8.0.6001.18702

MS Silverlight 3.0.50106.0 (add-ons is enabled in IE)

WebAii Test Execution Extension 2.0.50727.3053 (add-ons is enabled in IE)

Thanks for your attention.

7 Answers, 1 is accepted

Sort by
0
Missing User
answered on 13 Apr 2010, 09:02 PM
Hi Andrey,

Thanks for the post and trying out the WebAii Framework.

I tried your test code as is and did get the error. But it works for me with the line enabled:

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

Please try clearing out the test playback browser cache:

-  In IE select: Tools -> Internet Options -> (Under General Tab) Delete -> Choose to delete Temporary Internet Files
- In  Firefox select: Tools -> Clear Recent History -> Select Everything in ‘Time Range to Clear’ drop down menu -> Choose to delete Cache
- In Safari select: Main ToolBar Drop Down Menu -> Reset Safari… -> Choose to ‘Empty the cache’

Also, please try increasing the Settings.SilverlightConnectTimeout to a larger integer.

Greetings,
Nelson Sin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andrey Cherepakha
Top achievements
Rank 1
answered on 14 Apr 2010, 08:07 AM

Hello, Nelson.

Thanks for your answer.

I have cleared out the browser cache with IE menu and manually (deleted all in Temporary Internet Files\Content.IE5).

 

I  increased the settings.SilverlightConnectTimeout value up to 5000000.

 

Also I use

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

 

And I have an error with this definition.

 

Error message:

 Test method Test3.UnitTest1.TestMethod1 threw exception:  ArtOfTest.WebAii.Silverlight.ApplicationNotReadyException: Error checking HTML access on Silverlight app --->  ArtOfTest.WebAii.Exceptions.ExecuteCommandException: ExecuteCommand failed!

InError set by the client. Client Error:

System.InvalidCastException: Specified cast is not valid.

   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)

   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)

   at ArtOfTest.InternetExplorer.IECommandProcessor.InvokeFunction(String functionCall, Boolean useEval, Boolean returnJSON)

   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessActionCommands(BrowserCommand request)

   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessCommand(WebBrowserClass ieInstance, BrowserCommand request, IHTMLDocument2 document)

BrowserCommand (Type:'Action',Info:'NotSet',Action:'InvokeJsFunction',Target:'ElementId (tagName: '',occurrenceIndex: '-1')',Data:'document.getElementsByTagName(\'object\')[0].settings.enableHtmlAccess',ClientId:'Client_9703c15c-f99a-4fec-b814-dacfbb0fe439',HasFrames:'False',FramesInfo:'',TargetFrameIndex:'-1',InError:'True',Response:'System.InvalidCastException: Specified cast is not valid.

   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)

   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)

   at ArtOfTest.InternetExplorer.IECommandProcessor.InvokeFunction(String functionCall, Boolean useEval, Boolean returnJSON)

   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessActionCommands(BrowserCommand request)

   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessCommand(WebBrowserClass ieInstance, BrowserCommand request, IHTMLDocument2 document)')

InnerException: none.

.

 Stack trace

 at ArtOfTest.WebAii.Core.Browser.ExecuteCommandInternal(BrowserCommand request)

   at ArtOfTest.WebAii.Core.Browser.ExecuteCommand(BrowserCommand request, Boolean performDomRefresh, Boolean waitUntilReady)

   at ArtOfTest.WebAii.Core.Browser.ExecuteCommand(BrowserCommand request)

   at ArtOfTest.WebAii.Core.Actions.InvokeScript(String script)

   at ArtOfTest.WebAii.BrowserSpecialized.InternetExplorer.InternetExplorerActions.InvokeScript(String script)

   at ArtOfTest.WebAii.Controls.HtmlControls.HtmlControl.GetValue[T](String propertyName, T defaultValue)

   at ArtOfTest.WebAii.Controls.HtmlControls.HtmlControl.GetValue[T](String propertyName)

   at ArtOfTest.WebAii.Silverlight.SilverlightAppSettings.GetValue[T](String propertyName)

   at ArtOfTest.WebAii.Silverlight.SilverlightAppSettings.get_EnableHtmlAccess()

   at ArtOfTest.WebAii.Silverlight.SilverlightApp.Connect(Int32 timeout)

 --- End of inner exception stack trace ---

    at ArtOfTest.WebAii.Silverlight.SilverlightApp.Connect(Int32 timeout)

   at ArtOfTest.WebAii.Silverlight.SilverlightApp.Connect()

   at ArtOfTest.WebAii.Silverlight.SilverlightAppsList.get_Item(Int32 index)

   at Test3.UnitTest1.TestMethod1() in C:\...\UnitTest1.cs:line 100

 

I would be obliged to you for any help.

 

Thanks.

0
Missing User
answered on 14 Apr 2010, 09:05 PM
Hello again Andrey,

Thanks for trying that. Unfortunately, I can not reproduce the problem you are having with the code you posted.

From the error, it looks like the problem is on this line?:

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

And is the default sample HealthCareDemo() test method (mostly) working for you as is without any modification?

Just to make sure, the test project is located in the Telerik Start Menu Shortcut under:

Telerik -> WebAii Testing Framework -> Samples -> WebAii Framework -> VSTS C#

Quick Edit: There are some other Silverlight examples you can try to see if they work better for you:

Telerik -> WebAii Testing Framework -> Samples -> RadControls Wrappers -> Silveright

Best wishes,
Nelson
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andrey Cherepakha
Top achievements
Rank 1
answered on 17 Apr 2010, 05:42 PM

Hello, Nelson.

Thanks for your answer, and sorry for delay.
Unfortunatelly, I cannot try your suggestion right now. I am afraid I can give it a try after about a week. I will inform about my result.

0
Konstantin Petkov
Telerik team
answered on 19 Apr 2010, 07:53 AM
Hello Andrey,

Sure, please take your time. If something else pops up meanwhile, please let us know.

Greetings,
Konstantin Petkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Accepted
Andrey Cherepakha
Top achievements
Rank 1
answered on 06 May 2010, 05:48 PM

So, I have at last solved the issue.

First of all, I have reinstalled operation system on my computer. I am afraid something wrong was with it.

I used the code from samples. It works fine for “www.mscui.net”:

Manager.Settings.ExecutionDelay = 10;

Manager.LaunchNewBrowser(BrowserType.InternetExplorer);

ActiveBrowser.NavigateTo("http://www.mscui.net/PatientJourneyDemonstrator/PrimaryCareAdmin.htm");

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

But it does not work for my Silverlight application. I have investigated the difference between html content of PrimaryCareAdmin.htm and My.html.

I have found out that my SL application is put into a frame. Something like that:

 <body <iframe id="CommandConsole"></iframe>

 </body>

I use following code and everything is OK:

Manager.Settings.ExecutionDelay = 10;

Manager.LaunchNewBrowser(BrowserType.InternetExplorer);

var browser = Manager.ActiveBrowser;

browser.NavigateTo("http://link.com/my.html");

browser.AutoDomRefresh = true;

browser.RefreshDomTree();

Browser silverFrame = browser.Frames.ById("CommandConsole");

SilverlightApp app = silverFrame.SilverlightApps()[0];

Thanks

0
Cody
Telerik team
answered on 07 May 2010, 02:48 PM
Hi Andrey Cherepakha,

Thank you very much for getting back to us and especially posting your solution. Looking it over it looks to me to be the best approach as well. Well done!

Sincerely yours,
Cody
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Andrey Cherepakha
Top achievements
Rank 1
Answers by
Missing User
Andrey Cherepakha
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Cody
Telerik team
Share this question
or