The following example shows how to write an automation script for the A Swing calculator (http://sourceforge.net/projects/simpcalc/?source=typ_redirect)
The following components are captured, and their IDs are saved to the Repository:
•1 button
•+ button
•= button
•Results field
A script is then written (using the objects auto-generated for the controls by JIA) to perform the following operation: 1+1=2.
To automate the operation 1 + 1 = 2:
1.Create a new JIA project (Starting a New JIA Project).
2.Open the Repository Builder tool.
3.Run the Calculator Java application (using injection).
4.At the upper left corner of the Repository Builder, select Add > Application.
The Add Application dialog opens.
5.From the list in the dialog, select the Simple Calculator application. Then, at the bottom of the dialog, click Add.
The Java application is added to the Repository.
6.From the Repository pane, right-click on the Simple Calculator application, and select Add Java Control.
The Repository Builder main window is hidden, and the capture tool opens.
7.From the capture tool, click . While still holding the left mouse button down, drag the mouse pointer over the application until the 1 button is indicated by a blue frame. Then, release the mouse button.
The Add Control dialog opens, displaying a preview of the captured control.
8.At the bottom of the dialog, click Add.
9.Capture and add the + button, the = button, and the Results textbox, using the technique described in Steps 7 and 8.
Be sure to provide appropriate programmatic Ids.
10.From the capture tool, click .
The Repository Builder main window is displayed.
11.At the upper left corner of the Repository Builder, click .
The Repository is saved.
12.From the Solution Explorer view, double-click Service.cs. In the project template, a registration to the WindowOpened event is already written within the Init function.
13.Write an if statement within the WindowOpened event handler, to identify that the window opened is that of SimpleCalculator.
Within the if statement, you can instantiate a SimpleCalculator window instance: Instantiation of the window object is performed by casting the sender parameter, passed as an event argument.
this.WindowOpened += Service_WindowOpened; void Service_WindowOpened(object sender, EventArgs e) { if (sender is SimpleCalculator) { SimpleCalculator calc = sender as SimpleCalculator; } |
14.Within the if statement, write the code that is going to perform the calculation, and store the result within a local string variable (result).
if (sender is SimpleCalculator) { SimpleCalculator calc = sender as SimpleCalculator; calc.OneButton.Click(); calc.PlusButton.Click(); calc.OneButton.Click(); calc.EqualsButton.Click(); string result = calc.ResultsTextBox.Text; } |
15.Check the code by displaying the result variable in a Message Box:
Add a using statement to include windows form, using System.Windows.Form
Add a MessageBox to display the result:
MessageBox.Show(result); |
16.To run the solution in VS2013, press F5.
Once the project is running, JIA is already listening to events on the desktop. At this point, when you launch the A Swing calculator, the automation is performed as soon as the main Calculator window is open. The result of the operation is displayed in the Message Box.