renatoathaydes / Automaton

Simple framework which allows the testing of Swing and JavaFX2 applications.
Apache License 2.0
100 stars 21 forks source link

how to use another window in groovy script? #55

Closed x1nas closed 7 years ago

x1nas commented 7 years ago

I use manual to run groovy script from command line. First window of my-app.jar - login window. After login another window opens. How to catch and use another window?

x1nas commented 7 years ago

Found this solution:

import com.athaydes.automaton.Swinger;
import java.awt.Window;
swinger = Swinger.getUserWith( Window.windows[1] );
swinger.clickOn( "text:OK" )
renatoathaydes commented 7 years ago

Swinger.forSwingWindow() should do the same.

x1nas commented 7 years ago

Swinger.forSwingWindow() should do the same.

Doesn't work for me:

AScript failed due to com.athaydes.automaton.GuiItemNotFound: Component not showing on screen:

renatoathaydes commented 7 years ago

Swinger.forSwingWindow() takes the first window available... in your example, you take the second one, so that explains why my suggestion didn't work..

If you have more than one windows, you should select the right window.. .Try to find it by name to make your test more reliable. Example:

myAppWindow = Window.windows.find { it.name == 'My App' }
if (!myAppWindow) throw new Exception("Could not find my window")