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 Select Cell in JTable - Need Example #27

Open cdmahy opened 9 years ago

cdmahy commented 9 years ago

Hello Renato,

I love your framework - it is very easy to use and has an elegant interface. Your docs say that you can select a cell in a JTable (I am using your framework with Java / JUnit). I have tried the following:

Swinger.getUserWith(dialog).doubleClickOn("text:CONTENTS OF CELL");

But the error is (when there is in fact a cell in the table with the given contents):

com.athaydes.automaton.GuiItemNotFound: Component not showing on screen: com.athaydes.automaton.FakeComponent[,0,0,0x0,invalid] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:232) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:244) at com.athaydes.automaton.SwingAutomaton.centerOf(SwingAutomaton.groovy:68) at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) ...

I have verified that the JTable component could in fact be found by your framework using its name. I tried clicking on it, and got the same error. How can I select a row in a JTable (or a cell - which would provide the same result)?

BTW - I am running on Max OS X (10.9.5) - running the code in Eclipse.

Thanks!

renatoathaydes commented 9 years ago

Hi, Thank you for your kind words.

I have a couple of tests for this that you can check out (the test also uses the "text" selector):

https://github.com/renatoathaydes/Automaton/blob/master/src/test/groovy/com/athaydes/automaton/SwingBaseForTests.groovy#L272

Not sure why it would not work for you. Try to create a Swinger on something other than the dialog maybe (something "closer" to the JTable)...

EDIT: Wait, the error says the component is not showing on the screen!! So that means the cell you're trying to click on is hidden, is that possible?? Maybe you need to click on the JTable first or scroll down a bit?

cdmahy commented 9 years ago

Thanks for the response. The cell is in fact displayed on the screen. Interesting that I can find the JTable component, but the component has a location (via getLocation()) of 0, 0. I decided to use the encompassing dialog (which only has the JTable embedded in a JScrollPane and a JButton), get its location via getLocation() and then use the following to select the row:

Point dialogLocation = dialog.getLocation(); dialogLocation.translate(300, 200); Swinger.getUserWith(dialog).moveTo(dialogLocation).doubleClick();

This works - so it is what I am using.

renatoathaydes commented 9 years ago

Oh, I see... looks like I may need to fix the location of components located in JDialogs... but the test for this passes... can you see any difference in layout between your component and my tests?

Will try to look more in depth at this issue later.

renatoathaydes commented 9 years ago

Hi @cdmahy . Can you try to up Automaton's version to 1.3.0-beta and see if you get the same problem still? Thanks.