<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stanislav Mokshyn on Medium]]></title>
        <description><![CDATA[Stories by Stanislav Mokshyn on Medium]]></description>
        <link>https://medium.com/@testdream66?source=rss-1a8720282b72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Zic-ldSx3CqUaapFUdCozA.jpeg</url>
            <title>Stories by Stanislav Mokshyn on Medium</title>
            <link>https://medium.com/@testdream66?source=rss-1a8720282b72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 08:38:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@testdream66/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Your Canvas E2E Tests Pass Locally but Fail in CI]]></title>
            <link>https://medium.com/@testdream66/why-your-canvas-e2e-tests-pass-locally-but-fail-in-ci-f234f49b95c9?source=rss-1a8720282b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/f234f49b95c9</guid>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[webgl]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Stanislav Mokshyn]]></dc:creator>
            <pubDate>Wed, 12 Aug 2026 09:50:33 GMT</pubDate>
            <atom:updated>2026-08-12T09:54:12.456Z</atom:updated>
            <content:encoded><![CDATA[<p>There is a particularly annoying category of problems in test automation for browser-based games.</p><p>You run the tests locally.</p><p>Everything looks perfect.</p><p>The game loads. Animations are smooth. The UI behaves exactly as expected. You run the same scenario several times and get the same result every time.</p><p>Green.</p><p>Then you move exactly the same test suite to CI.</p><p>And suddenly things start falling apart.</p><p>One test times out while waiting for an animation.</p><p>Another cannot detect a state transition.</p><p>Something that normally takes two seconds locally suddenly takes twenty.</p><p>Screenshots sometimes look fine, but the test still fails because the application did not reach the expected state in time.</p><p>And the worst part is that you cannot reproduce any of it locally.</p><p>At some point somebody inevitably says:</p><p><strong>“Looks like a flaky test.”</strong></p><p>This is where I would stop touching the test.</p><p>Because sometimes the problem has absolutely nothing to do with automation.</p><p>Sometimes the real problem is <strong>where that automation is running</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXMjv_CszLZvSl3TD8187Q.png" /><figcaption><em>The same test can behave completely differently when the rendering environment changes. Locally the game runs smoothly; in CI it may technically run, but at unusably low FPS.</em></figcaption></figure><h3>1. Start With the Environments Your Product Actually Supports</h3><p>This sounds obvious.</p><p>In practice, it is surprisingly easy to forget.</p><p>Imagine a fairly typical setup.</p><p>Developers work on Windows and macOS.</p><p>Most real users access the product through mobile devices or regular desktop browsers.</p><p>The CI infrastructure, however, runs on Linux.</p><p>Why Linux?</p><p>Because it is convenient.</p><p>Docker works nicely.</p><p>Jenkins agents are easy to provision.</p><p>It is relatively cheap.</p><p>It scales well.</p><p>Everybody is used to it.</p><p>And eventually nobody asks a very important question anymore:</p><p><strong>Does the product actually support Linux?</strong></p><p>If Linux is part of the officially supported environment, there is no problem.</p><p>But if it is not, things become much more interesting.</p><p>A developer may introduce a browser-related library or plugin.</p><p>It works on Windows.</p><p>It works on macOS.</p><p>It works in every environment mentioned in the product requirements.</p><p>From the developer’s point of view, everything is correct.</p><p>Then the nightly automation starts on a Linux Jenkins agent and the application suddenly behaves differently.</p><p>And honestly, the developer did not necessarily do anything wrong.</p><p>Why would they be required to support an operating system that is not part of the product requirements?</p><p>I have seen exactly this kind of issue.</p><p>One application used a component responsible for checking browser compatibility.</p><p>Locally, everything worked perfectly.</p><p>But inside CI, the application suddenly decided that the browser was unsupported and displayed a message similar to:</p><p><strong>Use Chrome 50+.</strong></p><p>The funny part was that the installed Chrome version was significantly newer than that.</p><p>You can spend hours debugging Cypress.</p><p>You can rewrite selectors.</p><p>You can change intercepts.</p><p>You can add waits.</p><p>You can blame synchronization.</p><p>But none of that fixes the actual problem.</p><p>The testing environment itself does not match the environment the product was designed and validated to support.</p><p>That gives us the first important rule:</p><p><strong>Your CI environment should be part of the environments your product actually supports.</strong></p><p>Or, at the very least, the team should consciously understand the risks when it is not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_1aRt14cG5FK8C7O2gKklA.png" /><figcaption><em>A mismatch between supported product environments and the CI platform can create failures that look like automation issues but are actually compatibility issues.</em></figcaption></figure><h3>2. “The Game Opened” Does Not Mean the Environment Is Correct</h3><p>Now suppose the operating system is fine.</p><p>The game opens in CI.</p><p>The page loads.</p><p>The Canvas is visible.</p><p>There are no obvious JavaScript errors.</p><p>Everything seems ready.</p><p>So we can start running tests, right?</p><p>Not necessarily.</p><p>For a traditional web application, the presence of a GPU on the CI machine may not matter very much.</p><p>For a canvas-based game, the situation can be completely different.</p><p>Especially when the application relies heavily on WebGL, Pixi.js, complex animations, particle systems, filters, or real-time rendering.</p><p>These applications may depend heavily on hardware acceleration.</p><p>And this creates a nasty situation.</p><p>Locally, your game might run at 30, 40, or 60 FPS.</p><p>The same game inside CI technically runs as well.</p><p>Except it runs at:</p><p><strong>1 FPS.</strong></p><p>If you only look at the Jenkins console output, you may never notice it.</p><p>The page opened.</p><p>Network requests succeeded.</p><p>JavaScript did not crash.</p><p>The test started.</p><p>Technically everything looks alive.</p><p>But from the application’s point of view, time is now moving at a completely different speed.</p><h3>3. When 1 FPS Makes Everything “Flaky”</h3><p>Consider a very simple test.</p><p>The test clicks <strong>Spin</strong>.</p><p>The slot starts an animation.</p><p>When the animation finishes, the result appears and the application transitions into the next state.</p><p>Locally, the animation takes two seconds.</p><p>The test waits for the correct application state.</p><p>Everything is fine.</p><p>Now run exactly the same scenario in an environment where rendering happens at approximately 1 FPS.</p><p>Suddenly things become very different.</p><p>Animation frames are processed much more slowly.</p><p>State transitions are delayed.</p><p>Events arrive later.</p><p>Intermediate states remain active much longer than expected.</p><p>And the test starts failing with things like:</p><ul><li>timeout;</li><li>element not ready;</li><li>animation still running;</li><li>expected state not reached;</li><li>inconsistent visual state.</li></ul><p>And then the usual debugging ritual begins.</p><p>Increase the timeout from 5 seconds to 10.</p><p>Then to 30.</p><p>Add a retry.</p><p>Add another retry.</p><p>Maybe put a fixed wait somewhere, just in case.</p><p>Eventually the test becomes “stable.”</p><p>Except it did not become stable.</p><p>We simply taught the automation to wait patiently for an application that barely works in the CI environment.</p><p>That is not test stabilization.</p><p>That is infrastructure failure being hidden inside test code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ydau3fy4ZmZ8QsuNPg_HNQ.png" /><figcaption><em>One of the most useful clues can be a simple runtime metric. A game running at 1 FPS in CI is already telling you that test stability is not the real problem.</em></figcaption></figure><h3>4. How We Realized the Problem Was the GPU</h3><p>These issues are difficult because they are not always obvious.</p><p>If the application does not start at all, debugging is straightforward.</p><p>There is an error.</p><p>There is usually a stack trace.</p><p>You have something concrete to investigate.</p><p>The much worse situation is when the application <strong>starts, but does not behave normally</strong>.</p><p>In our case, one of the key clues came from the artifacts produced by CI.</p><p>At first, the screenshots looked more or less normal.</p><p>But once we started looking closer at the application state and runtime information, something stood out.</p><p>The FPS was around:</p><p><strong>1.</strong></p><p>Locally, the same scenario was running somewhere around 25–40 FPS or higher.</p><p>That immediately changed the investigation.</p><p>The question was no longer:</p><p><strong>“Why doesn’t the test wait correctly?”</strong></p><p>The question became:</p><p><strong>“Why is the application rendering at one frame per second?”</strong></p><p>And that is a completely different problem.</p><p>The automation framework was not the bottleneck.</p><p>The environment was.</p><h3>5. WebGL Can Introduce Another Class of Problems</h3><p>There is another issue I have seen on game projects.</p><p>The application appears to open normally.</p><p>But the rendering path is not the one we expect.</p><p>For example, WebGL may fail to initialize correctly.</p><p>Depending on the framework, browser version, and implementation, the application may fall back to another rendering path.</p><p>Historically, this could mean something like a Canvas 2D fallback.</p><p>From the perspective of the test, everything may still look fine.</p><p>The game is visible.</p><p>The buttons exist.</p><p>The automation can even continue.</p><p>But technically, we may now be testing the application in a completely different rendering environment.</p><p>And I consider this more dangerous than a simple failing test.</p><p>A red test tells us:</p><p><strong>Something is wrong.</strong></p><p>A green test running against the wrong rendering backend tells us:</p><p><strong>Everything is fine.</strong></p><p>Even though we might not be testing the environment our real users actually run.</p><p>So simply checking that:</p><p><strong>the application successfully opened</strong></p><p>is not enough.</p><p>For canvas-heavy applications, the test infrastructure should ideally verify things like:</p><ul><li>whether WebGL is actually available;</li><li>whether hardware acceleration is enabled;</li><li>which rendering backend is being used;</li><li>whether the browser has fallen back to software rendering;</li><li>which GPU the browser detects;</li><li>whether FPS is within an acceptable range.</li></ul><p>These checks can become part of an environment health check that runs before the regression suite.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJe9FxTnwxeCcSzX3QEZcQ.png" /><figcaption><em>“The application is running” is not the same as “the application is running in the expected rendering mode.”</em></figcaption></figure><h3>6. Docker Does Not Magically Give You a GPU</h3><p>At this point, Docker usually enters the conversation.</p><p>And Docker is great.</p><p>It solves a huge number of CI problems.</p><p>It gives us reproducible environments.</p><p>We can control:</p><ul><li>Node.js versions;</li><li>browser versions;</li><li>dependencies;</li><li>environment variables;</li><li>test runner versions;</li><li>supporting services.</li></ul><p>That is extremely useful.</p><p>But Docker solves the <strong>software environment</strong>.</p><p>It does not magically create suitable graphics hardware.</p><p>You can build an absolutely perfect container image and still end up with terrible rendering performance.</p><p>For regular web automation, that may not matter.</p><p>For a game heavily dependent on WebGL, it absolutely can.</p><p>This means that canvas-based automation introduces another dependency:</p><p><strong>the hardware environment.</strong></p><p>And that needs to be treated as part of the test infrastructure.</p><h3>7. “But the Server Has a GPU”</h3><p>This is another assumption that can become expensive very quickly.</p><p>Imagine we solve the problem by buying or provisioning a powerful server with a GPU.</p><p>Great.</p><p>Now we create several virtual machines on that server.</p><p>And naturally, we want to run several UI test sessions in parallel.</p><p>One physical server.</p><p>One GPU.</p><p>Several VMs.</p><p>Looks efficient.</p><p>But GPUs do not work exactly like CPUs.</p><p>You cannot simply assume that because the host has one physical GPU, every virtual machine automatically gets independent access to it.</p><p>Depending on the hardware and virtualization platform, you may need:</p><ul><li>GPU passthrough;</li><li>vGPU support;</li><li>SR-IOV;</li><li>specific drivers;</li><li>additional licensing;</li><li>supported hypervisor configurations.</li></ul><p>Some graphics cards are not designed to be shared between several virtual machines at all.</p><p>So this mental model:</p><p><strong>1 physical server + 1 GPU + 10 VMs = 10 GPU workers</strong></p><p>is generally unsafe.</p><p>Infrastructure planning for GPU-dependent tests has to take this into account before parallelization is introduced.</p><p>Otherwise you may “scale” the test infrastructure and actually make the rendering environment less predictable.</p><h3>8. Do Not Build One Universal CI Machine</h3><p>My preferred solution is not to make every Jenkins agent powerful enough to run everything.</p><p>That is unnecessarily expensive.</p><p>Most tests do not need a GPU.</p><p>So instead, separate your workloads by infrastructure requirements.</p><h3>Standard CI agents</h3><p>Linux.</p><p>Docker.</p><p>No dedicated GPU.</p><p>These workers can handle things such as:</p><ul><li>API tests;</li><li>backend integration tests;</li><li>business logic;</li><li>network-level scenarios;</li><li>non-rendering E2E checks;</li><li>tests that do not depend on real-time graphics.</li></ul><p>These agents are relatively cheap and easy to scale.</p><p>You can have many of them.</p><h3>UI / Game agents</h3><p>A separate pool.</p><p>Use an operating system that the product actually supports.</p><p>Give these machines a real GPU or a correctly configured virtual GPU solution.</p><p>Run things such as:</p><ul><li>canvas-dependent scenarios;</li><li>WebGL-dependent tests;</li><li>gameplay flows;</li><li>animation-heavy tests;</li><li>visual validation;</li><li>anything where rendering performance affects application behavior.</li></ul><p>In Jenkins, this does not need to be complicated.</p><p>You can use agent labels such as:</p><p>linux</p><p>windows-gpu</p><p>game-ui</p><p>The pipeline then decides which environment is appropriate for each group of tests.</p><p>The infrastructure follows the requirements of the test instead of forcing every test into the same environment.</p><h3>9. Add an Environment Health Check Before Running the Suite</h3><p>This is one of the things I would strongly recommend.</p><p>Before starting a two-hour regression run, spend a few seconds validating the machine itself.</p><p>Check:</p><ol><li>Which operating system is running?</li><li>Which browser version is installed?</li><li>Is WebGL available?</li><li>Which renderer is active?</li><li>Is hardware acceleration enabled?</li><li>Which GPU does the browser detect?</li><li>Is the rendering performance within an acceptable range?</li></ol><p>If one of these checks fails, the regression suite should probably not start.</p><p>Fail the environment.</p><p>Not 200 individual tests.</p><p>Because otherwise the team may spend the next morning investigating dozens of failures caused by one broken GPU driver or an incorrectly configured Jenkins agent.</p><p>There is a big difference between:</p><p><strong>TEST FAILED</strong></p><p>and:</p><p><strong>TEST ENVIRONMENT IS INVALID</strong></p><p>Automation infrastructure should be able to tell us which one happened.</p><h3>10. What About Headless Browsers?</h3><p>Headless mode itself is not necessarily a problem.</p><p>Modern browsers are perfectly capable of running complicated applications in headless mode.</p><p>The problem is assuming that:</p><p><strong>Headless Chrome in CI = Chrome running locally.</strong></p><p>That assumption is not always true.</p><p>Depending on the environment, there may be differences in:</p><ul><li>hardware acceleration;</li><li>GPU availability;</li><li>compositor configuration;</li><li>browser flags;</li><li>sandbox configuration;</li><li>rendering backend.</li></ul><p>So the important question is not simply:</p><p><strong>“Are we running headed or headless?”</strong></p><p>The better question is:</p><p><strong>“What graphics environment did the browser actually get after startup?”</strong></p><p>That is measurable.</p><p>And for graphics-heavy applications, it should be measured.</p><h3>11. Why I Would Not Move the Entire CI Infrastructure to Windows</h3><p>After all of this, there is an obvious reaction:</p><blockquote><em>Fine. Let’s just run everything on Windows machines with GPUs.</em></blockquote><p>I would not do that.</p><p>GPU agents are more expensive.</p><p>Windows agents are generally heavier than simple Linux workers.</p><p>And the majority of an automation suite usually does not need real-time graphics acceleration anyway.</p><p>So the CI infrastructure should be heterogeneous.</p><p>There is no rule saying that every Jenkins worker must be identical.</p><p>Quite the opposite.</p><p>Use the cheapest suitable environment for each job.</p><p>A realistic setup might look like this:</p><p><strong>Linux worker pool</strong></p><p>Cheap, scalable, containerized.</p><p>Used for most tests.</p><p>And:</p><p><strong>Windows GPU worker pool</strong></p><p>Smaller and more expensive.</p><p>Used only for rendering-sensitive scenarios.</p><p>That gives us both scalability and realistic UI execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TitIIV3u9bc_VWwJXeTzeg.png" /><figcaption><em>Do not force every test onto the same infrastructure. Route rendering-sensitive scenarios to GPU-capable workers and keep everything else on cheaper, scalable agents.</em></figcaption></figure><h3>12. “But Tests Should Be Platform Independent”</h3><p>Ideally, sure.</p><p>But we are not testing our tests.</p><p>We are testing the product.</p><p>If the product officially supports a specific set of environments, automation needs to respect that reality.</p><p>Otherwise we end up in a strange situation.</p><p>The product is not required to work on Linux.</p><p>But the automation team considers it a bug that the application does not work properly on Linux.</p><p>At that point we are effectively testing a requirement that nobody ever created.</p><p>And then we wonder why the tests are unstable.</p><h3>The Main Takeaway</h3><p>When game UI automation starts becoming unstable in CI, the natural reaction is to investigate the tests.</p><p>Add waits.</p><p>Increase timeouts.</p><p>Add retries.</p><p>Rewrite selectors.</p><p>Change interception logic.</p><p>Upgrade Cypress.</p><p>Migrate to Playwright.</p><p>Sometimes those things are genuinely necessary.</p><p>But before changing any test code, I would check something much more fundamental:</p><p><strong>Is the application itself actually running correctly in CI?</strong></p><p>Is the operating system supported?</p><p>Is WebGL working?</p><p>Is hardware acceleration available?</p><p>Which rendering backend is active?</p><p>Which GPU does the browser see?</p><p>What is the FPS?</p><p>Because if the game runs at 40 FPS on your laptop and at 1 FPS inside Jenkins, the quality of your waitFor is not the main problem.</p><p>You are trying to automate an application inside an environment where the application itself barely works.</p><p>And no test framework is going to fix that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f234f49b95c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[E2E Testing for Pixi.js Canvas: A Practical Playwright and Cypress Example]]></title>
            <link>https://medium.com/@testdream66/e2e-testing-for-pixi-js-canvas-a-practical-playwright-and-cypress-example-2698459b7e38?source=rss-1a8720282b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/2698459b7e38</guid>
            <category><![CDATA[playwrights]]></category>
            <category><![CDATA[end-to-end-testing]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[pixijs]]></category>
            <dc:creator><![CDATA[Stanislav Mokshyn]]></dc:creator>
            <pubDate>Sat, 08 Aug 2026 11:13:52 GMT</pubDate>
            <atom:updated>2026-08-08T12:30:48.747Z</atom:updated>
            <content:encoded><![CDATA[<p>Testing a traditional web application is usually straightforward.</p><p>The browser exposes buttons, inputs, links, and other UI elements through the DOM. Playwright or Cypress can locate them, interact with them, and verify the result.</p><p>Canvas applications are different.</p><p>A Pixi.js game may visually contain buttons, reels, balance values, animations, and result messages, but from the browser automation perspective, all of them can be hidden behind a single &lt;canvas&gt; element.</p><p>That changes the way E2E automation has to be designed.</p><p>In my previous articles, I described why Canvas applications are difficult to test and how Pixi.js internally represents objects that are not visible in the DOM.</p><p>This time, I wanted to go one step further.</p><p>Instead of only explaining the problem, I built a small Pixi.js game specifically to demonstrate how Canvas applications can be made testable with real E2E frameworks.</p><p>The result is a working example with:</p><ul><li>a Pixi.js application;</li><li>deterministic game state;</li><li>a small test bridge;</li><li>Playwright automation;</li><li>Cypress automation;</li><li>and a live hosted demo.</li></ul><p><strong>Live demo:</strong><br> <a href="https://pixijs-e2e-testing-demo.vercel.app/">https://pixijs-e2e-testing-demo.vercel.app/</a></p><p><strong>Application repository:</strong><br> <a href="https://github.com/testomut/pixijs-e2e-testing-demo">https://github.com/testomut/pixijs-e2e-testing-demo</a></p><p><strong>Playwright tests:</strong><br> <a href="https://github.com/testomut/PixiJsE2EPlaywright">https://github.com/testomut/PixiJsE2EPlaywright</a></p><p><strong>Cypress tests:</strong><br> <a href="https://github.com/testomut/PixiJsE2ECypress">https://github.com/testomut/PixiJsE2ECypress</a></p><h3>The Problem</h3><p>Consider a simple slot game.</p><p>A player enters a nickname, starts the game, changes the bet, presses SPIN, watches the reels animate, and eventually receives a win or loss result.</p><p>Visually, the application looks like any other UI.</p><p>But the browser may see something closer to this:</p><pre>&lt;canvas&gt;&lt;/canvas&gt;</pre><p>There is no DOM button corresponding to the visible SPIN button.</p><p>There is no HTML element containing the current balance.</p><p>There is no DOM representation of each reel symbol.</p><p>This means that a selector such as:</p><pre>page.getByRole(&quot;button&quot;, { name: &quot;Spin&quot; })</pre><p>simply cannot work for the actual Canvas controls.</p><p>The button exists inside the Pixi.js scene graph, not inside the DOM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qcxv09vx_IgAyHs7rCRQLw.png" /><figcaption>The Pixi.js demo game is used throughout this article. Most of the interactive UI is rendered inside a single HTML canvas and is automated with both Playwright and Cypress.</figcaption></figure><h3>Why Coordinate-Based Tests Are Not Enough</h3><p>The first obvious solution is to click directly on the Canvas:</p><pre>await page.mouse.click(640, 520);</pre><p>This may work.</p><p>But now the test depends on two magic numbers.</p><p>If the button moves because of:</p><ul><li>viewport changes;</li><li>scaling;</li><li>layout changes;</li><li>responsive behaviour;</li><li>game redesign;</li></ul><p>the test may fail even though the feature still works correctly.</p><p>The test also communicates almost no intent.</p><p>Compare:</p><pre>await page.mouse.click(640, 520);</pre><p>with:</p><pre>await startedGame.spin();</pre><p>The second version tells us what the test is doing.</p><p>That distinction becomes increasingly important as the test suite grows.</p><p>The goal therefore was not to eliminate coordinates completely.</p><p>Canvas interaction ultimately still happens at a coordinate.</p><p>The goal was to stop hardcoding those coordinates inside tests.</p><h3>Making the Pixi.js Scene Discoverable</h3><p>Pixi.js itself already knows where every object is.</p><p>Buttons, text elements, containers and sprites are organized in a scene graph.</p><p>The missing piece is a safe way for automation code to access the application during testing.</p><p>For the demo application, I expose a controlled reference:</p><pre>window.__TEST_APP__</pre><p>This exposes a small read-only observability contract for selected Pixi.js objects and game state, without exposing the Pixi Application, stage, renderer, or mutable internals.</p><p>The idea is simple:</p><pre>E2E Test<br>   ↓<br>Page Object<br>   ↓<br>Pixi Controller<br>   ↓<br>window.__TEST_APP__<br>   ↓<br>Pixi.js Scene Graph</pre><p>The actual test stays high-level.</p><p>The Pixi-specific complexity remains inside a dedicated helper layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CpyvSbTi3FmfJ9NpWzLx6g.png" /><figcaption>High-level test architecture. Both Playwright and Cypress automate the same Pixi.js Canvas application through separate framework-specific layers, while sharing the same read-only window.__TEST_APP__ bridge and the same /api/game/spin contract.</figcaption></figure><h3>Giving Canvas Objects Stable Names</h3><p>Finding an object inside the scene graph is much easier if important objects have stable identifiers.</p><p>For example, the demo application exposes objects such as:</p><pre>spinButton<br>reelsDisplay<br>balanceDisplay<br>stateDisplay<br>resultText<br>betMinus<br>betPlus</pre><p>Instead of assuming that the SPIN button is always located at a specific point on the screen, the automation layer can first locate spinButton.</p><p>The same concept can be used for text elements, buttons and animated objects.</p><p>The important point is that these names become a contract between the application and the automation layer.</p><p>They are similar in purpose to stable data-testid attributes in traditional DOM testing.</p><h3>Finding Objects Recursively</h3><p>Pixi.js scenes are usually hierarchical.</p><p>An object may be located several containers deep.</p><p>Conceptually, the controller can recursively traverse the scene graph:</p><pre>function findObjectByLabel(container, label) {<br>  if (container.label === label) {<br>    return container;<br>  }</pre><pre>  for (const child of container.children ?? []) {<br>    const result = findObjectByLabel(child, label);</pre><pre>    if (result) {<br>      return result;<br>    }<br>  }</pre><pre>  return undefined;<br>}</pre><p>The implementation details can differ between projects, but the principle is the important part:</p><p><strong>Tests should identify logical Canvas objects instead of guessing screen positions.</strong></p><h3>Converting a Pixi Object into a Browser Interaction</h3><p>Finding the object is only half of the problem.</p><p>Playwright and Cypress still interact with the browser.</p><p>They need screen coordinates.</p><p>Pixi.js can provide the actual object bounds:</p><pre>const bounds = object.getBounds();</pre><pre>From those bounds, we can calculate the center of the Pixi object in render space:<br><br>```ts<br>const renderX = bounds.x + bounds.width / 2;<br>const renderY = bounds.y + bounds.height / 2;</pre><p>However, render-space coordinates are not always the same as browser coordinates.</p><p>The Canvas may be displayed at a different CSS size than its internal rendering resolution, so the automation layer has to calculate the current scale:</p><pre>const rect = canvas.getBoundingClientRect();<br><br>const scaleX = rect.width / canvas.width;<br>const scaleY = rect.height / canvas.height;</pre><p>For Playwright, page.mouse.click() expects viewport coordinates, so the Canvas offset must also be included:</p><pre>const browserX = rect.left + renderX * scaleX;<br>const browserY = rect.top + renderY * scaleY;<br><br>await page.mouse.click(browserX, browserY);</pre><p>Cypress uses a slightly different final step because cy.wrap(canvas).click(x, y) accepts coordinates relative to the Canvas element itself:</p><pre>const canvasX = renderX * scaleX;<br>const canvasY = renderY * scaleY;<br><br>cy.wrap(canvas).click(canvasX, canvasY);</pre><p>The important point is that the coordinates are still used, but they are derived dynamically from the actual Pixi.js object and the current Canvas geometry.</p><p>If the object moves or the Canvas is CSS-scaled, the automation layer recalculates the interaction point instead of relying on hardcoded screen coordinates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-3b6XyWP2a4onJ1IViliA.png" /><figcaption>Semantic Pixi.js UI elements inside a single Canvas, exposed to E2E tests through a read-only window.__TEST_APP__ bridge.</figcaption></figure><h3>Keeping Pixi.js Logic Out of the Test</h3><p>One of the main design goals of the project was to avoid tests like this:</p><pre>const object = await page.evaluate(() =&gt; {<br>  // traverse PIXI tree<br>  // find object<br>  // calculate bounds<br>});</pre><pre>await page.mouse.click(...);</pre><pre>const state = await page.evaluate(() =&gt; {<br>  // inspect game internals again<br>});</pre><pre>expect(state).toBe(...);</pre><p>Technically, that works.</p><p>Architecturally, it becomes difficult to maintain.</p><p>The test should describe user behaviour and expected results.</p><p>For example, the Playwright test can look like this:</p><pre>test(&quot;player completes a winning spin&quot;, async ({ startedGame }) =&gt; {<br>  await startedGame.setNextSpinResult(&quot;win&quot;);<br>  await startedGame.spin();<br>  await startedGame.verifyResult(&quot;win&quot;);<br>});</pre><p>There are no raw coordinates.</p><p>There is no direct access to the Pixi scene.</p><p>There is no knowledge about where the button lives.</p><p>There is no low-level animation logic.</p><p>The test only describes the scenario.</p><p>That is the level of abstraction I want an E2E test to have.</p><h3>The Page Object Layer</h3><p>The page object represents actions available to the player.</p><p>For example:</p><pre>await startedGame.spin();<br>await startedGame.verifyResult(&quot;win&quot;);</pre><p>Internally, spin() can use the Pixi controller to find the correct object and perform the interaction.</p><p>Conceptually:</p><pre>async spin(): Promise&lt;void&gt; {<br>  await this.pixiController.click(&quot;spinButton&quot;);<br>}</pre><p>This separation matters because there are really two different responsibilities.</p><p>The <strong>page object</strong> knows:</p><blockquote><em>What can a user do in the game?</em></blockquote><p>The <strong>Pixi controller</strong> knows:</p><blockquote><em>How do I technically interact with an object rendered inside Canvas?</em></blockquote><p>Keeping those responsibilities separate makes the test code much easier to read.</p><h3>Deterministic Game Results</h3><p>A different problem appears once interaction works.</p><p>Games are often random.</p><p>Suppose I write:</p><pre>await startedGame.spin();<br>await startedGame.verifyResult(&quot;win&quot;);</pre><p>If the spin result is genuinely random, this is not a reliable automated test.</p><p>Sometimes it wins.</p><p>Sometimes it loses.</p><p>The test would be validating the random number generator rather than validating the user flow.</p><p>For E2E automation, I usually want deterministic scenarios.</p><p>The demo therefore allows the test to control the next result:</p><pre>await startedGame.setNextSpinResult(&quot;win&quot;);</pre><p>Now the test can explicitly create the state it needs:</p><pre>await startedGame.setNextSpinResult(&quot;win&quot;);<br>await startedGame.spin();<br>await startedGame.verifyResult(&quot;win&quot;);</pre><p>Another test can deliberately exercise the losing path:</p><pre>await startedGame.setNextSpinResult(&quot;loss&quot;);<br>await startedGame.spin();<br>await startedGame.verifyResult(&quot;loss&quot;);</pre><p>This turns randomness into test data.</p><p>It also separates two concerns:</p><pre>Randomness testing<br>        ≠<br>User-flow testing</pre><p>Both can be tested, but they should not necessarily be tested by the same test.</p><h3>Testing Animation State</h3><p>Canvas applications often contain another difficult area: animation.</p><p>A simple assertion such as:</p><pre>await page.waitForTimeout(3000);</pre><p>is easy to write, but it introduces unnecessary timing assumptions.</p><p>The test now assumes that the animation always finishes within three seconds.</p><pre>A better solution is to wait for meaningful application conditions instead of arbitrary time.<br><br>In the final implementation, animation synchronization belongs inside the `spin()` action itself.<br><br>The flow is:<br><br>```text<br>capture reel symbols before the click<br>        ↓<br>perform a real Canvas click<br>        ↓<br>wait for the game to enter &quot;spinning&quot;<br>        ↓<br>wait for the reel symbols to actually change<br>        ↓<br>wait for the spin lifecycle to complete</pre><p>This distinction is important.</p><p>phase === &quot;spinning&quot; proves that the application entered the expected lifecycle state.</p><p>A change in reel symbols proves that something in the Pixi.js scene actually changed visually.</p><p>So the test does not need separate animation helpers:</p><pre>await startedGame.spin();<br>await startedGame.verifyResult(&quot;win&quot;);</pre><p>There are no fixed delays such as waitForTimeout(3000).</p><p>The synchronization is based on observable application state and actual reel movement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LeDySL7acWB5dBy3feleEQ.png" /><figcaption>Playwright flow for a deterministic winning spin. The test stays business-readable while PixiController resolves semantic Pixi bounds, converts them to viewport coordinates, performs a real mouse click, and waits for both application state and actual reel movement.</figcaption></figure><h3>Testing with Playwright</h3><p>I created a separate repository for the Playwright implementation:</p><p><strong>GitHub:</strong><br> <a href="https://github.com/testomut/PixiJsE2EPlaywright">https://github.com/testomut/PixiJsE2EPlaywright</a></p><p>The project separates the test architecture into several layers:</p><pre>e2e/<br>  game.spec.ts<br><br>fixtures/<br>  game.fixture.ts<br><br>pages/<br>  GamePage.ts<br><br>support/<br>  PixiController.ts<br>  ApiRequests.ts<br><br>types/<br>  game.types.ts<br>  pixi.types.ts</pre><p>The test file remains intentionally small.</p><p>The fixture handles test setup.</p><p>The page object represents game actions.</p><p>The Pixi controller contains Canvas-specific interaction logic.</p><p>ApiRequests isolates network observation and deterministic API mocking, while the types layer keeps game state and Pixi object contracts strongly typed.</p><p>This allows test cases to remain readable even though the underlying UI is not DOM-based.</p><p>A high-level scenario can therefore look like:</p><pre>test(&quot;player completes a winning spin&quot;, async ({ startedGame }) =&gt; {<br>  await startedGame.setNextSpinResult(&quot;win&quot;);<br>  await startedGame.spin();<br>  await startedGame.verifyResult(&quot;win&quot;);<br>});</pre><p>That is important because Canvas testing does not have to mean that every test becomes a collection of page.evaluate() calls.</p><p>The complexity can be isolated.</p><h3>Testing the Same Application with Cypress</h3><p>I also implemented the same idea with Cypress.</p><p><strong>GitHub:</strong><br> <a href="https://github.com/testomut/PixiJsE2ECypress">https://github.com/testomut/PixiJsE2ECypress</a></p><p>The framework API is different, but the architectural principle remains the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8F0y5P1P4riz5eDXcdza_w.png" /><figcaption>The same deterministic winning-spin scenario implemented with Cypress. The business flow remains almost identical to the Playwright version, but synchronization relies on Cypress command chaining, automatic retryability, element-relative Canvas coordinates, and cy.intercept() for network control.</figcaption></figure><p>Cypress should not need hardcoded Canvas coordinates either.</p><p>The automation layer can:</p><ol><li>locate a Pixi.js object;</li><li>read its bounds;</li><li>calculate the interaction point;</li><li>trigger the user action;</li><li>verify the game state.</li></ol><p>The important part is not whether Playwright or Cypress is being used.</p><p>The important part is where the Canvas-specific knowledge lives.</p><p>In both implementations, I want the final tests to describe game behaviour rather than rendering implementation details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q12NThCdsYaLnlWWqyX-sQ.png" /><figcaption>The testability strategy stays the same. What changes is how each framework schedules commands, waits for state, and translates Canvas interaction into browser events.</figcaption></figure><h3>Playwright vs Cypress for This Problem</h3><p>Building the same example in both frameworks was useful because it highlights that Canvas testing is not primarily a framework problem.</p><p>Both Playwright and Cypress can test Canvas applications.</p><p>The difficult part is creating the abstraction between the automation framework and the Canvas scene.</p><p>Once that layer exists, either framework can operate at a much higher level.</p><p>Conceptually:</p><pre>┌──────────────┐<br>             │ Pixi.js App  │<br>             └──────┬───────┘<br>                    │<br>             Testable interface<br>                    │<br>          ┌─────────┴─────────┐<br>          │                   │<br>     Playwright            Cypress</pre><p>For me, this is one of the main conclusions from the experiment.</p><p><strong>The testability of a Canvas application depends more on application architecture than on the choice between Playwright and Cypress.</strong></p><h3>The Demo Application</h3><p>The application itself is available separately:</p><p><strong>Repository:</strong><br> <a href="https://github.com/testomut/pixijs-e2e-testing-demo">https://github.com/testomut/pixijs-e2e-testing-demo</a></p><p><strong>Live version:</strong><br> <a href="https://pixijs-e2e-testing-demo.vercel.app/">https://pixijs-e2e-testing-demo.vercel.app/</a></p><p>I deliberately kept the game relatively small.</p><p>The point was not to build a production slot game.</p><p>The goal was to reproduce the problems that appear in real Canvas automation:</p><ul><li>elements rendered outside the DOM;</li><li>nested Pixi objects;</li><li>coordinate conversion;</li><li>animations;</li><li>state transitions;</li><li>random outcomes;</li><li>reusable automation abstractions.</li></ul><p>This makes the application useful as a reproducible test environment rather than just a code snippet.</p><p>Anyone can run the game, inspect the repositories and see how the pieces work together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*at64kvvk7ss-9YkdPH8x9Q.png" /><figcaption>The final setup consists of one testable Pixi.js application and two independent E2E repositories. Both automation projects consume the same semantic labels, read-only bridge, and API contract while keeping their framework-specific execution models separate.</figcaption></figure><h3>What I Would Do in a Real Production Project</h3><p>The demo intentionally exposes a test interface because I control both the application and the automation.</p><p>In a real project, I would treat that interface as part of the application’s testability architecture.</p><p>I would avoid exposing arbitrary internal objects.</p><p>Instead, I would expose only the information required by automation.</p><p>For example:</p><pre>window.__TEST_APP__ = {<br>  isReady,<br>  getObjectBounds,<br>  getObjectText,<br>  getReelSymbols,<br>  getGameSnapshot,<br>};</pre><p>The bridge exposes observability only. Deterministic win, loss, and error scenarios are controlled through the network layer rather than through mutable application hooks.</p><p>This creates a narrow contract between the application and the tests.</p><p>That contract should be:</p><ul><li>stable;</li><li>intentional;</li><li>available only where appropriate;</li><li>independent from unnecessary rendering details.</li></ul><p>The same principle already exists in traditional web automation.</p><p>Teams add stable test attributes such as:</p><pre>data-testid=&quot;checkout-button&quot;</pre><p>because testability is easier when the application provides a stable interface.</p><p>Canvas applications need the same idea.</p><p>The interface simply looks different.</p><h3>What Should Still Be Tested Visually?</h3><p>Access to application state does not make visual testing unnecessary.</p><p>There are things that internal state cannot fully prove.</p><p>For example:</p><ul><li>whether a sprite is visually corrupted;</li><li>whether text overlaps another component;</li><li>whether the reels are clipped;</li><li>whether scaling is incorrect;</li><li>whether a shader renders incorrectly.</li></ul><p>These problems are better suited to screenshots or visual regression testing.</p><p>That means a strong Canvas testing strategy can combine several levels:</p><pre>Application state<br>      +<br>Canvas interaction<br>      +<br>API verification<br>      +<br>Visual validation</pre><p>Trying to solve every problem with only coordinate clicks or only screenshots usually leads to fragile tests.</p><h3>The Key Lesson</h3><p>Before working deeply with Canvas automation, it is easy to think that the main problem is:</p><blockquote><em>“How can Playwright click something inside Canvas?”</em></blockquote><p>But that is only the surface-level problem.</p><p>The more important question is:</p><blockquote><strong><em>How can the application expose enough stable information for automation without coupling tests to rendering details?</em></strong></blockquote><p>Once that problem is solved, Canvas E2E automation becomes much more manageable.</p><p>Instead of tests filled with magic coordinates:</p><pre>click(642, 518);<br>click(231, 404);<br>wait(3000);</pre><p>we can build tests that describe behaviour:</p><pre>await startedGame.setNextSpinResult(&quot;win&quot;);<br>await startedGame.spin();<br>await startedGame.verifyResult(&quot;win&quot;);</pre><p>That is ultimately what I wanted to demonstrate with this project.</p><p>Canvas may hide the UI from the DOM.</p><p>It does not have to hide the application from automation.</p><h3>Source Code and Demo</h3><p>You can explore the complete examples here:</p><p><strong>Live Pixi.js demo</strong><br> <a href="https://pixijs-e2e-testing-demo.vercel.app/">https://pixijs-e2e-testing-demo.vercel.app/</a></p><p><strong>Pixi.js application</strong><br> <a href="https://github.com/testomut/pixijs-e2e-testing-demo">https://github.com/testomut/pixijs-e2e-testing-demo</a></p><p><strong>Playwright E2E implementation</strong><br> <a href="https://github.com/testomut/PixiJsE2EPlaywright">https://github.com/testomut/PixiJsE2EPlaywright</a></p><p><strong>Cypress E2E implementation</strong><br> <a href="https://github.com/testomut/PixiJsE2ECypress">https://github.com/testomut/PixiJsE2ECypress</a></p><p>This project is part of my ongoing exploration of practical E2E automation approaches for Canvas and Pixi.js applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2698459b7e38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Pixi.js Works Inside Canvas and Why It Matters for QA Automation]]></title>
            <link>https://medium.com/@testdream66/how-pixi-js-works-inside-canvas-and-why-it-matters-for-qa-automation-a85c6ed59dac?source=rss-1a8720282b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/a85c6ed59dac</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[qa-automation]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[pixijs]]></category>
            <dc:creator><![CDATA[Stanislav Mokshyn]]></dc:creator>
            <pubDate>Thu, 02 Jul 2026 21:34:17 GMT</pubDate>
            <atom:updated>2026-07-02T21:38:48.888Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous article, I wrote about why Canvas and Pixi.js applications are difficult to test with normal E2E approaches.</p><p>The main problem is simple: the user sees a full interface, but Playwright or Cypress may see only one &lt;canvas&gt; element.</p><p>But if we want to automate this kind of application properly, it is not enough to say: “The DOM cannot see the button.”</p><p>We need to understand what actually happens inside the canvas.</p><p>Pixi.js does not just randomly draw pixels on the screen. Internally, it has its own structure: application, stage, containers, sprites, text objects, graphics, interactive objects, coordinates, transformations, and state.</p><p>For a QA Automation Engineer, this is important because this internal structure can become the foundation for stable test automation.</p><p>If the DOM does not give us selectors, we need to look for another access layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkSqOOcCPQkFLJWCFO3Umw.png" /></figure><p>DOM sees either normal HTML elements or one canvas element. Pixi.js keeps the real UI structure inside its internal scene graph.</p><h3>Canvas is a drawing surface, not an interface structure</h3><p>In a normal web application, HTML describes the structure of the UI.</p><p>For example:</p><pre>&lt;button data-testid=&quot;spin-button&quot;&gt;Spin&lt;/button&gt;</pre><p>For Playwright or Cypress, this is a normal element. We can find it, click it, check its text, and verify its state.</p><p>But in a Canvas application, the DOM may look like this:</p><pre>&lt;canvas id=&quot;game-canvas&quot;&gt;&lt;/canvas&gt;</pre><p>And that is all.</p><p>Inside the canvas, there may be a Spin button, balance value, reels, animation, popup, round result, and game state. But for the DOM, these are not separate HTML elements.</p><p>Canvas is more like a drawing surface. It is like a sheet of paper or a screen. You can draw a button on it, but this drawn button does not become a DOM button.</p><p>That is why this code may not work:</p><pre>await page.getByText(&#39;Spin&#39;).click();</pre><p>or in Cypress:</p><pre>cy.contains(&#39;Spin&#39;).click();</pre><p>The user can see the text Spin, but the browser DOM may know nothing about this text.</p><h3>Where does the interface actually live?</h3><p>If the application is built with Pixi.js, the interface lives inside the Pixi.js scene graph.</p><p>A simplified structure can look like this:</p><pre>Pixi Application<br>  Stage<br>    Game Scene<br>      Background<br>      Reels Container<br>        Reel 1<br>        Reel 2<br>        Reel 3<br>      Controls Container<br>        Spin Button<br>        Balance Text<br>        Menu Button<br>      Result Text</pre><p>The DOM may still contain only one canvas. But inside Pixi.js, there is a tree of objects.</p><p>This is a very important difference.</p><p>For a normal E2E tool, the Spin button does not exist in the DOM. But inside Pixi.js, it may exist as an object:</p><pre>const spinButton = new PIXI.Container();<br>spinButton.name = &#39;spinButton&#39;;</pre><p>or as a Sprite, Graphics, Text, or a combination of several objects.</p><p>If we have access to the Pixi.js application or stage, we can try to find this object not through the DOM, but through the internal Pixi.js structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkSqOOcCPQkFLJWCFO3Umw.png" /></figure><p>A Pixi.js interface is usually built as a hierarchy of display objects. The canvas shows the final result, but Pixi.js still knows the internal structure.</p><h3>The Pixi.js parts that matter for QA Automation</h3><p>I do not think a QA Automation Engineer needs to know Pixi.js like a game developer. But for test automation, a few concepts are very useful.</p><h3>Application</h3><p>Application is the main entry point of a Pixi.js app.</p><p>It usually contains the renderer, canvas, ticker, and stage.</p><p>A simplified example:</p><pre>const app = new PIXI.Application({<br>  width: 1280,<br>  height: 720,<br>  backgroundColor: 0x101018<br>});</pre><pre>document.body.appendChild(app.view);</pre><p>For tests, Application is useful because it gives access to the stage:</p><pre>window.__PIXI_APP__ = app;</pre><p>This does not always have to be available in production. But for a demo project or test environment, controlled access like this can make automation much easier.</p><h3>Stage</h3><p>stage is the root container of the Pixi.js scene.</p><p>You can think of it as the root of the visual tree.</p><pre>app.stage.addChild(gameScene);</pre><p>If a test has access toapp.stage, it can search for objects inside the scene.</p><p>For example:</p><pre>const spinButton = app.stage.getChildByName(&#39;spinButton&#39;);</pre><p>In a real project, the object may be deeper in the tree, so we may need a recursive search. But the core idea is the same: we are not searching inside the DOM. We are searching inside the Pixi.js scene graph.</p><h3>Container</h3><p>Container is a group of objects.</p><p>For example, a button can be a container with a background, text, and hover effect inside it:</p><pre>spinButton Container<br>  buttonBackground Graphics<br>  buttonText Text<br>  glowEffect Sprite</pre><p>For automation, this is useful because we can give a name to the entire container:</p><pre>spinButton.name = &#39;spinButton&#39;;</pre><p>Then the test can work with the button as one object instead of trying to separately find the text, background, and graphics.</p><h3>Sprite</h3><p>Sprite is an image or texture.</p><p>In games and visual interfaces, many elements are sprites: symbols, icons, buttons, background parts, and animation frames.</p><p>For example:</p><pre>const symbol = new PIXI.Sprite(symbolTexture);<br>symbol.name = &#39;reelSymbol1&#39;;</pre><p>For tests, a Sprite is interesting because it can be visible, positioned, sized, and named. But again, the DOM does not know anything about it.</p><h3>Text</h3><p>Text is text drawn inside the canvas by Pixi.js.</p><p>For example:</p><pre>const balanceText = new PIXI.Text(&#39;Balance: 1000&#39;);<br>balanceText.name = &#39;balanceText&#39;;</pre><p>The user sees this text. But cy.contains(&#39;Balance&#39;) or page.getByText(&#39;Balance&#39;) may not find it, because it is not HTML text.</p><p>For tests, I prefer not to rely on reading this text through the DOM. It is usually better to get the value from application state or a test hook:</p><pre>window.__TEST_APP__.getBalance();</pre><h3>Graphics</h3><p>Graphics is used to draw simple shapes: rectangles, lines, circles, borders, and button backgrounds.</p><p>For example, a button background can be drawn with Graphics:</p><pre>const buttonBackground = new PIXI.Graphics();<br>buttonBackground.roundRect(0, 0, 200, 70, 12);<br>buttonBackground.fill(0x3366ff);</pre><p>For the user, it looks like a button. For the DOM, it is still just pixels.</p><h3>Why object names are important for tests</h3><p>In normal web automation, we often use data-testid.</p><p>For example:</p><pre>&lt;button data-testid=&quot;spin-button&quot;&gt;Spin&lt;/button&gt;</pre><p>In Pixi.js, we do not have data-testid in the DOM. But we can use a similar idea with object names or custom metadata.</p><p>For example:</p><pre>spinButton.name = &#39;spinButton&#39;;<br>balanceText.name = &#39;balanceText&#39;;<br>reelsContainer.name = &#39;reelsContainer&#39;;</pre><p>Then tests can use stable object names.</p><p>For example:</p><pre>const spinButton = window.__PIXI_APP__.stage.getChildByName(&#39;spinButton&#39;);</pre><p>If the object is deeper in the tree, we can write a helper:</p><pre>function findPixiObjectByName(container, name) {<br>  if (container.name === name) {<br>    return container;<br>  }<br><br>for (const child of container.children || []) {<br>    const result = findPixiObjectByName(child, name);<br>    if (result) {<br>      return result;<br>    }<br>  }<br>  return null;<br>}</pre><p>This works like a selector, but instead of selecting DOM nodes, we select display objects inside the Pixi.js scene graph.</p><h3>Local coordinates are not always real canvas coordinates</h3><p>In the DOM, when we click an element, the browser knows where it is on the screen.</p><p>In Pixi.js, things are a bit more complicated.</p><p>An object can have a local position:</p><pre>spinButton.x = 300;<br>spinButton.y = 120;</pre><p>But if the object is inside a parent container, and that parent container is moved, scaled, or transformed, the local position may not match the real position on the canvas.</p><p>For example:</p><pre>stage<br>  gameScene x = 100, y = 50<br>    controlsContainer x = 60, y = 30<br>      spinButton x = 300, y = 120</pre><p>In this case, the real screen position is not just (300, 120). We need to include parent container positions.</p><p>In Pixi.js, this is usually handled through world coordinates.</p><p>For example:</p><pre>const worldPosition = spinButton.getGlobalPosition();</pre><p>or in some cases:</p><pre>const x = spinButton.worldTransform.tx;<br>const y = spinButton.worldTransform.ty;</pre><p>For E2E tests, this matters a lot.</p><p>Instead of hardcoding coordinates:</p><pre>await page.mouse.click(960, 540);</pre><p>we can calculate or read the real object position at runtime:</p><pre>const position = await page.evaluate(() =&gt; {<br>  return window.__TEST_APP__.getObjectPosition(&#39;spinButton&#39;);<br>});</pre><pre>await page.mouse.click(position.x, position.y);</pre><p>This is much more stable because the test clicks where the object actually is now, not where it happened to be when the test was written.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0gCVqTPSmh6nRI3zNrWYA.png" /></figure><p>Local coordinates are relative to a parent object. For reliable canvas clicks, tests usually need world coordinates on the canvas.</p><h3>Interactive objects and pointer events</h3><p>In Pixi.js, an object can be interactive.</p><p>Depending on the Pixi.js version, the syntax may look different, but the idea is similar:</p><pre>spinButton.eventMode = &#39;static&#39;;<br>spinButton.cursor = &#39;pointer&#39;;</pre><pre>spinButton.on(&#39;pointertap&#39;, () =&gt; {<br>  startSpin();<br>});</pre><p>For the user, this is just a normal click on a button. Technically, it is a Pixi.js pointer event inside the canvas.</p><p>An E2E test can interact with this in two main ways.</p><p>The first way is close to real user behavior: click on the canvas at the object coordinates.</p><pre>await page.mouse.click(position.x, position.y);</pre><p>The second way is to call an application method directly:</p><pre>window.__TEST_APP__.spin();</pre><p>For real E2E tests, I prefer the first option because it is closer to how the user interacts with the application. The second option can still be useful for lower-level checks or for preparing test state.</p><h3>App state is often better than text on the screen</h3><p>In Canvas applications, checking text the same way we do it in a normal DOM application is often unreliable.</p><p>For example, the game state can be drawn inside the canvas as:</p><pre>IDLE<br>SPINNING<br>RESULT</pre><p>But if this is Pixi.js Text, Playwright and Cypress may not see it through normal text locators.</p><p>That is why it is useful to expose a small app state API for tests:</p><pre>window.__TEST_APP__ = {<br>  getGameState: () =&gt; gameState,<br>  getBalance: () =&gt; balance,<br>  getLastSpinResult: () =&gt; lastSpinResult<br>};</pre><p>Then the test can wait for a real state instead of waiting for a fixed timeout:</p><pre>await page.waitForFunction(() =&gt; {<br>  return window.__TEST_APP__.getGameState() === &#39;result&#39;;<br>});</pre><p>In Cypress, the idea is similar:</p><pre>cy.window().then((win) =&gt; {<br>  expect(win.__TEST_APP__.getGameState()).to.eq(&#39;result&#39;);<br>});</pre><p>This makes tests more stable.</p><p>Instead of this:</p><pre>await page.waitForTimeout(3000);</pre><p>we wait for a meaningful application condition.</p><h3>Test hooks are not a hack if they are designed carefully</h3><p>Sometimes test hooks are treated as something dirty or artificial. But in Canvas and Pixi.js applications, they can be a normal part of testability.</p><p>The important thing is to keep them small, explicit, and safe.</p><p>A good test hook may look like this:</p><pre>window.__TEST_APP__ = {<br>  getGameState: () =&gt; gameState,<br>  getBalance: () =&gt; balance,<br>  getObjectPosition: (name) =&gt; getObjectPosition(name),<br>  getLastSpinResult: () =&gt; lastSpinResult<br>};</pre><p>A bad test hook would expose too much:</p><pre>window.__TEST_APP__ = {<br>  app,<br>  store,<br>  services,<br>  apiClient,<br>  allInternalMethods<br>};</pre><p>The goal is not to give tests unlimited access to the application. The goal is to provide a small and predictable API for checking real user scenarios.</p><p>For QA Automation, this is not about “cheating.” It is about making a Canvas-heavy application testable.</p><h3>How this connects to Playwright and Cypress</h3><p>Playwright and Cypress are still useful for Canvas applications.</p><p>They can:</p><ul><li>open the page;</li><li>control the browser;</li><li>click on the canvas;</li><li>intercept network requests;</li><li>wait for responses;</li><li>take screenshots;</li><li>work with localStorage and sessionStorage;</li><li>execute JavaScript in the page context;</li><li>read exposed test hooks.</li></ul><p>But instead of this classic model:</p><pre>Find DOM element -&gt; click -&gt; expect DOM result</pre><p>we often use a different model:</p><pre>Find Pixi object -&gt; calculate coordinates -&gt; click canvas -&gt; wait network/state -&gt; verify result</pre><p>For example, in Playwright:</p><pre>const position = await page.evaluate(() =&gt; {<br>  return window.__TEST_APP__.getObjectPosition(&#39;spinButton&#39;);<br>});<br><br>await Promise.all([<br>  page.waitForResponse(response =&gt;<br>    response.url().includes(&#39;/api/game/spin&#39;) &amp;&amp;<br>    response.status() === 200<br>  ),<br>  page.mouse.click(position.x, position.y)<br>]);<br>await page.waitForFunction(() =&gt; {<br>  return window.__TEST_APP__.getGameState() === &#39;result&#39;;<br>});</pre><p>In Cypress:</p><pre>cy.intercept(&#39;POST&#39;, &#39;**/api/game/spin&#39;).as(&#39;spinRequest&#39;);<br><br>cy.window().then((win) =&gt; {<br>  const position = win.__TEST_APP__.getObjectPosition(&#39;spinButton&#39;);<br>  cy.get(&#39;canvas&#39;).click(position.x, position.y);<br>});<br>cy.wait(&#39;@spinRequest&#39;);<br>cy.window().then((win) =&gt; {<br>  expect(win.__TEST_APP__.getGameState()).to.eq(&#39;result&#39;);<br>});</pre><p>This is not classic DOM-based testing. But it is still E2E testing because we verify real application behavior in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pjKLyCTaXcn8L55cDOz4Q.png" /></figure><p>A stable Canvas/Pixi.js E2E flow can combine Pixi.js object access, dynamic coordinates, canvas clicks, network waits, application state, and result verification.</p><h3>What makes a Pixi.js application easier to test?</h3><p>If I were preparing a Pixi.js application for E2E automation, I would ask for a few simple things.</p><p>First, stable names for important objects:</p><pre>spinButton.name = &#39;spinButton&#39;;<br>balanceText.name = &#39;balanceText&#39;;<br>reelsContainer.name = &#39;reelsContainer&#39;;</pre><p>Second, small and safe test hooks:</p><pre>window.__TEST_APP__ = {<br>  getGameState,<br>  getBalance,<br>  getObjectPosition,<br>  getLastSpinResult<br>};</pre><p>Third, clear application states:</p><pre>idle<br>spinning<br>result</pre><p>Fourth, network requests that tests can wait for:</p><pre>POST /api/game/spin<br>GET /api/balance</pre><p>Fifth, deterministic test mode.</p><p>For example, in a demo or test environment, it can be useful to have controlled results:</p><pre>force win<br>force lose</pre><p>This does not have to be available to real users. But for automated tests, it helps make scenarios stable and repeatable.</p><h3>Why this matters for QA Automation Engineers</h3><p>In normal web automation, QA Automation Engineers often work with DOM, locators, and page objects.</p><p>In Canvas and Pixi.js applications, this is not enough.</p><p>We need to understand:</p><ul><li>where the UI actually lives;</li><li>why the DOM cannot see internal elements;</li><li>how Pixi.js organizes visual objects;</li><li>how to get object coordinates;</li><li>how to wait for application state;</li><li>how to combine state and network waits;</li><li>how to avoid fragile hardcoded coordinates.</li></ul><p>This is closer to engineering work than simply writing a selector and clicking a button.</p><p>That is why Canvas and Pixi.js automation can be a strong area of expertise. These tasks are less common than normal DOM testing, but when they appear, standard approaches often hit their limits very quickly.</p><h3>Conclusion</h3><p>Pixi.js applications are not hard to test because they have no elements.</p><p>They have elements.</p><p>The difference is that these elements do not live in the DOM. They live inside the Pixi.js scene graph.</p><p>For the user, the Spin button is a button.</p><p>For the DOM, it is just pixels inside a canvas.</p><p>For Pixi.js, it is an object with a name, position, state, and events.</p><p>This internal layer can be used to build more stable automation.</p><p>If the application has stable object names, access to state, safe test hooks, and predictable network events, tools like Playwright and Cypress can test even Canvas-heavy interfaces effectively.</p><p>In the next article, I will move to the practical part: building a small helper layer for a Pixi.js application, finding objects inside the canvas, calculating dynamic coordinates, clicking them with Playwright and Cypress, waiting for app state, and synchronizing with network requests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a85c6ed59dac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Canvas and Pixi.js Applications Are Hard to Test in E2E]]></title>
            <link>https://medium.com/@testdream66/why-canvas-and-pixi-js-applications-are-hard-to-test-in-e2e-b95474640633?source=rss-1a8720282b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/b95474640633</guid>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[playwright-test]]></category>
            <category><![CDATA[qa-automation]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[test-automation]]></category>
            <dc:creator><![CDATA[Stanislav Mokshyn]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 14:05:43 GMT</pubDate>
            <atom:updated>2026-06-28T14:12:59.549Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first worked with Canvas/Pixi.js interfaces, one thing became clear quite quickly: the usual web automation approaches do not work as well there.</p><p>And this is not really a Playwright-only or Cypress-only problem. Both tools are powerful when the application exposes a proper DOM structure. If there is a button, it can have a role, text, data-testid, CSS selector, or another stable attribute. If there is a modal, we can find it in the DOM. If there is an error message, we can check it by text or by an attribute.</p><p>But Canvas applications are different.</p><p>The user sees a full interface: buttons, animations, balance, game objects, popups, and game states. But the E2E tool often sees only this:</p><pre>&lt;canvas id=&quot;game&quot; width=&quot;1280&quot; height=&quot;720&quot;&gt;&lt;/canvas&gt;</pre><p>That is all.</p><p>The Spin button is visible, but it does not exist as a DOM element. The balance is visible on the screen, but getByText(&#39;1250&#39;) in Playwright or cy.contains(&#39;1250&#39;) in Cypress may find nothing. The reels are spinning, the result appears, the animations are playing, but for the automation framework, it is still one canvas.</p><p>This is where things become interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hsNDGQ4zXFfD_j-Ij-oCnQ.png" /></figure><h3>The main problem</h3><p>Playwright and Cypress work very well when the application gives them a useful DOM structure.</p><p>For example, if we have a normal button:</p><pre>&lt;button data-testid=&quot;login-button&quot;&gt;Log in&lt;/button&gt;</pre><p>In Playwright, we can write:</p><pre>await page.getByTestId(&#39;login-button&#39;).click();</pre><p>and in Cypress:</p><pre>cy.get(&#39;[data-testid=&quot;login-button&quot;]&#39;).click();</pre><p>Both examples are readable and reasonably stable. Even if a designer changes the button color or adjusts the spacing, the test will probably keep working.</p><p>In a Canvas/Pixi.js application, the same button can be a sprite, texture, or graphical object inside the scene. For the user, it is a button. For the E2E tool, it is just pixels inside the canvas.</p><p>For example, the interface can look like a game with a Spin button, balance, animations, and a round result, while the DOM looks like this:</p><pre>&lt;body&gt;<br>  &lt;canvas id=&quot;game&quot; width=&quot;1280&quot; height=&quot;720&quot;&gt;&lt;/canvas&gt;<br>&lt;/body&gt;</pre><p>This changes the automation strategy completely.</p><p>We can no longer simply write this in Playwright:</p><pre>await page.getByText(&#39;Spin&#39;).click();<br>await expect(page.getByText(&#39;You won&#39;)).toBeVisible();</pre><p>Or this in Cypress:</p><pre>cy.contains(&#39;Spin&#39;).click();<br>cy.contains(&#39;You won&#39;).should(&#39;be.visible&#39;);</pre><p>In a normal web application, this would be fine. In a Canvas interface, it may not work at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ujg3o3Mw7vhERqpHeP1i3A.png" /></figure><h3>Coordinate clicks are fast, but fragile</h3><p>The most obvious workaround is to click by coordinates.</p><p>In Playwright, it can look like this:</p><pre>await page.mouse.click(960, 540);</pre><p>In Cypress, something similar can be done through the canvas element:</p><pre>cy.get(&#39;canvas&#39;).click(960, 540);</pre><p>Sometimes this works. Especially when we need a quick smoke test or proof of concept. If the button is always in the same place, a coordinate click can solve a simple problem.</p><p>But the problem usually appears later.</p><p>Today the button is at (960, 540). Tomorrow the designer changes the layout a little. Then the test runs in CI with a different viewport. Then the canvas is placed inside an iframe. Then the scale changes. Visually, almost nothing has changed for the user, but the test is already clicking in the wrong place.</p><p>Coordinates can break because of:</p><ul><li>different browser window size;</li><li>responsive layout;</li><li>canvas scaling;</li><li>device pixel ratio;</li><li>iframe or external container;</li><li>localization;</li><li>design changes;</li><li>animation;</li><li>different object position after rendering.</li></ul><p>The same test can pass locally and fail in CI. It can work in headed mode and fail in headless mode. It can pass on 1920x1080 and break on 1366x768.</p><p>So I do not think coordinate-based testing is bad. I think it becomes dangerous when it is the only strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7pLyXiwxvgZ894xfv9gaCA.png" /></figure><h3>Visual testing helps, but it does not always explain the problem</h3><p>Another option is visual testing.</p><p>We can take a screenshot of the canvas or a specific canvas area and compare it with a baseline. For Canvas-heavy applications, this can be useful, because some bugs are visible only visually: broken rendering, missing objects, wrong color, clipped animation, or visual artifacts.</p><p>But visual testing does not solve everything.</p><p>A screenshot can show that something changed, but it does not always explain why. In games or interactive applications, two screenshots can be different simply because:</p><ul><li>The animation was captured on a different frame;</li><li>The round result was random;</li><li>The application had not reached the required state yet;</li><li>rendering differs slightly between environments;</li><li>The test took the screenshot too early.</li></ul><p>So a screenshot can be a good additional check, but I would not build the entire automation strategy only around visual comparison.</p><p>Especially if the scenario is not only about the image, but also about the logic: the bet was placed, the request was sent, the result came back, the balance was updated, and the game returned to the idle state.</p><h3>Why application state matters</h3><p>In many Canvas and Pixi.js applications, the most reliable source of information is not the DOM and not the screenshot. It is the internal application state.</p><p>For example, a Pixi.js application can contain:</p><ul><li>sprites;</li><li>containers;</li><li>scenes;</li><li>buttons;</li><li>reels;</li><li>symbols;</li><li>animations;</li><li>game state;</li><li>balance state;</li><li>round result;</li><li>loading state.</li></ul><p>If the test can access this state, it becomes much more stable.</p><p>Instead of asking:</p><p>“Is there a Spin text in the DOM?”</p><p>We can ask:</p><p>“Is the Spin button available inside the Pixi.js stage?”</p><p>Instead of asking:</p><p>“Did the screenshot change?”</p><p>We can check:</p><p>“Did the game state move from idle to spinning, then to result, and then back to idle?”</p><p>Instead of a fixed wait:</p><pre>await page.waitForTimeout(5000);</pre><p>It is better to wait for a real state:</p><pre>await page.waitForFunction(() =&gt; window.app.game.state === &#39;idle&#39;);</pre><p>In Cypress, a similar idea can look like this:</p><pre>cy.window()<br>  .its(&#39;app.game.state&#39;)<br>  .should(&#39;eq&#39;, &#39;idle&#39;);</pre><p>This is a different level of automation. We stop treating the canvas as a black box and start testing the application through its real states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eMapiS-dfMAzYC_h4YMR0w.png" /></figure><h3>Dynamic coordinates instead of hardcoded coordinates</h3><p>Coordinates are not always bad by themselves. The problem is not that we use mouse clicks. The problem is that we click a hardcoded point without knowing where the object actually is.</p><p>If the application uses Pixi.js, we can try to find the object inside the Pixi stage and get its current position.</p><p>For example, in Playwright:</p><pre>const buttonPosition = await page.evaluate(() =&gt; {<br>  const button = window.app.stage.getChildByName(&#39;spinButton&#39;);<br>  return {<br>      x: button.worldTransform.tx,<br>      y: button.worldTransform.ty<br>  };<br>});<br>await page.mouse.click(buttonPosition.x, buttonPosition.y);</pre><p>In Cypress, the idea is similar:</p><pre>cy.window().then((win) =&gt; {<br>  const button = win.app.stage.getChildByName(&#39;spinButton&#39;);<br>  const { x, y } = button.worldTransform;<br>  cy.get(&#39;canvas&#39;).click(x, y);<br>});</pre><p>This is already better than simply clicking (960, 540), because the position is taken from the application at runtime. If the layout changes slightly, the test may still work.</p><p>Of course, the application needs to be at least somewhat testable. Objects should have meaningful names or metadata. The team needs to agree on which elements can be found and how they should be accessed.</p><p>But when this is done, Canvas automation becomes much more manageable.</p><h3>Test hooks - when you want less magic</h3><p>In some cases, it is better not to guess the Pixi application structure and instead add test hooks.</p><p>For example:</p><pre>window.__TEST_APP__ = {<br>  getGameState: () =&gt; game.state,<br>  getButtonPosition: (name) =&gt; ui.getButton(name).position,<br>  getBalance: () =&gt; wallet.balance,<br>  getLastRoundResult: () =&gt; game.lastRoundResult<br>};</pre><p>Then the test can work with a clean testing API instead of touching the internal implementation directly.</p><p>In Playwright:</p><pre>await page.waitForFunction(() =&gt; {<br>  return window.__TEST_APP__.getGameState() === &#39;idle&#39;;<br>});</pre><p>In Cypress:</p><pre>cy.window().then((win) =&gt; {<br>  expect(win.__TEST_APP__.getGameState()).to.eq(&#39;idle&#39;);<br>});</pre><p>This is not always possible. Sometimes we do not have access to the application code. Sometimes the team does not want to add test-only logic. Sometimes there is a risk of exposing too much in production.</p><p>But when test hooks are designed carefully, they make life much easier. Especially in large Canvas/Pixi.js products, where normal DOM selectors are almost useless.</p><h3>Combining UI actions, application state, and network requests</h3><p>In practice, I would not build Canvas automation around only one approach.</p><p>If the test relies only on coordinates, it is fragile.<br>If it relies only on visual testing, it is hard to understand the reason for a failure.<br>If it relies only on internal state, there is a risk of testing implementation instead of the user scenario.</p><p>A more reliable option is to combine several levels of verification.</p><p>For example, in a game interface, the user clicks Spin. For the E2E tool, this may not be a real DOM button, but an object inside the canvas. But the scenario does not end with the click.</p><p>After the click, the application can:</p><ul><li>send a request to the backend;</li><li>receive the round result;</li><li>update the balance;</li><li>show animation;</li><li>move to the spinning state;</li><li>then move to result;</li><li>then return to idle.</li></ul><p>In Playwright, it can look like this:</p><pre>const spinResponsePromise = page.waitForResponse(response =&gt;<br>  response.url().includes(&#39;/api/game/spin&#39;) &amp;&amp;<br>  response.status() === 200<br>);<br><br>await clickPixiObject(page, &#39;spinButton&#39;);<br>const spinResponse = await spinResponsePromise;<br>const spinResult = await spinResponse.json();<br>await waitForGameState(page, &#39;spinning&#39;);<br>await waitForGameState(page, &#39;result&#39;);<br>expect(spinResult).toHaveProperty(&#39;roundId&#39;);<br>expect(spinResult).toHaveProperty(&#39;winAmount&#39;);</pre><p>In Cypress, a similar idea can be implemented with cy.intercept:</p><pre>cy.intercept(&#39;POST&#39;, &#39;**/api/game/spin&#39;).as(&#39;spinRequest&#39;);<br>cy.window().then((win) =&gt; {<br>  const button = win.app.stage.getChildByName(&#39;spinButton&#39;);<br>  const { x, y } = button.worldTransform;<br>  cy.get(&#39;canvas&#39;).click(x, y);<br>});<br>cy.wait(&#39;@spinRequest&#39;)<br>  .its(&#39;response.statusCode&#39;)<br>  .should(&#39;eq&#39;, 200);<br>cy.window()<br>  .its(&#39;app.game.state&#39;)<br>  .should(&#39;eq&#39;, &#39;result&#39;);</pre><p>Here, we are not only checking that we clicked somewhere. We connect the user action with real system behavior:</p><ul><li>The click was performed on the correct object;</li><li>The expected network request was sent;</li><li>The backend returned a successful response;</li><li>The application moved to the expected state;</li><li>The UI was able to show the round result.</li></ul><p>This is much closer to real E2E testing than a simple waitForTimeout.</p><p>But it is also important not to overuse this. A network request alone does not prove that the user saw the correct result. It only confirms that one part of the scenario happened.</p><p>That is why I prefer to combine things:</p><pre>await clickPixiObject(page, &#39;spinButton&#39;);<br>await waitForResponseByUrl(page, &#39;/api/game/spin&#39;);<br>await waitForGameState(page, &#39;result&#39;);<br>await expectBalanceToBeUpdated(page);</pre><p>In a normal DOM application, we can often verify the scenario through locators. In a Canvas application, we need a more hybrid model: the action can be performed through a Pixi.js object, synchronization can happen through a network request, and the final check can be done through state, screenshot, or an exposed test hook.</p><p>In my opinion, this combination is what makes Canvas automation really useful. We are not just clicking pixels. We are checking product behavior on several levels.</p><h3>What a hybrid approach can look like</h3><p>If we put everything together, the flow can look like this:</p><ol><li>The E2E tool opens the application and waits until it is ready.</li><li>The test gets access to Pixi.js objects or test hooks.</li><li>The required object is found inside the canvas/application layer, not by a DOM selector.</li><li>Coordinates are calculated dynamically.</li><li>The click is performed through Playwright mouse events or Cypress canvas click.</li><li>The test waits for the required network request.</li><li>Then it waits for the application state to change.</li><li>After that, it verifies the result through state, test hook, or screenshot.</li></ol><p>In simplified form:</p><pre>await openGame();<br>await waitForGameState(&#39;idle&#39;);<br>await Promise.all([<br>  waitForResponseByUrl(&#39;/api/game/spin&#39;),<br>  clickPixiObject(&#39;spinButton&#39;)<br>]);<br>await waitForGameState(&#39;spinning&#39;);<br>await waitForGameState(&#39;result&#39;);<br>const balance = await getBalance();<br>expect(balance).toBeGreaterThanOrEqual(0);</pre><p>This is not a perfect universal formula for every project. Some projects will need more visual testing. Some will need more network checks. Some can have good test hooks. Some will have to work almost blindly with coordinates and screenshots.</p><p>But the main principle is the same: do not rely on only one source of truth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owEaEJCRIRqd3k_Y7SIIuw.png" /></figure><h3>Why Pixi.js is interesting for automation</h3><p>Pixi.js is interesting because it has its own internal structure — a scene graph.</p><p>Even if the DOM contains only one canvas, the application can contain containers, sprites, text objects, buttons, scenes, and other display objects inside Pixi.js.</p><p>So the DOM may know nothing about the Spin button, but Pixi.js may know.</p><p>If objects have names, properties, or metadata, tests can use that:</p><pre>const spinButton = window.app.stage.getChildByName(&#39;spinButton&#39;);</pre><p>or:</p><pre>const currentScene = window.app.game.currentScene;</pre><p>or:</p><pre>const balance = window.app.store.wallet.balance;</pre><p>Of course, in a real project, everything depends on the application architecture. In one project, the object can be found directly. In another, we need to recursively search the stage. In another, the state is stored in a store. In another, we need a separate test helper layer.</p><p>But the idea is important: if the interface is not represented in the DOM, it does not mean it cannot be tested. We just need to find another access layer.</p><h3>Where this approach is especially useful</h3><p>Canvas automation is useful not only for slots or casino games.</p><p>Similar problems appear in different types of products:</p><ul><li>online gaming platforms;</li><li>casino and slot games;</li><li>interactive dashboards;</li><li>trading interfaces;</li><li>map-based applications;</li><li>educational simulations;</li><li>design tools;</li><li>visual editors;</li><li>real-time visual applications.</li></ul><p>In these systems, the visual layer is not just a picture. Very often, it contains an important part of the user scenario.</p><p>If we test only the backend, we do not know whether the user actually saw the correct result.<br>If we test only the DOM, we may not reach the main logic at all.<br>If we test only screenshots, we may get many flaky results.</p><p>That is why Canvas/Pixi.js automation requires a more engineering-focused approach.</p><h3>Conclusion</h3><p>Testing Canvas and Pixi.js applications is difficult, not because Playwright or Cypress are bad tools. The problem is that the standard web testing model expects the DOM, while a Canvas application often hides the main interface inside a rendering engine.</p><p>Normal selectors, text locators, role-based locators, and data-testid can be useless if the whole logic is drawn inside one canvas.</p><p>Coordinates help to start quickly, but they become fragile when the layout changes. Visual testing is useful, but it does not always explain the reason for a failure. State-based waiting makes tests more stable, but it requires access to internal state. Network waits help synchronize the test with backend behavior, but they do not verify the UI by themselves.</p><p>In practice, the best option is a hybrid approach:</p><pre>Canvas automation = E2E tool + Pixi.js objects + dynamic coordinates + app state + network waits + visual checks where needed</pre><p>The E2E tool can be Playwright, Cypress, or another framework. The main challenge is not the framework itself, but the fact that a Canvas application does not give us the usual DOM model for testing.</p><p>This is not a silver bullet. But this approach can significantly reduce flaky tests and make Canvas automation much closer to real product behavior.</p><p>In the next article, I want to show the practical part: how to build a small helper layer for a Pixi.js application, find objects inside the stage, calculate coordinates, wait for game states, and combine this with network checks. The examples can be shown for both Playwright and Cypress, because the problem itself does not depend on a specific E2E framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b95474640633" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>