I am trying to write edit mode tests using the Test Runner to automatically test some editor only functionality which uses UIElements to render its layout.
I have a UIElements Button and I am trying to invoke a click event upon it from one of my unit tests, to ensure that its functionality is working correctly, however I can’t figure out how to do this from a script.
If anyone has any pointers or advice on how to achieve this I would be extremely grateful.
I had a feeling this was the correct answer and I have set it up now and I can see the button visual changing like it has been clicked by the script but its clicked event is not triggered (if I click the button with my mouse in the editor window this occurs as expected). Is there any reason you know of why this might happen?
Current code to click the button (and the whole unit test) is as follows:
Thanks again for the reply. I tried setting the target of the event to be the Button I am trying to click but it seems to have made no difference.
I have also tried to follow the example more closely and use an instance of Event to initialise the pooled object returned from GetPooled but this also hasn’t made any difference.
I can still see the button visually looking like it has been clicked but the clicked event for the button is never invoked and subsequently my code is never executed to create objects in the hierarchy/graph view.
Isn’t it so, that the clicked event is only fired on mouse down followed by mouse up?
I remember trying to fire the clicked event through code, unfortunately, without any success some time ago. I ended up implementing the feature differently due to this issue.
Amazing. I have nailed it off the back of your reply.
I tried swapping from MouseDownEvent to a MouseUpEvent and that still didn’t trigger the clicked event but then tried a MouseDownEvent followed straight away by a MouseUpEvent and that resulted in the clicked event being invoked and behaving like I was expecting.
Thanks for the reply. You have helped me immensely! Cheers!