Siddi Posted July 9, 2018 Share Posted July 9, 2018 Hi, I'd like to develop some automated UI tests for my PixiJS application (PixiJS 4.8.1). My test procedure should look something like this later: const test = new UITest() test.click({x: 100, y: 80}) test.drag({x: 100, y: 80}, {x: 120, y: 40}) test.dblClick({x: 200, y: 120}) etc. For this I have to trigger events. I know that the InteractionManager and DisplayObject inherit from EventEmitter. Which option is the best way to trigger events? 1. directly on the canvas element? const originalEvent = new MouseEvent('click', { bubbles: true, cancelable: true, ... }) app.view.dispatchEvent(originalEvent) 2. or via app.renderer.plugins.interaction.onPointerUp (originalEvent) for example? 3. or via app.renderer.plugins.interaction.emit(originalEvent) Unfortunately, I have not yet managed to trigger an event with these three ways ? What already worked was to call the emit method directly on a PIXI.DisplayObject, but I needed to create a PIXI.InteractionEvent object myself, which was quite expensive ... Thanks in advance! Siddi Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 9, 2018 Share Posted July 9, 2018 look up InteractionManager class. The instance is in "app.renderer.interaction" You might want to look inside the class (look up in SOURCES, not docs) Quote Link to comment Share on other sites More sharing options...
Siddi Posted July 9, 2018 Author Share Posted July 9, 2018 (edited) I've looked into the sources, but still don't know if it's best to use app.renderer.plugins.interaction.emit('pointerup', originalEvent) or app.renderer.plugins.interaction.onPointerUp(originalEvent) But I think both should work, or not? Edited July 9, 2018 by Siddi Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 9, 2018 Share Posted July 9, 2018 InteractionManager-related questions are mostly experimental. There are no guides for it, I even recommend to hack that class if something goes wrong for you. Quote Link to comment Share on other sites More sharing options...
Siddi Posted July 10, 2018 Author Share Posted July 10, 2018 OK, thank you! Quote Link to comment Share on other sites More sharing options...
xerver Posted July 11, 2018 Share Posted July 11, 2018 Depends on what you want to test. If you want to test your code and assume the interaction manager works, then dispatch events from the interaction manager. If you want to test that the interaction manager works, and that your code works using it, then dispatch mouse events onto the canvas. The second is also more similar to what "a user would do". Siddi 1 Quote Link to comment Share on other sites More sharing options...
Siddi Posted July 11, 2018 Author Share Posted July 11, 2018 I assume that the interaction manager works, and want to test my own code. I found a solution for me. I fire standard JavaScript events (MouseEvent and PointerEvent) directly on the canvas element. The rest (triggering the events on a certain DisplayObject) then takes over pixi for me. It is easier than expected ?, thank you! Quote Link to comment Share on other sites More sharing options...
AlexanderO Posted March 21, 2021 Share Posted March 21, 2021 How did you achieve that @Siddi ? i have tried function pressMe() { console.log('INCEARCA SA DEA CLICK'); const eventObject = document.createEvent('MouseEvents'); console.log(app.view); eventObject.initMouseEvent( 'click', true, true, window, 1, 100, 100, 100, 100, false, false, false, false, 0, null ); const element = document.getElementsByTagName('canvas')[0]; console.log("my canvas is", element); element.dispatchEvent(eventObject); } and it doesn't work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.