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

Silverlight: assertion fails (what is incorrect?)

2 Answers 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
solo
Top achievements
Rank 1
solo asked on 14 Oct 2010, 07:32 PM
Hello!

I wrote simple test for silverlight sample app http://www.artoftest.com/Samples/SampleApplication.html

The code is:
           Manager.LaunchNewBrowser();
            Manager.ActiveBrowser.NavigateTo("http://www.artoftest.com/Samples/SampleApplication.html");
            Manager.ActiveBrowser.WaitUntilReady();
            System.Threading.Thread.Sleep(1000);
            
            SilverlightApp app = Manager.ActiveBrowser.SilverlightApps()[0];
            Assert.IsNotNull(app);
            TextBox name = app.Find.ByName<TextBox>("name1");
            name.User.TypeText("john", 50);
            Button okButton = app.Find.ByName<Button>("okButton");
            okButton.User.Click();
            FrameworkElement message = app.Find.ByName("message1");
            Assert.IsTrue(message.TextContent.Contains("Selected Date: <date not selected>"));

After I run the test, the assertion is failed, what is wrong in my assertion?

Also, if I set assertion Assert.IsTrue(message.TextContent.Contains("Hi john Selected Date: <date not selected>"));
it is failed, too.

How should I write the assertion to check that all this phrase ("Hi john Selected Date: <date not selected>") is displayed in the framework element?

2 Answers, 1 is accepted

Sort by
0
solo
Top achievements
Rank 1
answered on 17 Oct 2010, 06:36 AM
Any ideas???
0
Keaegan
Telerik team
answered on 29 Oct 2010, 11:24 PM
Hi solo,

Try using the following code instead:

            Manager.Settings.EnableSilverlight=true;
            Manager.LaunchNewBrowser();
            Manager.ActiveBrowser.NavigateTo("http://www.artoftest.com/Samples/SampleApplication.html");
            Manager.ActiveBrowser.WaitUntilReady();
            System.Threading.Thread.Sleep(1000);
                        
            SilverlightApp app = Manager.ActiveBrowser.SilverlightApps()[0];
            Assert.IsNotNull(app);
            TextBox name = app.Find.ByName<TextBox>("name1");
            name.User.TypeText("john", 50);
            Button okButton = app.Find.ByName<Button>("okButton");
            okButton.User.Click();
            TextBlock message = app.Find.ByName<TextBlock>("message1");
            Assert.IsTrue(message.Text.Contains("Selected Date: <date not selected>"));

After testing your provided code we saw that you did not have a couple of things present, but we were able to confirm the above code snippet as working. Your 2nd to last line was marked as a framework element instead of a TextBlock, which was causing issue with the code getting to the final line (Assertion).

Please let us know if you have furhter question on the above.

Greetings,
Keaegan
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
solo
Top achievements
Rank 1
Answers by
solo
Top achievements
Rank 1
Keaegan
Telerik team
Share this question
or