-
Notifications
You must be signed in to change notification settings - Fork 94
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
[Question] Is it possible to run tests that interact with UI using InputSender? #586
Comments
Do you really need to test pressing the actual button, if i test ui i just simulate a mouse press by retrieving the button and call |
Fair enough, I'll just do this instead. It made sense in my head to simulate it being physically clicked, but this is obviously much easier. |
If it helps, the doc says
I'm not in the same situation as you, but for me waiting 2 frames solved my problems. Tip: If you provide a minimal reproducible example, including .tscn or .gd files under test, it would make it easier to help you. |
When testing buttons, it is often best to just emit the signal yourself (an opinion I've come to after trying to simulate it myself). This should be added to the documentation. The Input mocking is more useful when you have implemented complicated logic in your input handling. Like if you have made your own "pressed" event on an Area2D by
|
I'm trying to write a few tests that simulate pressing buttons in a UI. I'm using InputSender to send mouse events to the buttons, but they don't seem to be reacting to the events. I've tried a number of things to get it to work. I first tried just calling
_sender.mouse_left_button_up()
on the sender to send an mouse up event to the button, as i've noticed that buttons don't usually toggle unless you release the left mouse button, but this did not work. Next, I tried a combination of_sender.mouse_left_button_down()
and_sender.mouse_left_button_up()
in that order thinking maybe the button won't toggle unless it first receives a mouse down event, but that did not work either. Finally, I did_sender.mouse_motion()
,_sender.mouse_left_button_down()
and_sender.mouse_left_button_up()
in that order, but once again, it did not work. I also checked to make sure that the positions I was passing to those methods were right where the button was located, and it was indeed where it should be.Here is what my test looks like at the moment:
So I have no idea if I'm doing something wrong or if this is even possible to begin with. Can you interact with UI elements using InputSender? How would you write tests that interact with UI elements?
The text was updated successfully, but these errors were encountered: