<?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 Normia Pop on Medium]]></title>
        <description><![CDATA[Stories by Normia Pop on Medium]]></description>
        <link>https://medium.com/@normiaaa?source=rss-c3e3d5f68b59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H__4APQJKDgk-wn3GWKsxQ.png</url>
            <title>Stories by Normia Pop on Medium</title>
            <link>https://medium.com/@normiaaa?source=rss-c3e3d5f68b59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:55:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@normiaaa/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[Unlocking Efficiency: Integrating Cypress with Your Development Codebase]]></title>
            <link>https://javascript.plainenglish.io/unlocking-efficiency-integrating-cypress-with-your-development-codebase-33374e9fe8b7?source=rss-c3e3d5f68b59------2</link>
            <guid isPermaLink="false">https://medium.com/p/33374e9fe8b7</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Normia Pop]]></dc:creator>
            <pubDate>Sun, 17 Mar 2024 15:20:29 GMT</pubDate>
            <atom:updated>2024-03-20T01:13:29.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O4ciodZDsXAzBq8u" /><figcaption>Photo by <a href="https://unsplash.com/@danielfazio?utm_source=medium&amp;utm_medium=referral">Daniel Fazio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello, my name is Normia and I am a Cypress Ambassador. In this article, I’m eager to present the advantages of integrating your <strong>Cypress project</strong> directly into your <strong>development repository</strong>. Launching an automation project presents a variety of strategies but one method I particularly advocate for, due to its significant benefits, involves placing the automation tests in the same repository as the development code.</p><p>Let’s start:</p><h4>Effortless Selector Handling</h4><p>One of the best practices when using Cypress is the use of <strong>data attributes</strong> for selecting elements. Imagine how streamlined the process becomes when these are set up <strong>directly</strong> in our <strong>development project</strong>.</p><p>By using this approach, we can avoid the hassle of <strong>managing different repositories</strong> for our tests by importing the selectors straight into our tests. Maintaining a constants file for our test IDs within the same repository ensures that when any updates occur, the process is <strong>straightforward</strong>, making <strong>test maintenance</strong> and <strong>application</strong> much easier.</p><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ow68zNB8JW1qxqrG" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jJhwoPieuvBh8i8u" /></figure><h4>Streamlined CI/CD Flows</h4><p>Integrating the tests into our main repository also means smoother <strong>CI/CD experience</strong>. Let’s take GitHub Actions for our example. We could set up a deploy and end to end pipeline, triggered with every push. In this way, we can catch bugs or issues in an early stage. Here’s a quick GitHub actions setup to get you started:</p><pre>name: Deploy and run E2E tests<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  deploy: <br>    runs-on: ubuntu-latest<br>    // your deployment steps here<br>  cypress-run:<br>    runs-on: ubuntu-latest<br>    needs: deploy<br>    steps:<br>      - name: Checkout<br>        uses: actions/checkout@v4<br><br>      - name: Install pnpm<br>        uses: pnpm/action-setup@v3<br>        with:<br>          version: 8<br><br>      - name: Cypress run with local env<br>        uses: cypress-io/github-action@v6<br>        env:<br>          BASE_URL: url<br>          CYPRESS_email: ${{ secrets.email }}<br>          CYPRESS_password: ${{ secrets.password }}</pre><p>Let’s break down this code a bit:</p><p>First off, we create a new YAML file in the <strong>.github/workflows</strong> directory and name it <strong>deploy_e2e.yml.</strong></p><p>Next, we outline the steps:</p><ul><li><strong>On push </strong>— this triggers the tests with every push to the project.</li><li><strong>Branches</strong> — the branch that we want to run on push.</li><li><strong>Jobs</strong> — describes the jobs to be executed and their names.</li><li><strong>Deploy</strong> — here will be the deploy steps depending on your app</li><li><strong>Needs</strong> — on this step we need to add the deploy.</li><li><strong>Steps</strong> — outlines the specific actions to be taken and the execution process.</li><li>If you’re working with <strong>pnpm</strong>, remember to include the<strong> step to install pnpm</strong>. If npm is your tool of choice, you can skip this part.</li><li><strong>Run</strong> — the command that actually runs the tests.</li><li><strong>Env</strong> — here we place the url, email and password (in this example email and password are stored in secrets)</li></ul><p>And there you have it! With this configuration, <strong>every push</strong> to the main branch <strong>initiates</strong> both the <strong>deployment</strong> and <strong>testing</strong>. Also, another benefit it is that everything is customizable to fit our specific requirements. This kind of setup allows the <strong>simultaneous triggering</strong> of <strong>development</strong> and <strong>QA Automation</strong> without the need for separate pipelines.</p><h4>Simultaneous Development and Testing</h4><p>Another significant advantage is worth mentioning here — Cypress is designed with developers in mind, offering a user-friendly experience. During the development of new features, <strong>developers can effortlessly run the tests locally </strong>to confirm that everything functions correctly before marking a new PR. This process <strong>eliminates</strong> the <strong>need to switch between various repositories</strong>.</p><p>As previously highlighted, this approach enables the <strong>early detection</strong> and <strong>resolution of bugs</strong>. Also, implementing a regression suite that developers can run on their branches is an excellent strategy.</p><h4>Wrapping Up</h4><p>Integrating Cypress directly into your development repository not only streamlines your workflow but also fosters a more <strong>collaborative</strong> and <strong>efficient testing culture</strong>. It’s about making <strong>testing an integral part of development</strong>, catching bugs early, and ensuring a smoother CI/CD process.</p><p>I’m here to help you navigate your Cypress journey. For more insights or help, you can contact me at<a href="https://normia.dev/"> https://normia.dev/</a>. I look forward to supporting your testing journey. Happy testing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*H__4APQJKDgk-wn3GWKsxQ.png" /></figure><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33374e9fe8b7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/unlocking-efficiency-integrating-cypress-with-your-development-codebase-33374e9fe8b7">Unlocking Efficiency: Integrating Cypress with Your Development Codebase</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Schedule, Run, Repeat: Integrating Cypress with GitHub Actions]]></title>
            <link>https://blog.devgenius.io/schedule-run-repeat-integrating-cypress-with-github-actions-143b0459dcf5?source=rss-c3e3d5f68b59------2</link>
            <guid isPermaLink="false">https://medium.com/p/143b0459dcf5</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Normia Pop]]></dc:creator>
            <pubDate>Thu, 15 Feb 2024 16:10:10 GMT</pubDate>
            <atom:updated>2024-02-16T17:08:33.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oY-MaP1b2E0_Jqon" /><figcaption>Photo by <a href="https://unsplash.com/@safarslife?utm_source=medium&amp;utm_medium=referral">Safar Safarov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello, I’m Normia, and in this article, I’ll be walking you through the process of integrating your <strong>Cypress</strong> tests with<strong> GitHub Actions</strong>. GitHub Actions is a powerful tool that <strong>enhances your CI/CD</strong> pipeline by enabling automated builds, tests and deployments.</p><p>Automatically running your Cypress tests improves the <strong>long term quality</strong> of your application and <strong>rapid identification</strong> of any issues is crucial. By running your <strong>Cypress</strong> test suites through <strong>GitHub Actions</strong>, ensures the reliability of existing workflows and alerts developers about any bugs, allowing for fixes before deploying to prod.</p><p>Understanding how to configure such integrations, especially for QA professionals, is invaluable. In teams lacking DevOps specialists, or when developers are preoccupied with urgent tasks, the ability to independently set up these integrations from an early stage <strong>improves</strong> the <strong>efficiency</strong> of the processes.</p><p>Now, let’s dive into the step-by-step process of setting up <strong>GitHub Actions</strong> for your <strong>Cypress</strong> tests.</p><h4>Setting Up GitHub Actions for Cypress Tests</h4><p>We’ll structure this setup into two distinct jobs:</p><p>a. <strong>Scheduled Job</strong></p><p>In this example, this job runs at a scheduled time, and it is set by a cron job to execute every 24 hours.</p><ol><li>Navigate to the <em>.github/workflows</em> folder (create it if it doesn’t exist)</li></ol><p>2. Create a new <em>.yml</em> file named <em>e2e.yml</em></p><p>3. Define your job details: name, jobs, steps, and schedule</p><p>4. Input your application’s URL for the QA/Dev/Prod environments</p><p>It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tACxKjLeL02KxZZZoaP9KA.png" /></figure><p>Important Points:</p><ul><li>For those using <strong>pnpm</strong>, an extra step for installation is required. This isn’t necessary for <strong>npm</strong> or <strong>yarn</strong> users</li><li>We use<strong> GitHub secrets </strong>(check Secrets tab from GitHub) for <strong>email</strong> and <strong>password</strong> details to avoid hardcoding sensitive information. Also the URL can be added to GitHub secrets</li></ul><p>Verify the test runs in the Actions tab on GitHub. Your setup should now be operational.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hGR4n2aI5ZfiqpIO" /></figure><p>b. <strong>On Push Job</strong></p><p>This job activates upon any push to a designated branch, typically running a subset of tests known as a sanity suite.</p><p>1. Go to the <em>.github/workflows</em> folder (create it if it doesn’t exist)</p><p>2. Generate a new <em>.yml </em>file, this time named <em>sanity.yml</em></p><p>3. Input job details: name, jobs, steps, push action, and specific tests (specs)</p><p>4. Update with your application’s URL for the QA/Dev/Prod environments</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kknSItab2LxERR3W" /></figure><p>Important points:</p><ul><li>Like the scheduled job, include pnpm installation and secrets (check Secrets tab from GitHub)</li><li>Specify <strong>branches</strong> for test runs, in this case ‘dev’ and ‘main’ - if the branch is not defined the job will run on all of them</li><li>For now, we only selected one spec to run, and we declared it in the spec section</li></ul><p>After performing a push on the selected branches, check the GitHub Actions tab to ensure tests are functioning as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gzU4NkGdj4AW915V" /></figure><h4>Conclusion</h4><p>By effectively implementing GitHub Actions, as illustrated, your tests will run consistently, allowing <strong>early detection </strong>of <strong>issues</strong> and <strong>minimizing bugs</strong> in production. This guide aims to help you <strong>integrate Cypress tests</strong> with <strong>GitHub Actions</strong> seamlessly.</p><p>Thank you for reading, and I hope this guide is helpful for your testing journey. For further tips or questions regarding Cypress, don’t hesitate to connect with me at<a href="https://normia.dev/"> <strong>https://normia.dev/</strong></a><strong>.</strong> I look forward to it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*H__4APQJKDgk-wn3GWKsxQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=143b0459dcf5" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/schedule-run-repeat-integrating-cypress-with-github-actions-143b0459dcf5">Schedule, Run, Repeat: Integrating Cypress with GitHub Actions</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revolutionize Your Cypress Tests: Mastering Scalability with Data Attributes]]></title>
            <link>https://blog.stackademic.com/revolutionize-your-cypress-tests-mastering-scalability-with-data-attributes-3620fa46f4da?source=rss-c3e3d5f68b59------2</link>
            <guid isPermaLink="false">https://medium.com/p/3620fa46f4da</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Normia Pop]]></dc:creator>
            <pubDate>Fri, 09 Feb 2024 09:56:09 GMT</pubDate>
            <atom:updated>2024-02-13T01:38:20.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LnBeCpdbz_nSKMfx" /><figcaption>Photo by <a href="https://unsplash.com/@firsara?utm_source=medium&amp;utm_medium=referral">Fabian Irsara</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong>The Power of Data Attributes</strong></h4><p>Welcome to the world of efficient testing! I’m Normia, and today I’ll guide you through leveraging <strong>data attributes</strong> to supercharge the <strong>scalability and organization</strong> of your <strong>Cypress</strong> tests. Let’s explore how proper organization of selectors with data attributes can save invaluable time.</p><p>Why shifting to data attributes? For example, unlike <strong>CSS or xPath selectors that often change with the code updates</strong>, the <strong>data attributes remain consistent</strong>. This stability ensures your tests are more <strong>reliable</strong> for a longer period of time and no input is required when this happens.</p><h4><strong>Strategic Implementation of Data Attributes</strong></h4><p>In the strategy that I will present here, we will use <strong>data-testid</strong>, a custom attribute that enhances test scalability. Organizing these IDs meticulously ensures that, regardless of how your project evolves, your tests remain<strong> robust </strong>and<strong> adaptable</strong>. I also suggest keeping the Cypress project in the same repository as the primary project, as it simplifies making changes and adjustments whenever necessary.</p><p>Let’s dive in.</p><h4><strong>Step-by-Step Guide to Applying Data Attributes</strong></h4><p>1. <strong>Structuring Your Test IDs</strong></p><p>Create a new folder name <strong>testID</strong> within your project’s constants file. This is where you’ll store your selectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*8APyOGFaKhaoE3fE" /></figure><p>For <strong>TypeScript</strong> users, don’t forget to include a <strong>types.ts</strong> file to streamline imports and usage across your tests. It should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/0*yown3foype7OShBK" /></figure><p>2. Within the folder we established in step 1, we proceed to <strong>create a new file</strong>, which in this case is named <strong>“login”</strong>. In this file, we define and add the constants required for our selectors, as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XE2HXXWR47FSLvTL" /></figure><p>3. Once we declare our constants, we move on to <strong>locating the initial component</strong> to which we want to attach the attribute. In this example, we focus on the ‘Create an account’ button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SLEsd43pLJM787RC" /></figure><p>4. After locating the file where our component is, <strong>we need to import the file created in step 2</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JtDBI-B2C3-cKPmW" /></figure><p>5. Then, add the <strong>data-testid</strong> attribute to your button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zWohrYSOhlBUNoE6" /></figure><p>6. <strong>Refresh </strong>your<strong> webpage</strong> and inspect the element to confirm the attribute’s addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1NHgJ1BzL4K6aTe7" /></figure><p>Once we’ve incorporated all the necessary <strong>data attributes</strong> into our tests, we’re ready to begin <strong>starting our end-to-end test</strong>. Additionally, I highly recommend creating a <strong>custom command</strong> specifically for the data-testid attribute. This ensures our<strong> code remains well-structured</strong> and easily readable.</p><h4>Improving the utilization of data attributes with a custom command</h4><p>Here are the steps to add the custom command for the data attribute:</p><ol><li>Navigate to the <strong>commands</strong> file</li></ol><p>2. Add the <strong>custom command</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/0*u1X5sy3mepWGlhjn" /></figure><p>3. If you’re using <strong>TypeScript</strong>, be sure to <strong>declare your custom command</strong> in the Cypress support file <strong>(index.ts</strong>) to ensure recognition by the TypeScript compiler</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mqZp5qx0vxOfkq15" /></figure><p>With these steps completed, we now have our <strong>custom command</strong> in place and can seamlessly integrate it into our tests. This not only enhances readability but also streamlines our testing process.</p><p>Let’s take a look at an example:</p><p>a. <strong>Without custom command</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*ZNpzooryCxwl3vkA" /></figure><p>b. <strong>With custom command</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*X3f-KwSh3yvJLKvU" /></figure><p>As illustrated, by using this custom command significantly i<strong>mproves code readability</strong>, making our testing workflow smoother and more efficient.</p><h4>End result: Writing our end to end test</h4><p>Now, let’s dive into writing our test. In this example, we’ll walk through a <strong>UI login test</strong>, applying the techniques we’ve covered: setting up <strong>data attributes</strong> and using the <strong>custom command</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mfL8FYGJOCWqaAk6" /></figure><p>Don’t forget to<strong> import the test IDs</strong> from the files created in step 1 to ensure accessibility. After crafting our test, such as the UI flow in this example, we can expect results that are both effective and visually appealing.</p><p>Exciting stuff, isn’t it?</p><h4>Conclusion: The Unmatched Benefits of Data Attributes</h4><p>Embracing data attributes in Cypress testing <strong>transforms your tests into models of scalability and organization</strong>. This approach not only makes your codebase more maintainable but also insulates your tests from the vagaries of UI changes. With <strong>data attributes </strong>and<strong> custom commands</strong>, your tests are not just code; they’re a robust framework that stands the test of time.</p><p>I hope this guide illuminates the path to more scalable, organized testing with Cypress. Embrace data attributes, and watch your testing process transform. For further insights or questions, feel free to connect with me at<a href="https://normia.dev/"> normia.dev</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*H__4APQJKDgk-wn3GWKsxQ.png" /></figure><h3>Stackademic</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3620fa46f4da" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/revolutionize-your-cypress-tests-mastering-scalability-with-data-attributes-3620fa46f4da">Revolutionize Your Cypress Tests: Mastering Scalability with Data Attributes</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elevate Your Cypress Tests: A Guide to Custom Commands and Environments]]></title>
            <link>https://blog.stackademic.com/elevate-your-cypress-tests-a-guide-to-custom-commands-and-environments-1390885c5cc2?source=rss-c3e3d5f68b59------2</link>
            <guid isPermaLink="false">https://medium.com/p/1390885c5cc2</guid>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Normia Pop]]></dc:creator>
            <pubDate>Mon, 05 Feb 2024 12:18:16 GMT</pubDate>
            <atom:updated>2024-02-07T04:15:16.936Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*H__4APQJKDgk-wn3GWKsxQ.png" /><figcaption>Illustration made by Tania Miresan Art</figcaption></figure><p>Get ready to enhance your Cypress tests by using <strong>Cypress environments</strong> and <strong>custom commands</strong>. I’m Normia, and in this article, I’ll break down these concepts and share some simple examples to make your automation tests more scalable.</p><h4>1. Cypress Environments: Safeguarding Sensitive Data</h4><p>Cypress environments play a key role in enhancing the security and scalability of your tests. By utilizing the <strong>Cypress.env</strong> function, we can easily gain access to the values of environment variables. Typically, this feature is employed to store confidential information like emails, passwords, and tokens that shouldn’t be shared openly within the project.</p><p><strong>How to use Cypress Environments:</strong></p><p>To begin, consider adopting a practice where you create two separate files:</p><p><strong>a. cypress.env.example.json</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nozwswGWKeiFKUrv" /></figure><p>Use this file to provide examples of the data used within your tests.</p><p><strong>b. cypress.env.json</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UrXrKR5aGeUEiWcz" /></figure><p>This file serves as the main file for your environment variants. Ensure that it is listed in the<strong> .gitignore</strong> file to prevent sensitive data from being inadvertently merged. A sample structure may look like this.</p><p>By maintaining this separation, you’ll always have a clear reference for the data required to run your tests successfully. Also, from here you can easily switch between different environments, for example QA env or Prod env.</p><p><strong>Note:</strong> Values in here will overwrite conflicting environment variables in your Cypress configuration.</p><h4>2. Custom Commands: Simplifying Test Flows</h4><p>Custom commands within Cypress enhance the testing framework’s functionality, enabling the creation of <strong>specific actions and assertions</strong> tailored to our needs. These commands help streamline testing processes by reducing repetition and increasing efficiency.</p><p><strong>The Power of Custom Commands — Example of a Login Function</strong></p><p>One of the most impactful custom commands is the <strong>‘login’ command</strong>. This can be implemented in two ways: through the<strong> UI or via API</strong>.</p><p><strong>Examples:</strong></p><p><strong>a. Login via UI</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jGhj5BFTscRE5ADi" /></figure><p><strong>b. Login via API</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vUQA_GNfD1vyhFAz" /></figure><p>The API-based login option is particularly advantageous due to its speed, making it a preferred choice for efficient testing.</p><p>Now, you can effortlessly import the custom command into any of your Cypress tests as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*TNbDcI74RziKB3fBZfLSmw.png" /></figure><p>That’s it!</p><p>Note: I I advocate for using Cypress with <strong>TypeScript</strong>, and if you choose to do so, ensure that you also declare your custom commands in the Cypress support file (index.ts). This is important to ensure that the TypeScript compiler recognizes them. Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4MeRMhE95QgQZGa2GEmzw.png" /></figure><p><strong>Integrating Cypress Environments with Custom Commands</strong></p><p>As we can see in the examples above, we seamlessly integrated <strong>Cypress.env</strong>, as discussed in the first part of the article. This ensures that <strong>sensitive data remains shielded from direct exposure in commands</strong>. Any alterations can be effortlessly made in the Cypress.env file, eliminating the need for modifications in tests or commands, which will enhance <strong>scalability</strong>.</p><p><strong>Conclusion</strong></p><p>In conclusion, <strong>implementing Cypress environments and custom commands in your Cypress tests can significantly boost efficiency, security, and scalability</strong>. By adopting these practices, you’ll find yourself spending less time tweaking and fixing failing tests, allowing you to focus on what truly matters — <strong>building reliable automation suites</strong>.</p><p>I hope you find these insights helpful on your journey to optimizing Cypress tests. Thanks for reading!</p><p>If you’re looking for tips or have questions about <strong>Cypress</strong>, I’m here to help. Visit me at <a href="https://normia.dev/">https://normia.dev/</a> and let’s talk. I’m excited to connect and support your testing journey.</p><h3>Stackademic</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1390885c5cc2" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/elevate-your-cypress-tests-a-guide-to-custom-commands-and-environments-1390885c5cc2">Elevate Your Cypress Tests: A Guide to Custom Commands and Environments</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>