<?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 Sunu Eric on Medium]]></title>
        <description><![CDATA[Stories by Sunu Eric on Medium]]></description>
        <link>https://medium.com/@sunuerico?source=rss-2609d99150d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Sunu Eric on Medium</title>
            <link>https://medium.com/@sunuerico?source=rss-2609d99150d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:53:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunuerico/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[From Kotlin to BrightScript: How I Ported a Modern Android TV App to Roku]]></title>
            <link>https://medium.com/@sunuerico/from-kotlin-to-brightscript-how-i-ported-a-modern-android-tv-app-to-roku-bdf24f31809a?source=rss-2609d99150d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdf24f31809a</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[smart-tv]]></category>
            <category><![CDATA[roku]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Sunu Eric]]></dc:creator>
            <pubDate>Fri, 06 Feb 2026 14:26:12 GMT</pubDate>
            <atom:updated>2026-02-06T14:26:12.611Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="From Kotlin to BrightScript: How I Ported a Modern Android TV App to Roku" src="https://cdn-images-1.medium.com/max/1024/1*x5EQ-Z9gHOKcHe9cFgg2rA.png" /><figcaption>From Kotlin to BrightScript: How I Ported a Modern Android TV App to Roku</figcaption></figure><p>We were having our daily standup when my boss dropped a suggestion that would <strong>define my next three months</strong>.</p><p>“We need to tap more into the US market,” he said. “We should really build this on Roku.”</p><p>We built <strong>LiveSpaces</strong>, a digital signage solution that turns screens into remotely controlled billboards. We already had a polished, modern Android TV app built with <strong>Kotlin</strong> and <strong>Jetpack Compose</strong>. It was reactive, declarative, and beautiful.</p><p>Then came the kicker. <em>“How hard can it be?”</em> I thought to myself as the meeting wrapped up. <em>“Roku holds roughly 50% of the connected TV market in the United States. If we’re targeting the waiting room or the hotel lobby in the West, we can’t ignore the purple box. I’ll probably just find a cross-platform library, wrap our existing logic, and ship it.”</em></p><p>I was dead wrong.</p><h3>First Contact: No IDE, Just a Zip File</h3><p>I went to download the SDK, expecting an installer like Android Studio or Xcode. Instead, the documentation just said:</p><p><em>“To get started, download the Hello World sample app and unzip it…”</em></p><p>That was it. No heavy environment. Just a folder structure that looked like this:</p><ul><li><strong>components/</strong>: The XML files that define the layout (SceneGraph).</li><li><strong>source/</strong>: The BrightScript code (the logic).</li><li><strong>images/</strong>: Assets and splash screens.</li><li><strong>manifest</strong>: The app configuration.</li></ul><p>It felt raw. To write code, I couldn’t use a dedicated Roku IDE because one doesn’t really exist. I fired up <strong>VS Code</strong> and installed the <strong>BrightScript Extension</strong>.</p><p>The docs pitched it as a “suite of tools,” and to be fair, the community extension for VS Code is a lifesaver: it gives you debugging, code formatting, and a telnet log. But coming from the rich, auto-completing embrace of Android Studio, I felt like I had been handed a text editor and a prayer</p><h3>The Stack: A Primer for Web &amp; Android Devs</h3><p>Before diving into the bugs, you need to understand what “Native Roku Development” actually looks like. It relies on two pillars: <strong>BrightScript</strong> and <strong>SceneGraph</strong>.</p><p>If you come from the <strong>Web World</strong>, think of <strong>SceneGraph</strong> as the HTML DOM. It is a tree of nodes defined in XML. <strong>BrightScript</strong> is the JavaScript, it’s the scripting language used to manipulate those nodes. But unlike React or Vue, there is no Virtual DOM or data binding engine. You are manually selecting nodes and updating their properties, closer to the days of jQuery.</p><p>If you come from Android, think of <strong>SceneGraph</strong> as the old res/layout XML system, but strictly enforced. There is no Jetpack Compose here. BrightScript is your Java/Kotlin, but with syntax that looks like Visual Basic. It’s case-insensitive, uses End Sub and End If, and has no concept of generic types.</p><h3>The Paradigm Shift: Reactive vs. The Node Tree</h3><p>The hardest part of the migration was the shift in mental model. In Android, I live in a world of Coroutines, Flow, and StateFlow. If I want to update the UI, I update the state, and the UI reacts.</p><p>Roku uses <strong>SceneGraph</strong>. It’s a node-based architecture. But here is the catch: <strong>Threading is manual and strict.</strong></p><h3>1. Concurrency: Coroutines vs. Task Nodes</h3><p>In Android, fetching data is a simple suspend function.</p><p><strong>Android (Kotlin):</strong></p><pre>// Modern and clean<br>viewModelScope.launch {<br>    val data = repository.fetchPlaylist()<br>    _uiState.value = data<br>}</pre><p>On Roku, you can’t just run a background thread. You have to create a <strong>Task Node</strong> (literally an XML file representing a thread), spin it up, pass it data, and then have your main thread <em>observe</em> a field on that task to see when it changes.</p><p><strong>Roku (BrightScript):</strong></p><pre>&#39; 1. Create the task object<br>m.contentTask = CreateObject(&quot;roSGNode&quot;, &quot;ContentTask&quot;)<br>&#39; 2. Set the observer (callback)<br>m.contentTask.observeField(&quot;response&quot;, &quot;onContentResponse&quot;)<br>&#39; 3. Trigger the task<br>m.contentTask.control = &quot;RUN&quot;</pre><h3>2. The Missing Operators</h3><p>I caught myself constantly trying to use Kotlin conveniences. I’d type:</p><pre>m.top.posterUri = item.thumbnail_url ?? &quot;pkg:/images/placeholder.png&quot;</pre><p>BrightScript: <em>“We don’t do that here.”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*acTfuNe176A3iehR.jpg" /></figure><p>I had to write helper functions just to check if a string was valid without crashing the app.</p><h3>The Trenches: 3 Bugs That Almost Broke Me</h3><p>Developing for digital signage is different from developing a streaming app like Netflix. Netflix expects you to watch for 2 hours and turn it off. Digital signage runs <strong>24/7</strong>. It must never sleep, never crash, and never complain.</p><p>Here are the specific technical hurdles I hit, and the “MacGyver” workarounds I used to fix them.</p><h3>Bug #1: The “Double JSON” Parsing Error</h3><p><strong>The Issue</strong>: One of the data streams we consumed had a serialization inconsistency. Specifically, JSON data sometimes arrived as native JSON objects, and other times as Strings containing JSON.</p><p><strong>Scenario A:</strong> API returns “{ &#39;id&#39;: 1 }&quot; (String)</p><p><strong>Scenario B</strong>: API returns { &#39;id&#39;: 1 } (Object)</p><p><strong>The Roku Crash</strong>: Roku’s ParseJson() is strict. If you pass it an object that is already parsed, or try to access properties on a string as if it were an object, the app crashes immediately.</p><p><strong>The Fix:</strong> I implemented “Defensive Parsing” logic that checks the type at runtime.</p><pre>&#39; The &quot;Double Parse&quot; Workaround<br>if type(serverData.payload) = &quot;roString&quot;<br>    &#39; It is a string, so we must parse it manually<br>    serverData.payload = ParseJson(serverData.payload)<br>else if type(serverData.payload) = &quot;roAssociativeArray&quot;<br>    &#39; It is already an object, do nothing<br>end if</pre><h3>Bug #2: The Battle Against the Screensaver</h3><p><strong>The Issue:</strong> Roku is aggressive about preventing screen burn-in. If no user input is detected for 10 minutes, the screensaver kicks in. For a digital signage app, this is a death sentence.</p><p><strong>The Complication</strong>: While we advise our users to maximize their screensaver timeout settings, many Roku devices generally do not offer a “Never” option in the consumer menu. The OS will eventually force a sleep mode if no media is playing.</p><p><strong>The Failed Attempt:</strong> I tried setting screensaver_mode=disabled in the manifest. While documented, this flag is often ignored by the OS or flagged by the Store Certification team as a policy violation.</p><p><strong>The Solution:</strong> I found a legendary hack deep in the developer forums. <strong>The 1x1 Pixel Ghost Video.</strong></p><p>Roku will not trigger the screensaver if a video is playing. So, I created a component that plays a video that is invisible to the human eye but visible to the OS.</p><pre>&lt;!-- MainScene.xml --&gt;<br>&lt;Video <br>    id=&quot;keepAwakeVideo&quot; <br>    uri=&quot;pkg:/images/silent_1sec_black.mp4&quot; <br>    width=&quot;1&quot; <br>    height=&quot;1&quot; <br>    translation=&quot;[-10, -10]&quot; <br>    opacity=&quot;0.01&quot; <br>    loop=&quot;true&quot; /&gt;</pre><p><em>Logic:</em> It’s 1 pixel wide, 99% transparent, positioned off-screen, and loops forever.<br><em>Result:</em> The Roku thinks, “The user is watching a movie,” and keeps the screen awake 24/7.</p><h3>Bug #3: No WebViews Allowed</h3><p><strong>The Issue:</strong> Our Android app relies heavily on WebView components to render <strong>dynamic web dashboards</strong>, embedded presentation slides, and third-party widgets.</p><p><strong>The Reality:</strong> Roku <strong>does not support WebViews.</strong> Period. There is no HTML rendering engine available to developers in the SDK. You cannot simply “embed” a website.</p><p><strong>The Workaround:</strong> We had to implement a simple fallback system.<br>If the content type is “Web Page,” the Roku app automatically generates a QR Code using an external API (api.qrserver.com).<br>The UI displays a message: <em>“Web content not natively supported on Roku. Scan to view on mobile.”</em></p><p>It wasn’t the seamless experience we had on Android, but it saved the feature from being cut entirely.</p><h3>UI Limitations: The Font Struggle</h3><p>Polishing the UI made me miss Jetpack Compose dearly.</p><p>In Compose, if I want a text header to be 24sp, I just write fontSize = 24.sp.</p><p>On Roku, you technically <em>can</em> use custom fonts, but the implementation is incredibly verbose. According to the docs, you have to define a Font node, set the URI to a .ttf file, and assign it to the label.</p><pre>&lt;!-- The XML way --&gt;<br>&lt;Label&gt;<br>  &lt;Font role=&quot;font&quot; uri=&quot;pkg:/fonts/my_font.ttf&quot; size=&quot;24&quot; /&gt;<br>&lt;/Label&gt;</pre><p>But what if you just want to use the System font, but slightly bigger?<br>Roku provides presets like MediumBoldSystemFont or LargeSystemFont. But if Large is too small and ExtraLarge is too big, you are stuck.</p><p>To get our branding right without importing custom TTF files for every single variation, I ended up using a programmatic override in the BrightScript logic:</p><pre>&#39; The BrightScript way: Manually instantiating nodes<br>label = CreateObject(&quot;roSGNode&quot;, &quot;Label&quot;)<br>font  = CreateObject(&quot;roSGNode&quot;, &quot;Font&quot;)<br>font.uri = &quot;font:MediumBoldSystemFont&quot; &#39; Start with a preset<br>font.size = 58 &#39; Override the size manually<br>label.font = font</pre><p>It works, but it’s 5 lines of code for what takes 1 line in Compose.</p><h3>The Verdict: Android vs. Roku</h3><p>After three months of wrestling with the emulator and finally testing on a real TV, I created this mental map for any Android dev attempting this migration:</p><p>FeatureAndroid TV (Kotlin)Roku (BrightScript)<strong>Threading</strong>Coroutines (Easy)Task Nodes (Manual, XML-based)<strong>State</strong>StateFlow / LiveDataobserveField (Callback hell)<strong>HTML</strong>WebView (Full support)<strong>Unsupported</strong> (QR Code fallback)<strong>Fonts</strong>.ttf / Dynamic SizingVerbose XML setup or Manual overrides<strong>Memory</strong>Robust Garbage CollectionStrict ref-counting (Watch for mem leaks!!)<strong>Background</strong>WorkManager<strong>None</strong> (App freezes on exit)</p><h3>My Advice to My Past Self</h3><p>If I could travel back in time back to November, I would tell myself:</p><p>“Don’t fight the platform. It is not Android.”</p><p>In the beginning, I tried to force Android architecture patterns (MVVM, Repositories) into BrightScript, and it caused nothing but friction. Once I accepted <strong>SceneGraph</strong> for what it was: a hierarchical, event-driven state machine, the code started to flow.</p><p>It’s like learning a language from a different era. It requires patience, but there is a strange satisfaction in mastering its strict rules. Plus, seeing our app running flawlessly on a $25 device in a busy hotel lobby? That makes the struggle worth it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdf24f31809a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Comprehensive E2E Test Suite with Playwright: Lessons from 100+ Test Cases]]></title>
            <link>https://medium.com/@sunuerico/building-a-comprehensive-e2e-test-suite-with-playwright-lessons-from-100-test-cases-975851932218?source=rss-2609d99150d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/975851932218</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[playwright-automation]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Sunu Eric]]></dc:creator>
            <pubDate>Tue, 25 Nov 2025 00:14:22 GMT</pubDate>
            <atom:updated>2025-12-03T11:28:55.844Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Building a Comprehensive E2E Test Suite with Playwright: Lessons from 100+ Test Cases" src="https://cdn-images-1.medium.com/max/1024/1*kZUw7WXQfzpJGO6xhShpkg.png" /></figure><h3>The Journey</h3><p>While developing the platform for <strong>LiveSpaces</strong>, I identified a critical gap in our delivery workflow. As the application grew, our reliance on manual verification and our existing CI/CD checks proved insufficient. We needed a way to streamline release cycles without sacrificing quality.</p><p>I took the initiative to build a comprehensive End-to-End (E2E) test suite using <a href="https://playwright.dev/"><strong>Playwright</strong></a>, but I underestimated the complexity. It wasn’t just about clicking buttons; it was about handling authentication flows, managing device states, and dealing with third-party integrations securely and reliably.</p><p>From authentication flows to device management, every feature presented unique challenges. Here is a retrospective on the architecture I built to solve these bottlenecks, the decisions I made, and the lessons I learned.</p><h3>Prerequisites</h3><p>This post focuses on <strong>advanced patterns and architectural decisions</strong> rather than basic installation. I assume you are familiar with the basics of Playwright or similar E2E tools (Cypress, Selenium).</p><p>If you are brand new to Playwright, I highly recommend checking out the <a href="https://playwright.dev/docs/intro"><strong>official documentation</strong></a> first.</p><p><strong>Quick Context:</strong> The examples below use:</p><ul><li><strong>Framework:</strong> Playwright (Node.js)</li><li><strong>Language:</strong> JavaScript/TypeScript</li><li><strong>Pattern:</strong> Page Object Model (POM)</li></ul><h3>What I Built</h3><h3>100+ Test Cases Across 6 Major Areas</h3><ol><li><strong>Email Signup Flow</strong> — The complete journey from registration to business setup.</li><li><strong>OAuth Integration</strong> — Signup and signin flows with comprehensive mocking.</li><li><strong>Device Pairing</strong> — Device pairing logic using 6-character OTP codes.</li><li><strong>Device Management</strong> — Renaming, deleting, and managing device settings.</li><li><strong>Account Type Selection</strong> — Complex modal handling for onboarding flows.</li><li><strong>Business Information Forms</strong> — Industry, demographics, and capacity selection logic.</li></ol><h3>Key Challenges &amp; Solutions</h3><h3>Challenge 1: Email Verification in Tests</h3><p><strong>The Problem</strong>: I could not access real email inboxes (Gmail/Outlook) reliably in automated tests. Using real inboxes made the tests slow, flaky, and prone to security blocks.</p><p><strong>The Solution</strong>: I implemented a smart mocking strategy.</p><ul><li><strong>Development</strong>: I mocked the email verification endpoint to return a fixed success response.</li><li><strong>Production/Integration</strong>: I documented hooks for services like <a href="https://mailosaur.com/"><strong>Mailosaur</strong></a> for when real delivery testing is strictly necessary.</li></ul><p><strong>Code Example:</strong></p><pre>// Mock the verification code endpoint to bypass email delivery<br>await page.route(&#39;**/api/verification/send&#39;, route =&gt; {<br>  route.fulfill({<br>    status: 200,<br>    body: JSON.stringify({<br>      success: true,<br>      code: &#39;123456&#39; // Fixed mock code for testing<br>    })<br>  });<br>});</pre><h3>Challenge 2: OAuth Testing</h3><p><strong>The Problem</strong>: Automating third-party providers (Google, Facebook) is often a violation of their Terms of Service. Furthermore, dealing with 2FA, captchas, or external popups leads to incredibly flaky tests.</p><p><strong>The Solution</strong>: Comprehensive OAuth flow mocking. Instead of visiting the provider, I intercepted the callback that the provider <em>would</em> have sent to our application.</p><p><strong>Code Example:</strong></p><pre>// Mock the OAuth callback<br>await page.route(&#39;**/api/auth/oauth/callback**&#39;, route =&gt; {<br>  const url = new URL(route.request().url());<br>// If the app is trying to exchange a token, give it a mock user<br>  if (url.searchParams.has(&#39;access_token&#39;)) {<br>    route.fulfill({<br>      status: 200,<br>      body: JSON.stringify({<br>        jwt: &#39;mock_jwt_token&#39;,<br>        user: { id: 123, email: &#39;test@example.com&#39; }<br>      })<br>    });<br>  }<br>});</pre><h3>Challenge 3: Integration vs. Mocked Tests</h3><p><strong>The Problem</strong>: I needed fast feedback loops during development (mocks) but actual verification before deployment (integration). I didn’t want to maintain two separate test suites.</p><p><strong>The Solution</strong>: <strong>Dual-mode test files.</strong> I designed the tests to auto-detect the presence of an authentication token in the environment variables to decide whether to mock network requests or hit the real backend.</p><p><strong>The Logic Flow:</strong></p><figure><img alt="Dual-mode flowchart" src="https://cdn-images-1.medium.com/max/960/1*Atbrks2uzZn9hmdPvlYFyA.png" /></figure><p><strong>Code Example:</strong></p><pre>const AUTH_TOKEN = process.env.AUTH_TOKEN;<br>const USE_REAL_BACKEND = !!AUTH_TOKEN;<br><br>test.beforeEach(async ({ page }) =&gt; {<br>  if (USE_REAL_BACKEND) {<br>    console.log(&#39;Using REAL backend&#39;);<br>    // No mocks; allow requests to pass through<br>  } else {<br>    console.log(&#39;Using MOCKED mode&#39;);<br>    // Apply mocks defined in separate helper files<br>    await applyNetworkMocks(page); <br>  }<br>});</pre><h3>Challenge 4: Test Data Cleanup</h3><p><strong>The Problem</strong>: Integration tests running against a real backend leave behind “zombie” data (e.g., created devices), causing subsequent tests to fail due to duplicate name errors or database bloat.</p><p><strong>The Solution</strong>:</p><ul><li>Strict try/finally blocks for guaranteed cleanup within the test.</li><li><em>(Pro Tip: For larger suites, moving this logic into </em><a href="https://playwright.dev/docs/test-fixtures"><em>Playwright Fixtures</em></a><em> is the preferred pattern).</em></li></ul><p><strong>Code Example:</strong></p><pre>test(&#39;should create and manage device&#39;, async ({ page, request }) =&gt; {<br>  let testDeviceId = null;<br><br>try {<br>    // 1. Create test device via API<br>    const response = await request.post(`${API_URL}/devices`, {<br>      headers: { Authorization: `Bearer ${AUTH_TOKEN}` },<br>      data: { name: &#39;Test Device&#39;, code: &#39;TEST123&#39; }<br>    });<br>    testDeviceId = (await response.json()).data.id;<br>    // 2. Test the UI flow interacting with this device...<br>    await page.reload();<br>    await expect(page.getByText(&#39;Test Device&#39;)).toBeVisible();<br>  } finally {<br>    // 3. Always cleanup, even if the assertion above fails<br>    if (testDeviceId) {<br>      await request.delete(`${API_URL}/devices/${testDeviceId}`, {<br>        headers: { Authorization: `Bearer ${AUTH_TOKEN}` }<br>      });<br>    }<br>  }<br>});</pre><h3>Challenge 5: Async Component Loading</h3><p><strong>The Problem</strong>: Third-party components (maps, heavy charts) often load asynchronously. Tests were failing because they tried to interact with elements before they were truly interactive.</p><p><strong>The Solution</strong>:</p><ul><li>Use explicit synchronization points with locator.waitFor()</li><li>Avoid waitForTimeout (hard sleeps)</li><li>Distinguish between <em>assertions</em> (expect) and <em>waiting</em> (waitFor)</li></ul><p><strong>Result</strong>: Reliable tests that handle real-world timing without flakiness.</p><p>- Use explicit synchronization points with `locator.waitFor()`<br>- Avoid `waitForTimeout` (hard sleeps)<br>- Distinguish between *assertions* (`expect`) and *waiting* (`waitFor`)</p><p><strong>Code Example:</strong></p><pre>const mapInput = page.getByTestId(&#39;map-input&#39;);<br><br>// ❌ Bad Practice: Hard wait<br>// await page.waitForTimeout(1000);<br><br>// ❌ Common Mistake: Using assertion as a wait<br>// await expect(mapInput).toBeVisible(); // This is an assertion, not a strict wait step<br><br>// ✅ Best Practice: Explicit synchronization<br>// Wait specifically for the element to be ready before proceeding<br>await mapInput.waitFor({ state: &#39;visible&#39;, timeout: 10000 });<br><br>// Now safe to interact<br>await mapInput.click();</pre><h3>Challenge 6: Portal-Based UI Components</h3><p><strong>The Problem</strong>: Modern UI libraries (like <a href="https://www.radix-ui.com/"><strong>Radix UI</strong></a> or Headless UI) often render dropdowns and modals in “portals” at the bottom of the &lt;body&gt; tag, physically outside the component that triggered them.</p><p><strong>The Solution</strong>:</p><ul><li>I used specific ARIA roles.</li><li>I scoped locators correctly to escape the current container and search the document root.</li></ul><p><strong>Code Example:</strong></p><pre>// The dropdown trigger is in the main container<br>await page.getByRole(&#39;button&#39;, { name: &#39;Options&#39; }).click();<br><br>// The menu itself is in a portal at the document root<br>// We wait for the menu specifically to be visible<br>const menu = page.getByRole(&#39;menu&#39;);<br>await expect(menu).toBeVisible();<br><br>// Click the item inside the menu<br>await menu.getByRole(&#39;menuitem&#39;, { name: &#39;Rename&#39; }).click();</pre><h3>What Worked Really Well</h3><h3>1. Page Object Model (POM) Pattern</h3><p>Centralizing selectors in reusable classes was the single highest-ROI decision I made. When the UI changed (and it did often), I updated one file instead of 20.</p><p><strong>The Architecture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2CUdhpUeZv0sfW8Ah0xZg.png" /></figure><p><strong>Code Example:</strong></p><pre>// pages/AuthPage.js<br>export class AuthPage {<br>  constructor(page) {<br>    this.page = page;<br>    this.emailInput = page.getByPlaceholder(&#39;name@example.com&#39;);<br>    this.loginButton = page.getByRole(&#39;button&#39;, { name: &#39;Login&#39; });<br>  }<br><br>  async login(email, password) {<br>    await this.emailInput.fill(email);<br>    await this.loginButton.click();<br>  }<br>}</pre><h3>2. Comprehensive Documentation</h3><p>Tests without documentation become legacy code the moment they are written. I created 15+ markdown files covering “How to run,” “How to mock,” and “How to debug.” This dramatically reduced onboarding time for future developers and prevented “fear of the test suite.”</p><h3>3. Error Case Testing</h3><p>Testing the “Happy Path” is easy. Testing the “Sad Path” is where value lies. I systematically mocked 404s, 500s, and network timeouts to ensure the UI handled errors gracefully (e.g., showing Toast notifications) rather than crashing.</p><h3>4. Dual-Mode Testing</h3><p>By using environment variables to switch between Mocks and Real Backends, a single test file serves as both a <strong>Unit-like Test</strong> (Mocked: fast, stable, deterministic) and an <strong>Integration Test</strong> (Real: slower, verifies backend contracts).</p><h3>Key Learnings &amp; Tips</h3><ol><li><strong>Mock External Services</strong>: Never test Google’s login page. Mock the OIDC response. You are testing <em>your</em> app, not Google’s uptime.</li><li><strong>Prioritize User-Visible Locators</strong>: Use getByRole and getByText over CSS classes (.btn-primary). This mimics how users find elements and makes tests resilient to styling refactors.</li><li><strong>Always Cleanup</strong>: Test data pollution causes flaky tests. If you create it, delete it (preferably in a finally block or a fixture).</li><li><strong>Wait Properly</strong>: Never use waitForTimeout(5000). If you find yourself doing this, you are likely missing a proper state assertion or an await expect(...).</li></ol><h3>The Numbers</h3><ul><li><strong>Test Files</strong>: 10+</li><li><strong>Test Cases</strong>: 100+</li><li><strong>Lines of Code</strong>: ~5,000+</li><li><strong>Coverage Areas</strong>: 6 major features</li><li><strong>Confidence Level</strong>: High</li></ul><h3>Further Reading</h3><p>If you want to dive deeper into the concepts mentioned here, I recommend these resources:</p><ul><li><a href="https://playwright.dev/docs/pom"><strong>Playwright Page Object Models</strong></a> — Official documentation on structuring tests.</li><li><a href="https://martinfowler.com/bliki/PageObject.html"><strong>Martin Fowler on Page Objects</strong></a> — The theory behind the pattern.</li><li><a href="https://mailosaur.com/docs"><strong>Mailosaur Documentation</strong></a> — For handling email in tests.</li><li><a href="https://kentcdodds.com/blog/the-testing-trophy-and-testing-classifications"><strong>The Testing Trophy</strong></a> — Kent C. Dodds’ approach to balancing static, unit, integration, and E2E tests.</li></ul><p><em>This post is based on real-world experience building a production E2E suite. All code examples are simplified for clarity.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=975851932218" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>