The following example shows how to write an automation script for the Windows calculator. 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.
Note: This exercise reflects the values for the calculator on the Win7 operating system. Values on the XP operating system may differ. |
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.Open the Windows calculator.
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 Calculator application. Then, at the bottom of the dialog, click Add.
The Calculator application is added to the Repository.
6.From the Repository pane, right-click on the Calculator application, and select Add Standard 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 Calculator 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.
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.
this.WindowOpened += Service_WindowOpened; |
13.Write an if statement within the WindowOpened event handler, to identify that the window opened is that of Calc.
Within the if statement, you can instantiate a Calc window instance. Instantiation of the window object is performed by casting the sender parameter, passed as an event argument.
void Service_WindowOpened(object sender, EventArgs e) { if (sender is Calc) { Calc calc = sender as Calc; } } |
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 Calc) { Calc calc = sender as Calc; calc.oneButton.Click(); calc.plusButton.Click(); calc.oneButton.Click(); calc.equalsButton.Click(); string result = calc.resultWindow.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.Forms
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 Windows calculator, the automation is performed as soon as the Calculator window is open. The result of the operation is displayed in the Message Box.