Here is an example of using automation to simulate a button click pulled straight from the book...
aWindow = New MainWindow aWindow.Show() Dim BAutomationPeer As New Automation.Peers.ButtonAutomationPeer(aWindow.Button1) Dim InvProvider As IInvokeProvider InvProvider = BAutomationPeer.GetPattern(PatternInterface.Invoke) InvProvider.Invoke()
Four lines of code to simulate a click? Why is that better than...
aWindow = New MainWindow aWindow.Show() aWindow.Button1.RaiseEvent(New RoutedEventArgs(Button.ClickEvent, Button1))
I'm pretty sure I can simulate any event I want to with the RaiseEvent method.
Also the book example creates the window to be tested from the testing window. This has got to be a bad pattern. Surely the testing window should find an already instantiated window and obtain a reference to it. Perhaps something like...
I rather like the idea of having an icon on a page that has test scripts (hidden to regular users) that opens a page of test scripts and passes the page as a reference to the test page. Then the tester could easily perform standard tests. The scripts should also include tests of the results too. For example a script that tests the creation of a balanced purchase order would test the net amount is zero after the purchase order is entered.Dim aWindow as MainWindow = Application.Current.MainWindow aWindow.Button1.RaiseEvent(New RoutedEventArgs(Button.ClickEvent, Button1))
What is it about Automation I am missing? The book doesn't explain.
No comments:
Post a Comment