views:

151

answers:

2

Hi,

I am using the white automation API to test a silverlight app, but when an unhandled exception occurs in silverlight I don't know of a way to report this back to the unit test or check in the white api to see if there was an exception. Anyone got a way to do this?

A: 

I am not familiar with the white test framework, but you can probably do something like the following in your test:

[Test]
public void MyTest()
{
    bool unhandledExceptionFired = false;
    Application.Current.UnhandledException += (s,e) => unhandledExceptionFired = true;

    //test code....


    Assert.IsFalse(unhandledExceptionFired);
}

Like I said, I have not used the particular test framework mentioned, but something like this should work. Or are you running into some problem that prevents this from working?

KeithMahoney
Thanks for the suggestion, but this won't work as I am not working directly with the silverlight app - it is being automated - basically this simulates user interaction on the app ie button clicks, enter text etc so it is external to the app - this is a functional test framework, along the lines of selenium for web apps. I can see the IE 'error on page' warning so I know the exception is fired in the app but it doesn't get reported in the white api (or I can't find a way to get to it anyway).
Trystan
A: 

The IE 'error on page' warning is a GUI element, so you should be able to check for it via the white api. Locate the IE status bar, query it for the status message, and if the message == 'error on page', then log an error in your test. Sample code below for inspecting the text on the status bar.

app = Application.Attach(Process.GetProcessesByName('iexplore')[0])
win = app.GetWindows()[0]
statusBar = win.Get(SearchCriteria.ByAutomationId('StatusBar'))
for item in statusBar.Items:
    print item.Id, String.Format("'{0}'", item.Text)

output

StatusBar.Pane0 'Done'
StatusBar.Pane1 '' 
StatusBar.Pane2 ''
StatusBar.Pane3 '' 
StatusBar.Pane4 ''
StatusBar.Pane5 '' 
StatusBar.Pane6 ''
StatusBar.Pane7 'Internet'
Tom E