<?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 Theo McCauley on Medium]]></title>
        <description><![CDATA[Stories by Theo McCauley on Medium]]></description>
        <link>https://medium.com/@theomakaurii?source=rss-704d2c0d3b13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Kx4mt1DunEHXs43x</url>
            <title>Stories by Theo McCauley on Medium</title>
            <link>https://medium.com/@theomakaurii?source=rss-704d2c0d3b13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:07:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theomakaurii/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[Cypress Resource Potpourri]]></title>
            <link>https://medium.com/@theomakaurii/cypress-resource-potpourri-bcf9fb94e69d?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcf9fb94e69d</guid>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[applitools]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[cypressio]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Sun, 14 Nov 2021 19:33:49 GMT</pubDate>
            <atom:updated>2021-11-15T01:02:30.893Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LG79XkG6PKHNOHCB8m2Kgw.jpeg" /><figcaption>A medley of tutorials and insights to take your Cypress test suite to the next level</figcaption></figure><p>The Cypress.io framework will revolutionize your current testing library, but only if you wield it correctly. Whether you’re migrating from an existing framework or evolving your quality assurance from a manual approach, this digest will give you insight into the current community support and tools that will now be at your fingertips. In this post the articles listed will be covering Cypress basics, Auth0 authentication, testing mobile apps, testing drag &amp; drop functionality, and network edge cases.</p><h3><strong>Gleb Bahmutov’s cypress-workshop-basics:</strong></h3><p><a href="https://glebbahmutov.com/cypress-workshop-basics/">Gleb Bahmutov is one of the loudest and most supportive voices in the Cypress community. The following github repository will lead you through the process of getting started by installing Cypress all the way to writing your first custom command:</a></p><p><a href="https://github.com/bahmutov/cypress-workshop-basics">GitHub - bahmutov/cypress-workshop-basics: Basics of end-to-end testing with Cypress.io test runner</a></p><h3><strong>How to Test a Mobile Web App in Cypress:</strong></h3><p><a href="https://applitools.com/blog/how-to-test-mobile-web-app-cypress/?utm_source=linkedin&amp;utm_medium=organic-social&amp;utm_content=blog&amp;utm_term=applitools-cat-li&amp;utm_campaign=blog-how-to-test-mobile-web-app-cypress">When testing a mobile web app it is best to look at the application in terms of what distinguishes it from the desktop app. This blog post from Applitools will help you consider the essential characteristics of screen size, touch interface, and user agent when reinforcing your test library for mobile devices.</a></p><p><a href="https://applitools.com/blog/how-to-test-mobile-web-app-cypress/?utm_source=linkedin&amp;utm_medium=organic-social&amp;utm_content=blog&amp;utm_term=applitools-cat-li&amp;utm_campaign=blog-how-to-test-mobile-web-app-cypress">How to Test a Mobile Web App in Cypress</a></p><h3><strong>End-to-End Testing with Cypress and Auth0:</strong></h3><p><a href="https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/">It is inevitable the you will need to test features protected by user authentication. This post discusses how to authenticate against Auth0 in your Cypress end-to-end tests successfully. You will use a small sample React application to illustrate patterns you can use to programmatically log your user into Auth0 while running Cypress tests.</a></p><p><a href="https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/">End-to-End Testing with Cypress and Auth0</a></p><h3><strong>Drag and Drop:</strong></h3><p>Testing the drag and drop features of your app will be essential to your test suite, but the approach (while simple) might be a little dubious. This video tutorial from Applitools will guide you through the process of testing your first drag and drop story. You can also check out a forum discussion on the topic <a href="https://github.com/cypress-io/cypress-example-recipes/issues/173">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhvwYBlKLz6U%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhvwYBlKLz6U&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhvwYBlKLz6U%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c8a1b8c17b94d1dec1234b887471016/href">https://medium.com/media/1c8a1b8c17b94d1dec1234b887471016/href</a></iframe><h3><strong>Test network edge cases with .intercept() command:</strong></h3><p><a href="https://egghead.io/courses/test-network-edge-cases-with-cy-intercept-command-in-cypress-0fd94c68">Egghead.io offers a ton of tricks that can make your current testing plan much more dynamic. The linked post will teach you how to simulate a network condition, where an http request does not make it to the server. It will be important to assert that the app is showing your user the correct error message.</a></p><p><a href="https://egghead.io/courses/test-network-edge-cases-with-cy-intercept-command-in-cypress-0fd94c68">Test network edge cases with .intercept() command in Cypress</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcf9fb94e69d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Essential Custom Command]]></title>
            <link>https://medium.com/@theomakaurii/the-essential-custom-command-41d2c1d92fe?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/41d2c1d92fe</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[custom-commands]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[cypress]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Mon, 01 Nov 2021 19:23:10 GMT</pubDate>
            <atom:updated>2021-11-13T18:30:26.508Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJQQqk-Rf7OrvT6R4kGaEQ.jpeg" /></figure><p>Hey QA’s!</p><p>If you’ve been writing solid tests with Cypress then its no doubt that you’ve started garnishing your application code with data-cy selectors. These identifiers make your job easier by targeting specific containers more reliably than targeting CSS elements. If you’ve been following my posts from the begining you may have even decided to <a href="https://medium.com/@theomakaurii/how-to-avoid-brittle-testing-using-enum-type-constants-62da66090cb8">centralize your </a><a href="https://medium.com/@theomakaurii/how-to-avoid-brittle-testing-using-enum-type-constants-62da66090cb8">data-cy selectors by using a type enum.</a></p><p>Today I wanted to focus on optimizing your Cypress workflow even further by discussing one simple custom command which will make selecting containers even faster. We will do this by writing one custom command which will combine several steps and checks into a streamlined package.</p><p>If you haven’t delved too deep into writing custom commands then this blog post should serve as a useful tutorial for writing basic commands from scratch.</p><p>After installing the Cypress framework to your application you will be treated with a file hierarchy which will accept, but not expect, structure tampering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*6M-W87xPhFmqEK4juFIX0A.png" /><figcaption>For this exercise we are going to be working in the support folder.</figcaption></figure><p>If you haven’t ventured into the realm of custom commands with Cypress then you can use this opportunity to navigate into support &gt; command.js where you will find helpful examples of the basic skeleton needed to write custom parent, child and dual commands. You will also find an example needed to overwrite an existing Cypress command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBIygUDAnv2Z7jCe8HvJZQ.png" /><figcaption>ICYMI: The primary difference between parent and child commands is their ability to be chained directly from `cy.` (parent) or a predefined application element (child).</figcaption></figure><p>From here create and navigate to a new file in the support folder titled dataCy.js. Once you are graced with the blank canvas you can recreate the basic skeleton for a parent command. Replace the string in single quotes with the name of the command you are creating, and (for now) pass one argument which will act as the data-cy selector needed in the runtime scenario.</p><pre>Cypress.Commands.<strong>add</strong>(&#39;dataCy&#39;, (container) =&gt; {});</pre><p>From inside we can recreate the steps which you would otherwise rewrite a dozen time per test.</p><pre>Cypress.Commands.<strong>add</strong>(&#39;dataCy&#39;, (container) =&gt; {</pre><pre>cy.<strong>get</strong>(`[data-cy=${container}]`);</pre><pre>});</pre><p>This will save you the trouble of typing cy.<strong>get</strong>(`[data-cy=&#39;cy-selector&#39;]`) and instead offer a cleaner cy.dataCy(cy-selector). This is a quality of life improvement which is easily more human readable, but I wouldn’t consider it fully optimized just yet. So often in Cypress you will need to write guards in your test to ensure that you are selecting the correct container once it is rendered. Normally this can be accomplished by writing:</p><pre>cy.<strong>get</strong>(`[data-cy=&#39;parent-selector&#39;]`)<br>.find(`[data-cy=&#39;child-selector&#39;]`)</pre><p>OR</p><pre>cy.dataCy(cy-selector).find(`[data-cy=&#39;child-selector&#39;]`)</pre><p>This process will start to feel more cumbersome the longer you repeat it, and eventually you will be wishing you could simply pass a second argument to your custom command. WELL you CAN and SHOULD.</p><p>All you have to do is update your custom command to make this dream a reality.</p><pre>Cypress.Commands.<strong>add</strong>(&#39;dataCy&#39;, (parent, child) =&gt; {</pre><pre>cy.<strong>get</strong>(`[data-cy=${parent}]`).find(`[data-cy=${child}]`);</pre><pre>});</pre><p>Be warned! The custom command above will lead to a new problem. It will only function properly if you pass a parent and child argument everytime, and this might not always be necessary. This issue can be resolved by adding a conditional check that will verify whether a child argument is present.</p><pre>Cypress.Commands.<strong>add</strong>(&#39;dataCy&#39;, (parent, child) =&gt; {</pre><pre>if (child) {</pre><pre>cy.<strong>get</strong>(`[data-cy=${parent}]`).<strong>first</strong>().<strong>find</strong>(`[data-cy=${child}]`);</pre><pre>} else {</pre><pre>cy.<strong>get</strong>(`[data-cy=${parent}]`);</pre><pre>}</pre><pre>});</pre><p>Congratulations! You’ve just written your first custom command using Cypress. The command is prescient, and will be versatile depending on the needs of the overarching application environment.</p><p>One final note on a good practice when using custom commands. It should be obvious that they are incredibly powerful, but they are not always the best solution to a problem. When writing a custom command you should consider how many tests you will be able to impact with your new command. If the coverage impact is minimal then it is safe to say that the necessity is also minimal.</p><p>Until next time!</p><p>Happy Hacking,</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41d2c1d92fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cypress M.V.P (Most Visitable Pages)]]></title>
            <link>https://medium.com/@theomakaurii/cypress-m-v-p-most-visitable-pages-d7f7dc7eeee1?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7f7dc7eeee1</guid>
            <category><![CDATA[protractor]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[cypressio]]></category>
            <category><![CDATA[cypress-testing]]></category>
            <category><![CDATA[flaky-tests]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Tue, 12 Oct 2021 16:49:20 GMT</pubDate>
            <atom:updated>2021-11-13T18:23:57.096Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*_g66iQK3gScSiKU0eCQhFw.jpeg" /></figure><p>Hey QA’s,</p><p>The web has evolved. Finally, testing has too.</p><p>If you’re new to Cypress then you might be worried that your team will have some intense catching up to do. You’re not completely wrong, but you will find that they’ve made it easy for you to hit the ground running. Whether you’re starting test coverage from scratch or converting from another open source framework they’ve got you covered.</p><p>Below you’ll find a list of some of my favorite bookmarks from the Cypress documentation that should qualify as a healthy jumping off point. This is not an exhaustive list, but you’ll find that the documentation has been routed like a safety net. Rest assured that if an essential core concept is referenced on a page it will be backlinked to open in a new tab so you can easily refresh your knowledge pool without losing momentum.</p><h3>Migration 🦆</h3><p><a href="https://docs.cypress.io/guides/getting-started/installing-cypress"><strong>Initial Installation</strong></a> : If you haven’t installed cypress yet it should go without saying that this should be your first step!! Simply run ​​npm install cypress — save-dev to get started.</p><p><a href="https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Folder-structure"><strong>Organization</strong></a> : A super useful read that will help you in the early stages to group, structure, and optimize tests in your suite. This article will also cover hooks which can be used to set staging conditions or clean up after tests.</p><p><a href="https://docs.cypress.io/guides/references/configuration"><strong>Configuration</strong></a> : Many elements of the Cypress Test Runner and Dashboard are fully configurable (baseUrl, retries, port, timeout, video, etc). This guide will help you unleash the full power of the tools they’ve placed at your fingertips.</p><p><a href="https://docs.cypress.io/guides/migrating-to-cypress/protractor#Introduction"><strong>Switching From Protractor</strong></a> : They’ve made the process of switching from Protractor to Cypress as easy as possible. You’ll find that the skeleton of your Protractor based test suites can be graciously retained for a simple 1:1 trade off once Cypress is installed.</p><h3>Coverage 🕸</h3><p><a href="https://docs.cypress.io/guides/getting-started/writing-your-first-test#Write-your-first-test"><strong>Your First Test</strong></a> : Writing your first test can be daunting! Start simple and assert that True is True with this helpful tutorial.</p><p><a href="https://docs.cypress.io/examples/examples/recipes#Fundamentals"><strong>Recipes</strong></a> : Sometimes the best way to start cooking is to explore some popular recipes just to see what you can accomplish with the ingredients already in your kitchen. Testing with Cypress can work the same way! Check out some of the recipes they’ve collected to see if any inspiration is sparked.</p><p><a href="https://docs.cypress.io/api/table-of-contents"><strong>API</strong></a> : You’ll find that as you build up your test coverage you will be living with this tab open in your browser. Think of the Cypress API as your utility belt.</p><p>Here are your first five batarangs 🦇</p><ul><li><a href="https://docs.cypress.io/api/commands/visit">.<strong>visit()</strong></a> : visit a remote URL.</li><li><a href="https://docs.cypress.io/api/commands/get"><strong>.get()</strong></a> : get one or more DOM elements by unique selectors.</li><li><a href="https://docs.cypress.io/api/commands/contains"><strong>.contains()</strong></a> : get a DOM element containing specific text (‘Sign Up’, ‘Send’, ‘Home’, etc).</li><li><a href="https://docs.cypress.io/api/commands/click"><strong>.click()</strong></a><strong> </strong>: click on a selected DOM element.</li><li><a href="https://docs.cypress.io/api/commands/type"><strong>.type()</strong></a><strong> </strong>: type into a selected input field (can also be used for keystrokes).</li></ul><h3>Productivity 🦾</h3><p><a href="https://docs.cypress.io/guides/guides/screenshots-and-videos"><strong>Test Run Recording</strong></a> : Cypress allows your team to review screenshots and screen recordings of tests in your suite. This is an indispensable tool when attempting to resolve broken tests or feature bugs. Do yourself a favor and use this tutorial to configure recording sooner rather than later.</p><p><a href="https://docs.cypress.io/guides/dashboard/github-integration#Install-the-Cypress-GitHub-app"><strong>Github Integration</strong></a> : Once recording has been configured on your project you will be able to integrate test runs on PRs with Github which will give you a helpful snapshot of the essential analytics of each run (passes, fails, and flakes) as well as a chance to investigate the dashboard further for more KPIs.</p><p><a href="https://docs.cypress.io/guides/guides/parallelization#Overview"><strong>Parallelization</strong></a> : Running tests one at a time in continuous integration can be incredibly time consuming and could pose a huge blow to productivity. Cypress utilizes test parallelization to simultaneously run separate spec files across multiple machines using a unique load balancing strategy that will save your team time and headache.</p><p><a href="https://docs.cypress.io/guides/guides/test-retries"><strong>Test Retries</strong></a><strong> </strong>: Cypress efficiently handles front end testing of complex systems. However, there are still behaviors that will take more steps to verify and may lead to unreliable test suites. Test retries will soften the blow of unreliable tests by double checking whether the test fails correctly or just intermittently.</p><h3>HOMEWORK 🧑‍🏫</h3><p>Once you’ve enable test retries on PR checks you will be able to take advantage of <a href="https://docs.cypress.io/guides/dashboard/flaky-test-management#Flake-Detection">Flaky Test Management</a>. This feature will be available to subscribers of the <a href="https://cypress.io/pricing/">Team Dashboard</a> plan and unleashes the full power of test retries by making the data more readable by flagging flaky tests and providing helpful analytics.</p><p>It’s an awesome tool that’s totally worth a look.</p><p>Until Next Time!</p><p>Happy Hacking,</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7f7dc7eeee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Choose Cypress Over Selenium]]></title>
            <link>https://medium.com/@theomakaurii/why-i-choose-cypress-over-selenium-926fb010ba5f?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/926fb010ba5f</guid>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[cypressio]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Fri, 01 Oct 2021 18:26:58 GMT</pubDate>
            <atom:updated>2021-11-13T18:24:18.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-N6Gpeyt8vXdmv0Uv4L1g.png" /><figcaption>img credit: <a href="https://www.cypress.io/how-it-works/">https://www.cypress.io/how-it-works/</a></figcaption></figure><p>Hey QA’s!</p><p>Today felt like a great day to do a side by side comparison of the two most noteworthy test automation frameworks on the market: Cypress and Selenium.</p><p>Full disclosure, I have way more experience writing tests with Cypress and my experience with Selenium does not leave me eager to dig deeper. The two accomplish similar goals and the matter of preference might just boil down to familiarity. I personally love Cypress, but Selenium has been around for a lot longer, and people might not be eager to shift gears. However it is my firm belief that anyone that gets hands on experience with Cypress will quickly fall in love.</p><p>In the modern age of end to end testing, many libraries depend on a Selenium foundation to execute effectively. Selenium has a tried and true effectiveness that can be built upon by new libraries to enhance productivity. This trend has been widely accepted, but unfortunately means that any library depending on Selenium will also depend on all of Selenium’s shortcomings (poor documentation, slow run time, and steep learning curve).</p><p>Cypress is a much newer testing framework, but can accomplish fresh out of the box what Selenium would require multiple libraries to achieve. Cypress might not depend on external libraries, but still welcomes plugins and custom commands with open arms.</p><p>Selenium is significantly slower than Cypress. The move towards test parallelization has made it possible for Cypress checks to resolve faster and save the engineer time in the process. Selenium’s old school approach is significantly slower.</p><p>Selenium depends on a browser driver to execute tests, but Cypress can run right inside the browser. This is a huge deal for me. As a heavily visual learner it means so much to be able to see the automated user stories play out right before my eyes.</p><p>The Cypress documentation is a comprehensive treat to read. It is so refreshing to be able to find a quick answer to my questions when I get stuck. Selenium depends on so many libraries to function, and as a result, the documentation can feel dispersed and under-unified.</p><p>Cypress is more developer friendly than Selenium. Where Selenium forces a team into the realm of test driven development or test catch up, Cypress tests can be written so quickly that a developer (or a QA) could deploy a test in the same day a new feature is merged.</p><p>I would be remiss if I forgot to mention the Cypress Dashboard. The beauty of Cypress is not just the fast easy execution of new test suites, the dashboard offers analytics and insights about each test that helps the engineers troubleshoot bugs. Being able to review a video of the test execution in conjunction with flake rate will always be more helpful than a disappointing red X in your CLI.</p><p>Okay Hackers! It’s Friday so I wont be passing out any homework today. I hope you enjoyed my comparison!</p><p>Like I said at the beginning, I have a strong bias and no inclination to hide it on this front. Maybe down the line I could try writing a alternate reality blog post that flips the script.</p><p>Which framework do you prefer for testing and why? At the end of the day, I’m just happy your team is writing tests!</p><p>Have a great weekend Hackers!</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=926fb010ba5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting the Stage With Before Hooks]]></title>
            <link>https://medium.com/@theomakaurii/setting-the-stage-with-before-hooks-85abb5a9fa7d?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/85abb5a9fa7d</guid>
            <category><![CDATA[cypressio]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[cypress-testing]]></category>
            <category><![CDATA[mocha]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 16:16:35 GMT</pubDate>
            <atom:updated>2021-11-13T18:24:43.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Thhjt1CPaX5wd3_oUV5uEA.jpeg" /><figcaption>You can’t execute until the pieces fall into place!</figcaption></figure><p>Hey QA’s,</p><p>Today we’re discussing another basic principle of testing that I’ve seen even senior or advanced engineers skirt.</p><p>You should hopefully know by now that Cypress borrows the useful before() and beforeEach() hooks from Mocha. These hooks allow engineers to easily establish their browser environment before testing its elements. This is a huge luxury because when testing with Cypress, the state of the browser will be reset at the initiation of each test. Without the use of hooks this reality would mean that any changes your test makes to the state will have to be repeated during the intro of each it() block.</p><pre><strong>describe</strong>(&#39;When a constructing our test interface&#39;, () =&gt; {</pre><pre>it(<strong>&#39;The test engineer&#39;</strong>, () =&gt; { <br>    cy.<strong>visit</strong>(&#39;http://localhost:3000/messages&#39;);<br>    cy.<strong>viewport</strong>(&#39;iphone-xr&#39;);</pre><pre>  });</pre><pre>it(<strong>&#39;Will be annoyed&#39;</strong>, () =&gt; {<br>    cy.<strong>visit</strong>(&#39;http://localhost:3000/messages&#39;);<br>    cy.<strong>viewport</strong>(&#39;iphone-xr&#39;);</pre><pre>  });</pre><pre>it(<strong>&#39;If they have to keep establishing the environment&#39;</strong>, () =&gt; {<br>    cy.<strong>visit</strong>(&#39;http://localhost:3000/messages&#39;);<br>    cy.<strong>viewport</strong>(&#39;iphone-xr&#39;);</pre><pre>  });</pre><pre><em>});</em></pre><p>The use of a beforeEach() hook will ensure that all of your pawns are in place at the start of each test. Trust me, you don’t want to worry about re-establishing the same elements everytime.</p><p>Getting into the habit of using these hooks will certainly help focus your tests. Setting the stage should not be considered a ‘test’ but rather a safety check of your environment that is guaranteed to pass every time. In fact Cypress will throw an assertion error if a before() check fails.</p><p>All this to say that if your safety check does not pass then something really crazy has gone wrong! So you better check it out immediately. When a before() or beforeEach() hooks fails the test runner will abort the following tests in order to raise the alarm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Y2zlHZBk_386YLHp-vF3og.png" /></figure><p>It’s important to keep the order of operations in mind when using before hooks.</p><pre><strong>before</strong>(()=&gt;{ <br>  &#39;Will run Before All others&#39; <br>})</pre><pre><strong>beforeEach</strong>(()=&gt;{ <br>  &#39;Runs after the before() hook but before each top level scope&#39; <br>})</pre><pre><strong>describe</strong>(&#39;Establishes a new scope&#39;, () =&gt; {</pre><pre><strong>  before</strong>(()=&gt;{ <br>    &#39;Will run at the top of the shared scope&#39; <br>  })</pre><pre><strong>  beforeEach</strong>(()=&gt;{ <br>    &#39;Runs after the before() hook, before each it() block&#39; <br>  })</pre><pre><strong>  it</strong>(&#39;Runs after every before() or beforeEach() hook&#39;, () =&gt; {<br>    cy.<strong>location</strong>(&#39;pathname&#39;).<strong>should</strong>(&#39;equal&#39;, &#39;/can-dance&#39;);</pre><pre>  })</pre><pre>})</pre><p>I’ve found that using these hooks will be especially valuable when authenticating your seed users, navigating to a specific page for each test, or testing mobile interfaces.</p><p>And now, a nice chance for some 🧑‍🏫HOMEWORK🧑‍🏫:</p><ul><li>There are surely other use cases where establishing the browser elements before running any tests will lead to a more deterministic testing environment. What are some of your ideas? Take your time, I’ll WAIT 😉</li></ul><p>Until Next Time!</p><p>Happy Hacking,</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85abb5a9fa7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When to Use Commands vs Assertions When Testing]]></title>
            <link>https://medium.com/@theomakaurii/when-to-use-commands-vs-assertions-when-testing-36e41d9a71c?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/36e41d9a71c</guid>
            <category><![CDATA[chai]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[commands]]></category>
            <category><![CDATA[cypressio]]></category>
            <category><![CDATA[assertions]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Tue, 21 Sep 2021 16:52:34 GMT</pubDate>
            <atom:updated>2021-11-13T18:25:18.537Z</atom:updated>
            <content:encoded><![CDATA[<h3>When to Use Commands vs Assertions While Testing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2FVt6Jun9SB7jQlGw579Yg.jpeg" /><figcaption>Kinda similar, but very different!</figcaption></figure><p>Hey QA’s,</p><p>Today felt like a great day to talk a little bit about the difference between <strong>Commands </strong>and <strong>Assertions </strong>in your Cypress library. I think this distinction will be easiest to explain by comparing two Cypress commands that perform very similar actions, but should be used in <em>completely </em>different contexts.</p><p>When you or a teammate test a message app you may very likely include the following checks in the the same suite: cy.get(&#39;button&#39;).contains(&#39;Send&#39;) and cy.get(&#39;button&#39;).should(&#39;contain&#39;, &#39;Send&#39;) — both will check for buttons in the DOM that contain the word ‘Send’. However the similarities between these commands will end here. One will be considered a <strong>Command</strong>, and the other will be considered and <strong>Assertion</strong> 🍏🍊</p><p>The difference between <strong>Commands </strong>and <strong>Assertions </strong>is crucial to understand when building a rock solid test using Cypress. Commands are chainable methods that will help perform an action on a DOM element. Some commands can be chained directly from cy and simply identify a DOM element to be acted upon by the next command in the chain. Other commands (such as type(), click(), and check()) will perform a specific action to the previous element returned.</p><p>contains() falls under the umbrella of commands that can be chained directly from cy but in my experience will be more effective if passed from get() or find().</p><p>Although .contains()will fail to pass if our test runner cannot find an element in the DOM that contains the case sensitive string passed as an argument, it should never be used as an assertion that an element exists. The command .contains() is chainable and should therefore lead to further actions such as click() or type() and should never be left dangling or capped by a semicolon.</p><p>❌cy.get(&#39;button&#39;).contains(&#39;Send&#39;);❌</p><p>✅cy.get(&#39;button&#39;).contains(&#39;Send&#39;).click();✅</p><p>Both checks featured above would actually pass, but the former would be considered a bad practice as the writer would not have used contains() to its full potential. If we are using contains() we should be committing to an action.</p><p>Assertions are technically commands that help you verify the intended rendering of the DOM — whether or not an element exists or is visible, etc. Assertions are not designed to encourage further command chaining.</p><p><em>“WAIT WAIT WAIT how can you just slyly state that </em><strong><em>Assertions</em></strong><em> and </em><strong><em>Commands</em></strong><em> are the same thing??”</em></p><p>I never said that, but good point. This may be confusing. I won’t get too deep into it. Just remember All squares are rectangles, but not all rectangles are squares. In this analogy the <strong>assertion is a square.</strong></p><p>In Cypress testing an assertions will almost always be passed as arguments to the command should() as an implicit subject and mirrors the Chai library of assertions plus more. They’re very easy to use and you can review a list of baked in Cypress assertions <a href="https://docs.cypress.io/guides/references/assertions">here</a>.</p><p>If the writer of the above checks merely wanted to assert the existence of a ‘Send’ button in the DOM they could include either of the following assertions.</p><p>✅cy.get(&#39;button&#39;).contains(&#39;Send&#39;).should(&#39;exist);✅</p><p>✅cy.get(&#39;button&#39;).should(&#39;contain&#39;, &#39;Send&#39;);✅</p><ul><li><em>The later may not pass if the DOM contains multiple button elements*</em></li></ul><p>We should not attempt to commit an action from an assertion. This is a poor practice and will fail your tests if attempted.</p><p>There is only one command that should be chained from should() which will provided deeper security to the initial assertions — and().</p><p>Example:</p><p>✅cy.get(&#39;button&#39;).should(&#39;be.visible&#39;).and(&#39;contain&#39;, &#39;Send&#39;);✅</p><p><strong>Assertions</strong> and <strong>Commands </strong>are the bread and butter of Cypress testing. With dozens of baked in methods and the freedom to create or overwrite existing commands QA Engineers are able to quickly draft comprehensive tests in a flash.</p><p>Now for some 🧑‍🏫HOMEWORK🧑‍🏫:</p><ul><li>Attempt to draft a single chain of commands that asserts the existence and visibility of my name ‘Theo McCauley’ on the page you are viewing. No need to put it through a test runner, just drop it in the comments below. This shouldn’t be too tough if you read thoroughly 😜</li><li>Based on one of my previous posts, why might the command chain included above: cy.get(&#39;button&#39;).contains(&#39;Send&#39;).click(); end up being drafted out or fortified as the development team iterates over the product down the road? Leave your conclusion in the comments below.</li></ul><p>Until Next Time!</p><p>Happy Hacking,</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36e41d9a71c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Not JUST Syntactic Sugar]]></title>
            <link>https://medium.com/@theomakaurii/not-just-syntactic-sugar-583b1127d4d2?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/583b1127d4d2</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[cypress-testing]]></category>
            <category><![CDATA[syntactic-sugar]]></category>
            <category><![CDATA[mocha]]></category>
            <category><![CDATA[test-fail]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Sun, 19 Sep 2021 16:45:49 GMT</pubDate>
            <atom:updated>2021-11-13T18:25:44.657Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*2H3-B_vxh-HE-DYz-gRe6A.jpeg" /></figure><p>Hey QA’s,</p><p>Today I wanted to riff about our tendencies to pin syntactic sugar as a bottom tier priority when constructing otherwise very strong tests. It’s a careless habit that might breed resentment when an otherwise high quality test fails correctly.</p><p>In a practice that mirrors the testing library Mocha, Cypress engineers use syntactic sugar in our test interfaces to add important details to our test suites. This is done via the commands describe() and it() (alternatives include the parallels context() and specify() ). This interface is considered syntactic sugar because the execution can improve the human experience of a test suite, but will not directly affect the test function in any substantial way.</p><p>For this reason a careless engineer might be inclined to shrug their shoulders at this juncture in favor of placing extra effort on stronger mechanics which from their perspective will be self explanatory. However, the real value of a well crafted test interface will not be apparent until a strong test inevitably fails. Poor interface construction will lead to unnecessary struggles down the road, and will not make your team smile 😭</p><p>Simply put:</p><pre><strong>describe</strong>(&#39;When a constructing our test interface&#39;, () =&gt; {</pre><pre><strong>it</strong>(&#39;The human developer should know what is being tested&#39;, () =&gt; {</pre><p>When all tests are passing our engineering team is happy, but when a test fails a responsible engineer will quickly investigate the failure in the hopes of finding helpful context from the QA team. If the test interface is well constructed the developer will know exactly which component is bugging out. They will then be able to quickly isolate some suspects in the case of the failure. If the interface was poorly written (by a careless but talented QA engineer) the developer will have no leads when investigating the failure.</p><p>️This would not be very helpful:</p><p>☠️☠️☠️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SU9lqOA0yeE7StRI_v0ZrQ.png" /><figcaption>No context and no clues! What even failed?</figcaption></figure><p>☠️☠️☠️</p><p>As important as it is to provide context via syntactic sugar, it can be equally important to avoid verbose descriptions of the actions being tested. Long descriptions can be tedious to read, and the intended message can be lost in the details.</p><p>☠️☠️☠️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uvusRz2UvhA4629DbR1p1A.png" /><figcaption>A verbose message like this might also be truncated on certain browsers or dashboards…</figcaption></figure><p>☠️☠️☠️</p><p>Typically when constructing my test interfaces, I try to mirror the formulaic user story I am testing. An easy rule of thumb — ‘When-Then’.</p><p>“When a chat item is sent on a desktop viewport, then the user can edit the chat item content.”</p><p>The describe() interface should represent the ‘When’ of a user story and the it() will capture the ‘Then’.</p><p>A test interface with greater context:</p><p>🕵️🕵️🕵️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0iXjjrHr-G-I_W9fY4qhg.png" /><figcaption>Short, sweet, and helpful! My user can’t edit their chat items!</figcaption></figure><p>🕵️🕵️🕵️</p><p>This practice is not difficult or technical but it will provide for a drastic quality of life improvement for both QA and development teams on a project. More than anything it demonstrates an important team oriented philosophy that a great team should strive for.</p><p>Happy hacking until next time!</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=583b1127d4d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Avoid Brittle Testing Using Enum Type Constants]]></title>
            <link>https://medium.com/@theomakaurii/how-to-avoid-brittle-testing-using-enum-type-constants-62da66090cb8?source=rss-704d2c0d3b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/62da66090cb8</guid>
            <category><![CDATA[selectors]]></category>
            <category><![CDATA[flaky-tests]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[cypressio]]></category>
            <dc:creator><![CDATA[Theo McCauley]]></dc:creator>
            <pubDate>Fri, 17 Sep 2021 15:43:03 GMT</pubDate>
            <atom:updated>2021-11-13T18:26:14.115Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaWd5RAXEmKQcqwJnjHPGA.png" /><figcaption>An enum type is a special data type that enables for a variable to be a set of predefined constants.</figcaption></figure><p>Hey QA’s,</p><p>I wanted to jump on today to talk a little bit about using one incredible tool a little better.</p><p>Since the advent of the Cypress test runner engineers have been able to execute commands in real time to assert feature dependability with more ease than ever before. This fully interactive test environment allows test engineers to see commands as they execute alongside an equally interactive simulation of the user stories being tested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3XHs7b3nvKBJbB0gmSIVJg.png" /><figcaption>Example of th Cypress test runner (img credit: <a href="https://docs.cypress.io/guides/core-concepts/test-runner#Overview">https://docs.cypress.io/guides/core-concepts/test-runner#Overview</a>)</figcaption></figure><p>Cypress was founded with the mission of creating an ecosystem that enhances productivity. The ability to interact with commands as they execute has created a linear environment that simplifies the process of identifying broken logic, and the ability to forge selectors using nothing but existing DOM elements means that a robust test suite can be erect in a day to ensure site reliability. However this new great power comes with great responsibility 🕷️.</p><p>To clarify, there is no existing argument to suggesting the following logic below is illegal cy.get(&#39;.list &gt; li&#39;).first().contains(&#39;Home&#39;).click() — however forging selectors with this logic leads to incredibly brittle tests. A test that seeks the Home button in the navigation bar using this logic (or worse 💀CSS ELEMENTS 💀) would depend on DOM conditions being constructed with the same elements, containers, and styles in perpetuity in order to avoid tests failures. It’s probably obvious that this is incredibly unrealistic.</p><p>Commands forged with brittle selectors inevitably lead to assertion errors such as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*MNv5CM6xw_8nx8yCP5EyIA.png" /><figcaption>Assertion errors occur when your test runner tries really hard to find something, but simply cannot.</figcaption></figure><p>We can avoid assertion errors of this nature by instead targeting data-cy properties of DOM elements. data-cy properties can be added to elements just as simply as classNames and then targeted by similar Cypress commands.</p><p>Example:</p><p>&lt;li className=&quot;border-l-4 rounded shadow&quot; data-cy= &quot;left-nav-home&quot;&gt;</p><p>&amp;&amp;</p><pre><strong>it</strong>(&#39;The user should be able to navigate to the  home page&#39;, () =&gt; {</pre><pre>  cy.<strong>authUserTo</strong>(sammywinchester, &#39;<strong>/</strong>messages&#39;);</pre><pre>  cy.<strong>get</strong>(&#39;[data-cy=left-nav-home]&#39;).<strong>click</strong>()</pre><pre>  cy.<strong>location</strong>(&#39;pathname&#39;).<strong>should</strong>(&#39;equal&#39;, &#39;/home&#39;);</pre><pre>});</pre><p>This pairing will lead to an assertion with a much higher resilience rate, but it could still be stronger! Remember, the goal with Cypress testing is not passing a test suite once. Our goal is to build rock solid tests that can withstand feature pivots and redesigns without failing or flaking. We want a test to pass on EVERY push and deploy 🪨</p><p>A great practice to pick up is relying on enumerated types otherwise known as enums to act as a liaison for your data-cy selectors between tests and components.</p><p>An enum is an object type whose contents consist of fixed constant.</p><p>Example:</p><pre>export enum <strong>DataCySelectors</strong> {</pre><pre>  left_nav_home = &#39;left-nav-home&#39;,<br>  left_nav_messages = &#39;left-nav-messages&#39;,<br>  left_nav_notifications =&#39;left-nav-notifications&#39;,</pre><pre>}</pre><p>These values are more reliable than string types because the data is housed at an isolated point of origin. This simple precaution will save future engineers frustrating hunts for tedious typographic errors in string types that won’t be caught by linters or intellisense. ‘left-nav-hom’ vs ‘left-nav-home’ can really slow down a good flow state.</p><p>Once implemented an enum constant will fit seamlessly in place of the original data-cy string selector in your test and component.</p><p>Example:</p><pre>&lt;li className=&quot;border-l-4 rounded shadow&quot; <br>data-cy={<strong>DataCySelectors</strong>.left_nav_home}&gt;</pre><p>&amp;&amp;</p><pre><strong>it</strong>(&#39;The user should be able to navigate to the  home page&#39;, () =&gt; {</pre><pre>cy.<strong>authUserTo</strong>(sammywinchester, &#39;/messages&#39;);</pre><pre>cy.<strong>get</strong>(`[data-cy=${<strong>DataCySelectors</strong>.left_nav_home}]`).<strong>click</strong>()</pre><pre>cy.<strong>location</strong>(&#39;pathname&#39;).<strong>should</strong>(&#39;equal&#39;, &#39;/home&#39;);</pre><pre>});</pre><p>The developers on your team will be eternally grateful for this pairing. It is reliable and deterministic just as a quality assertion should be.</p><p>Now for some homework 🧑‍🏫.</p><p>Using what we learned about how enum s can improve your existing assertions, how can the code block above be improved even further? Remember, strings in your tests are perfectly legal, but might not always be the best practice to follow when seeking to forge bullet proof assertions.</p><p>Happy hacking until next time!</p><p>Theo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62da66090cb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>