-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AssertJ not clicking boxes - Java 11 #229
Comments
Related to #226. It seems that |
Thanks for reporting this issue. Currently there is no advice but I also didn't have time to analyze the framework state against Java 11. Any help will be appreciated ;) Since this is not the only issue open for Java 11, AssertJ Swing seems to be not ready for Java 11. |
Can you give some information of your environment to find out the differences to #226 |
Using MacOs Mojave, Java 11, Gradle 4.2 build, latest assertj-swing-junit 3.8.0 and assertj-core 2.9.1 |
Seeing similar issues using JDK1.8.0_192. The issue appears to be the movement of the mouse to a point within the Button/radio/---. With radio button doing a focus() first and then the click(), resolved the issued. However, tried focus() on the OK button of a dialog, doesn't resolve. This issue maybe one of:
I've changed the version of JDK used (back to JDK1.8.0_171) and still had the issue. So I'd suspect 2). But this maybe caused by assertj-swing being built against and old JDK and compatible to JDK 8 assumed. At one time I tripped across a JDK 8 change/update that stopped backward compatibility. But OpenJDK and Oracle JDK are unresponsive to issues and appear not to care (the bane of open-source). |
In follow up. Used the latest assertj-swing source code and compiled within a Netbeans 8.2 environment. thus, compiled against JDK1.8.0_192. Same issue persists. However, observing the tests which have click, the mouse is consistently not on the object when the pressMouse happens. So tried debug, guest what, under debug with breakpoints no issues. Based on previous experience this tells me that a mouse-position/move is not completing prior to the pressMouse event. (assetj-swing code BasicRobot.java-> doClickWhileModifiersPressed) `String selectionPathStr = "test1svn/cvs_testbed"; above has consistent failure conditions, all but intermittent String selectionPathStr = "test1svn/cvs_testbed"; // pre-position the mouse pointer this.winFixT0.dirTreeF.selectPath(selectionPathStr);` Pre-position the mouse on the component, and then Thread.yield(); works all the time. This suggests that the position mouse for a click() does not complete correctly. This appears to be either:
Note: I run a MSI PE70 laptop with 1+2 monitor with Win10-home. IDE is Netbeans 8.2 and tests are using TestNG framework and run all tests sequentially. In an attempt to isolate issue I've done the following (without the explicit moveMouse workaround:
In closing (for now):
|
Found a work-around for my stuff. The issue is a moveMouse or mouse-location dependent Fixture action (eg. click()) is not positioned correctly for the actual click dispatch-event. Its as if the move_mouse/cursor/pointer is being dropped from the event list for AWT.Robot. I don't have the knowledge to go further. Below is a work-around.
I'm unable to test for JDK 11 but with JDK1.8.0_192 this removed stupid failures nicely and my app testing works smoothly, other than expect graphic rendering difference between Win7 to Win10. Code below package org.assertj.swing.core; RobotEventGenerator |
Decided to look for movemouse issues for AWT robot. Appears there are a number of them (eg. https://bugs.openjdk.java.net/browse/JDK-8186063). So the problem is for Windows 10 OS and scaled screen which does not apply to OP'ers MacOS. However, my Windows 10 environment is set at 100% scale, so should not have had this problem, but I did. The work around above [other comment] is an appropriate approach to the problem. And in my case resolves the issue. I don't have MacOS access so unable to confirm. My Linux environment does not have this issue, and the work around does no harm. (Linux is virtualbox Opensuse XFCE). Summary from reports
Hopefully this is helpful. |
I'm experiencing testing failures in Windows 10 as well, while it works perfectly fine in Linux. From my findings:
Thus, it seems to work with JDK 11.0.2. I don't know if my findings make sense in this bug or they are unrelated, but the symptoms look similar. |
I'd say the issue you are having is the same as I found on Win10. I rebuilt a special assertj-swing with the following method replaced for org.assertj.swing.core RobotEventGenerator.java
You don't say which JDK 8 you are using. I've gone to AdoptOpenJDK jdk8u202-b08 (hotspot) but this has the mouseMove issue. I no longer use Oracle Java because JDK 11 has restricted license and is not general use. I have 3 monitors, so the issue always shows even if scale is 100%. |
As specified here https://bugs.openjdk.java.net/browse/JDK-8196030 this has been fixed in jdk 11.0.1. All previous versions have this big from what I understand |
@hirshbergshachar the original problem was like nothing works at all, right? Is this solved by the solution mentioned in #224 - which is a security restriction under MacOS. @DaveBrad and @LorenzoBettini thanks for your comments - do your tests still fail? Always? Sometimes? If sometimes, does the JDK update make any difference? |
In my case the tests (concerning clicking) almost always fail unless I remove the scaling or I update to JDK 11.0.2 |
is this solved? I am also having similar issue mouse clicking works only if i lower the resolution? is there a workaround so that mouse clicking can be performed with default resolution. @croesch |
I've not seen any work being done on this. The root cause is Java 8 Robot and is likely not going to be fixed in Java code. I've not tried with JDK 11 yet. I'd suggest you: 1) move to Java 11 or 2) build the AssertJ-swing with my suggested workaround above. It doesn't take long. |
After long debugging, it looks AssertJ (and Java robot) failed to send Mouse event into JOptionPane (I guess into modal dialog). Under Ubuntu virtual machine mouse event (move, press, release) either send or not send. Potentially this thread is about the same: assertj/assertj-swing#229
As I'm relegated to a project stuck in Java 8 the best working solutions for me so far was:
|
I wrote this to overcome the problem clicking on buttons and it works in Java 22.
|
Thanks so much @billsdesk 👏👏👏 I also reuse your code for the /**
* Overcome bug in AssertJ where fixture.textBox(name).enterText(text); does not work.
*
* @param fixture window fixture
* @param name textBox name
* @param text text to enter
* @throws InvocationTargetException thrown error
* @throws InterruptedException thrown error
*/
@SuppressWarnings("rawtypes")
public static void setText(final AbstractWindowFixture fixture,
final String name, String text) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
fixture.textBox(name)
.target()
.setText(text);
}
});
} |
Summary
I’m not able to use basic click functionalities with AssertJ (basically everything related to activating buttons)
Opened a thread about it in STO as well -
I’m not sure if it’s a regression or if I’m just missing out something obvious… the example here - Example is not working on my env as well (Java 11)
Example
The GUI is a JPanel and I use Containers.showInFrame to display it.
The panel has some text fields, JCheckboxes and JComboboxes.
I'm able to set text in the text fields, but I am not able to check/select the boxes. Been breaking my head but couldn't figure out what is missing...
Working:
Not working:
The component description that I get for a checkbox is:
[javax.swing.JCheckBox[name='exampleCheckBox', text='Mandatory', selected=true, enabled=true, visible=true, showing=true] - property:'selected']
Using Java 11, Gradle build, latest assertj-swing-junit and assertj-core.
Would highly appreciate any leads!
Thank you
The text was updated successfully, but these errors were encountered: