views:

1591

answers:

2

I'm currently using the WebAii automation framework to write some user interface tests against a Silverlight 3 application. I'm new to Silverlight and suspect that I'm missing some bit of information about the HyperlinkButton.

The application has a HyperlinkButton and I'm attempting to write code that navigates to the page, finds the button the page, then "clicks" that button (which will then navigate to the NavigateUri as specified in the HyperlinkButton's properties).

I can't figure out how to execute that click. The code I have thus far (simplified):

Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://server/appname/");
var slApp = ActiveBrowser.SilverlightApps()[0];
var menu = slApp.FindName<StackPanel>("LinksStackPanel");
var linkicareabout = menu.Find.ByName<HyperlinkButton>("Some Cases");

I'd expect to see some sort of Click() action, or Navigate() method that I could invoke on the "linkicareabout" variable, but I must be missing how it's done.

A: 

I was unable to do this myself and instead, had to write my own navigation code. For Firefox and IE, you can just use HtmlPage.Window.Navigate to navigate to the desired URL.

However, Safari and Chrome need some extra work. I had to use hidden HTML components and some javascript interops.

This workaround is detailed here.

Basically, it entails adding a hidden anchor and button to the HTML page containing your Silverlight control, and then modifying the anchor and clicking the button via calls to the DOM.

 HtmlElement anchor = HtmlPage.Document.GetElementById("externalAnchor");
 HtmlElement button = HtmlPage.Document.GetElementById("externalButton");
 if ((anchor != null) && (button != null))
 {
     anchor.SetProperty("href", url);
     button.Invoke("click", null);
 }
Jeff Yates
+2  A: 

What you are looking for is the User object off the HyperlinkButton. All controls that WebAii comes with have that object. This way you can invoke any user action on any control type.

linkicareabout.User.Click()

The User object supports any user action you can think of and mimic real user interactions. Check out the documention here.

Faris