Hi all. Trying to do automated testing of our Silverlight App. They (the powers that be) insisted on creating custom Silverlight Controls, so all TextBoxes are actually e.g. MyTextBoxes: <MyTextBox x:Name="tbxCode"... etc. This was done to cover for future extentions to controls. This way they won't have to refactor controlname usages or something like that. Don't ask me... and tell me we should do it differently: I have no say in the matter.
All these custom controls are derived from the standard ones, so MyTextBox still has a Text property etc. Problem is that WebAii won't let me cast the FrameworkElement as a TextBox because the tag says MyTextBox. So silverLightApp.FindName<TextBox>("tbxCode") won't work. I'm stuck with a FrameworkElement, which does not have a Text property to get or set.
I am initially only trying to SET the text, so I sort of made peace with this because I was told to emulate user interaction as closely as possible, and I decided to do the following via FrameworkElement.User:
- Click
- KeyPress(Home)
- KeyDown(Shift)
- KeyPress(End)
- TypeText("Hello World")
So basically, select all the text and start typing, just like a human would.
For reading the text I considered doing something like selecting the text and copying it to the clipboard and read it from there in the test, but havn't even gotten to that yet.
But just trying to SET the text does not work. All the commands listed above WORK (afterwards the PC still thinks that Shift is being held down because I never call KeyUp(Shift), and when I click around in text everyting from the previous cursor position gets selected), but for some reason the text does not get selected.
I even tried KeyPress(Home), KeyDown(Shift) and then 3 x KeyPress(RightArrow). The cursor goes "home", shift is down (as is proved by my mouse afterwards) and the cursor moves 3 characters right... but doesn't SELECT anything. When it's run through I can press the arrow keys manually and then it DOES select text (thinks shift is still down).
So my questions are:
1) How can I force WebAii to cast the FrameworkElement to a TextBox... I KNOW it's a TextBox, the tag name just says something else.
2) How can I emulate holding down Shift, Control, Alt or a combination of the three and pressing other buttons (Ctrl+Home, Ctrl+Shift+End, etc)? The KeyDown, KeyPress route described above does not work... well, it works, it just doesn't DO what it should.
Thanks in advance for any help.
PS: GREAT software! This has totally saved me from UIAutomation-induced insanity. Thanks!