April 19, 2020
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.
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") |
21 Comments
How do we launch an application , inorder to automate a swing application from scratch
Please let me know once you have found an answer, I also have the same question.
There are several ways to launch an application in Vbscript.
like:
Set objShell = WScript.CreateObject( “WScript.Shell” )
objShell.Run(“””C:\Program Files (x86)\..\AppName.exe”””)
You can also use
Call util.StartApp(“C:\Program Files (x86)\..\AppName.exe”)
Also See https://stackoverflow.com/questions/28379207/launch-program-from-vbscript
how to find java swing element without name?
java.Exist(“Role::panel,Index::2).
is this possible??
Yes, It is possible. Using name is not mandatory.
You can use any property or set of properties that makes it unique .
thank you..
can we automate java applet usin TestMate?
Currently it supports only Java Swing Applications.
Is Testmate open-source?
Free. Not open source.
I absolutely love this program, I just have one question, is it safe from this new Log4j vulnerability?
Yes
Does the java here have some methods such as java.activate(window_name)? I found the testmate works well on every single java page, but failed when jumping from one dialog to another dialog(all the windows or dialogs are within the same application.)
You can Activate the windows using uia.SetFocus() method (For java Applications, this method works on the topmost windows, not the internal elements).
Do let me know if that works for you, or share some sample(With application) scenario and we can try to make it work for you.
Hi,
Thanks for the youyube video demo.
Can Testmate interact with JWS (jnlp) desktop app?
Can the Swing explorer identify elements from JWS (jnlp) desktop app?
Yes!
I saw your reply on Youtube.
Hi, for my application, the components are under a frame. they are visible, can be clicked on manually, but when I try to find it from the Access Bridge Explorer I can only see the frame and few child objects but not the object I am trying to find.
That’s interesting. It may be using some non Swing components.
For Swing applications it should work.
Hi, I’m getting “object reference not set to an instance of an object” when I run the sample click code. Is there any solution for this?
The prerequisite is Android studio must be open before running the sample code.
The objects may have changed. Try to find it first.