Automate Java Swing Application

In addition to .Net, web and mobile applications, Testmate can also automate Java swing applications. Below script uses Android studio as a sample.

The workflow starts on an already open Android Studio. It opens the Settings dialog from the File menu, performs some actions and closes it.

Any open source Object spy can be used to find object properties. Google acess bridge explorer can be a good option to spy objects.

https://www.youtube.com/watch?v=Q65qNXfirCc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'Open Settings Dialog from File Menu 
java.VirtualClick("Role::frame,Name::r|My Application.*>==>Role::menu,Name::File")
java.Click("Role::frame,Name::r|My Application.*>==>Name::Settings...")
 
'Wait for Settings To Open - Polling wait for 20 seconds
bSync = java.Exist("Role::dialog,Name::Settings",20)
 
'Validate the presence of Settings Window
If bSync  Then
   Call Logger.Pass("Step 1","Dialog is present", True)
Else
   Call Logger.Fail("Step 1","Dialog is not present", True)
End If
 
'Select Appearance node from Appearance & Behavior
Call java.SelectTreeNode("Role::dialog,Name::Settings>==>Role::tree","Name::Appearance & Behavior",0)
bSync = java.Exist("Role::dialog,Name::Settings>==>Role::combo box,Name::Theme:",20)
 
'Select DropDown Values
Call java.SelectFromCombobox("Role::dialog,Name::Settings>==>Role::combo box,Name::Theme:",1)
Call java.SelectFromCombobox("Role::dialog,Name::Settings>==>Role::combo box,Name::IDE:","Greyscale")
Call java.SelectFromCombobox("Role::dialog,Name::Settings>==>Role::combo box,Name::Editor:","Greyscale")
 
'Select Notifications tree Node
Call java.SelectTreeNode("Role::dialog,Name::Settings>==>Role::tree","Name::Appearance & Behavior",5)
bSync = java.Exist("Role::dialog,Name::Settings>==>Role::table,Visible::1",5)
 
 
'Validate the presence of notification Tables
If bSync  Then
   Call Logger.Pass("Step 1","Notifications table is present", True)
Else
   Call Logger.Fail("Step 1","Notifications table is not present", True)
End If
 
'Check the required checkboxes in the table
'Since the Table object has already been located in the host in the previous step, we don need to pass it again
Call java.ClickTableCell(2,2)
Call java.ClickTableCell(4,2)
Call java.ClickTableCell(6,2)
Call java.ClickTableCell(7,2)
Call java.ClickTableCell(8,2)
Call java.ClickTableCell(9,2)
Call java.ClickTableCell(10,2)
Call java.ClickTableCell(11,2)
Call java.ClickTableCell(12,2)
Call java.ClickTableCell(13,2)
Call java.ClickTableCell(14,2)
Call java.ClickTableCell(15,2)
Call java.ClickTableCell(16,2)
Call java.ClickTableCell(17,2)
Call java.ClickTableCell(18,2)
Call java.ClickTableCell(19,2)
 
'Clic on the Popup cell and select Balloon 
Call java.ClickTableCell(6,1)
util.Wait(100)
Call java.Click("Role::window>==>Name::Balloon")
 
 
'Click on Cancel button
'Virtyual click does not need mouse movement, but it is supported only by limited element types
Call java.VirtualClick("Role::dialog,Name::Settings>==>Role::push button,Name::Cancel")
19 Comments

Leave a Reply to Balaraj adappa Cancel reply

Your email address will not be published. Required fields are marked *