<?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 Tarun Maini ⚡️ on Medium]]></title>
        <description><![CDATA[Stories by Tarun Maini ⚡️ on Medium]]></description>
        <link>https://medium.com/@mainitarun7?source=rss-d7d6a694ec7d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TntlyyRtU2CFhvn4fTKUGw.jpeg</url>
            <title>Stories by Tarun Maini ⚡️ on Medium</title>
            <link>https://medium.com/@mainitarun7?source=rss-d7d6a694ec7d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:39:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mainitarun7/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[Best Practices to Master Clean and Maintainable Cypress Tests with Code]]></title>
            <link>https://medium.com/@mainitarun7/best-practices-to-master-clean-and-maintainable-cypress-tests-with-code-e40650e0654f?source=rss-d7d6a694ec7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e40650e0654f</guid>
            <dc:creator><![CDATA[Tarun Maini ⚡️]]></dc:creator>
            <pubDate>Thu, 09 May 2024 08:46:19 GMT</pubDate>
            <atom:updated>2024-05-09T08:46:19.351Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of automated testing, writing clean and maintainable Cypress tests is essential for ensuring the reliability and scalability of your test suite. By following best practices and leveraging effective coding techniques, you can streamline your testing process and improve overall efficiency. In this blog post, we’ll explore ten key best practices for writing clean and maintainable Cypress tests, accompanied by helpful code snippet examples to illustrate each point</p><p><strong>Plan Your Test Suite:</strong> Before diving into writing tests, take some time to plan your test suite structure. Define clear objectives and organize your tests into logical groups based on features or functionality. Here’s an example of how you can structure your test suite using Cypress’s describe blocks</p><pre>describe(&#39;Login Feature&#39;, () =&gt; {<br>  it(&#39;should allow users to login successfully&#39;, () =&gt; {<br>    // Test code goes here<br>  });<br><br>  it(&#39;should display an error message for invalid credentials&#39;, () =&gt; {<br>    // Test code goes here<br>  });<br>});<br><br>describe(&#39;User Profile Feature&#39;, () =&gt; {<br>  it(&#39;should display user information correctly&#39;, () =&gt; {<br>    // Test code goes here<br>  });<br><br>  it(&#39;should allow users to update their profile&#39;, () =&gt; {<br>    // Test code goes here<br>  });<br>});</pre><p><strong>Use conditional Waiting instead of Hard Wait</strong></p><p>In this example, we’re using a hard-coded wait of 2 seconds (cy.wait(2000)) to wait for the success message to appear after submitting the form. This approach is not recommended as it introduces unnecessary delays and can make tests flaky if the actual wait time varies</p><pre>// Bad practice: Using hard-coded wait<br>it(&#39;should display a success message after submitting the form (bad practice)&#39;, () =&gt; {<br>  cy.visit(&#39;/form&#39;);<br>  cy.get(&#39;form&#39;).submit();<br><br>  // Hard-coded wait for 2 seconds<br>  cy.wait(2000);<br>  cy.get(&#39;.success-message&#39;).should(&#39;be.visible&#39;);<br>});</pre><p>In this example, we’re using conditional waiting based on the presence of the success message (cy.get(&#39;.success-message&#39;, { timeout: 10000 })). Cypress will wait up to 10 seconds for the success message to become visible. This approach ensures that the test waits only as long as necessary and makes it more reliable and efficient.</p><p>By using conditional waiting instead of hard-coded waits, we improve the stability, reliability, and performance of our Cypress tests, leading to faster and more robust test execution</p><pre>// Good practice: Using conditional waiting<br>it(&#39;should display a success message after submitting the form (good practice)&#39;, () =&gt; {<br>  cy.visit(&#39;/form&#39;);<br>  cy.get(&#39;form&#39;).submit();<br><br>  // Conditional waiting based on the presence of success message<br>  cy.get(&#39;.success-message&#39;, { timeout: 10000 }).should(&#39;be.visible&#39;);<br>});</pre><p><strong>Keep Tests Atomic and Independent: </strong>Write tests that focus on one specific functionality or scenario, and avoid dependencies between tests. Use beforeEach and afterEach hooks to set up and clean up test state as needed. Here’s an example</p><pre>describe(&#39;Login Feature&#39;, () =&gt; {<br>  beforeEach(() =&gt; {<br>    cy.visit(&#39;/login&#39;);<br>  });<br><br>  it(&#39;should allow users to login successfully&#39;, () =&gt; {<br>    // Test code goes here<br>  });<br><br>  it(&#39;should display an error message for invalid credentials&#39;, () =&gt; {<br>    // Test code goes here<br>  });<br>  <br>  afterEach(() =&gt; {<br>    cy.resetDbState()<br>  });<br><br>});</pre><p><strong>Use Descriptive Test Names and Assertions:</strong> Choose descriptive names for your tests that clearly convey their purpose and expected outcome. Use meaningful assertions to verify the behavior of the application. Here’s an example:</p><pre>it(&#39;should display an error message when login credentials are invalid&#39;, () =&gt; {<br>  cy.visit(&#39;/login&#39;);<br>  cy.get(&#39;#username&#39;).type(&#39;invalid_username&#39;);<br>  cy.get(&#39;#password&#39;).type(&#39;invalid_password&#39;);<br>  cy.get(&#39;form&#39;).submit();<br>  cy.get(&#39;.error-message&#39;).should(&#39;be.visible&#39;);<br>});</pre><p><strong>Use Page Objects Pattern</strong>: Implement the Page Objects pattern to encapsulate page elements and interactions. Separate page-specific logic from test logic to improve maintainability. Here’s an example of a page object for a login page</p><pre>// loginPage.js<br>class LoginPage {<br>  visit() {<br>    cy.visit(&#39;/login&#39;);<br>  }<br><br>  fillUsername(username) {<br>    cy.get(&#39;#username&#39;).type(username);<br>    return this; // Return the LoginPage object for method chaining<br>  }<br><br>  fillPassword(password) {<br>    cy.get(&#39;#password&#39;).type(password);<br>    return this; // Return the LoginPage object for method chaining<br>  }<br><br>  submitForm() {<br>    cy.get(&#39;form&#39;).submit();<br>  }<br><br>  login(username, password) {<br>    return this<br>      .visit()<br>      .fillUsername(username)<br>      .fillPassword(password)<br>      .submitForm();<br>  }<br>}<br><br>export default new LoginPage();</pre><blockquote>Now, let’s use this Page Object in a Cypress test:</blockquote><pre>// login.spec.js<br>import LoginPage from &#39;../pageObjects/loginPage&#39;;<br><br>describe(&#39;Login Feature&#39;, () =&gt; {<br>  it(&#39;should allow users to login successfully&#39;, () =&gt; {<br>    const username = &#39;test_user&#39;;<br>    const password = &#39;test_password&#39;;<br><br>    LoginPage.login(username, password);<br><br>    // Add assertions here to verify successful login<br>    cy.url().should(&#39;eq&#39;, &#39;/dashboard&#39;);<br>  });<br><br>  it(&#39;should display an error message for invalid credentials&#39;, () =&gt; {<br>    const username = &#39;invalid_user&#39;;<br>    const password = &#39;invalid_password&#39;;<br><br>    LoginPage.login(username, password);<br><br>    // Add assertions here to verify error message<br>    cy.get(&#39;.error-message&#39;).should(&#39;be.visible&#39;);<br>  });<br>});</pre><p><strong>Manage Test Data Effectively</strong>: Use fixtures or mock data to ensure consistent test data across environments. Minimize reliance on hard-coded data within tests. Here’s an example of using fixtures to populate form fields:</p><p>Let’s say we have a JSON fixture file named user.json containing user data</p><pre>// user.json<br>{<br>  &quot;name&quot;: &quot;John Doe&quot;,<br>  &quot;email&quot;: &quot;john@example.com&quot;<br>}</pre><p>We can use this fixture to populate form fields in our Cypress test</p><pre>// Using fixtures for test data<br>it(&#39;should display user information correctly&#39;, () =&gt; {<br>  cy.fixture(&#39;user.json&#39;).then((user) =&gt; {<br>    cy.visit(&#39;/profile&#39;);<br>    cy.get(&#39;#name&#39;).should(&#39;have.value&#39;, user.name);<br>    cy.get(&#39;#email&#39;).should(&#39;have.value&#39;, user.email);<br>  });<br>});</pre><p><strong>Maintain a Consistent Test Structure</strong>: Establish a consistent structure and formatting style for your test code. Follow a standardized naming convention for files, folders, and test functions. Here’s an example of organizing test files using Cypress’s folder structure:</p><pre>cypress/<br>├── fixtures/                   // Test data fixtures<br>│   ├── example.json            // Example fixture file<br>├── integration/                // Test files<br>│   ├── login.spec.js           // Example test file<br>│   ├── profile.spec.js         // Example test file<br>│   └── ...<br>├── plugins/                    // Cypress plugins<br>│   ├── index.js                // Example plugin file<br>├── reports/                    // Test reports<br>│   ├── html/                   // HTML reports<br>│   │   ├── index.html          // Main HTML report file<br>│   │   └── ...<br>│   ├── junit/                  // JUnit XML reports<br>│   │   ├── report.xml          // Example XML report file<br>│   │   └── ...<br>│   └── ...<br>├── screenshots/                // Screenshots captured during tests<br>├── support/                    // Support files<br>│   ├── commands.js             // Custom Cypress commands<br>│   ├── index.js                // Custom configuration<br>│   └── ...<br>├── videos/                     // Videos captured during test runs<br>├── cypress.json                // Cypress configuration file<br>├── .gitlab-ci.yml              // GitLab CI/CD configuration file<br>├── .env.dev                    // Environment configuration file for development<br>├── .env.staging                // Environment configuration file for staging<br>├── .env.prod                   // Environment configuration file for production<br>├── mockServer/                 // Mock server files<br>│   ├── routes.js               // Route handlers for mock server<br>│   ├── data/                   // Mock data files<br>│   │   ├── users.json          // Example mock data file<br>│   │   └── ...<br>│   └── ...<br>└── package.json                // Node.js package file</pre><p><strong>Use Cypress Custom Commands</strong>: Custom commands allow you to encapsulate frequently used actions or assertions, promoting reusability and readability in your tests. Here’s an example of defining and using a custom command to log in:</p><pre>// Define custom command in support/commands.js<br>Cypress.Commands.add(&#39;login&#39;, (username, password) =&gt; {<br>  cy.visit(&#39;/login&#39;);<br>  cy.get(&#39;#username&#39;).type(username);<br>  cy.get(&#39;#password&#39;).type(password);<br>  cy.get(&#39;form&#39;).submit();<br>});<br><br>// Use custom command in your test<br>it(&#39;should allow users to login successfully&#39;, () =&gt; {<br>  cy.login(&#39;valid_username&#39;, &#39;valid_password&#39;);<br>  cy.url().should(&#39;eq&#39;, &#39;/dashboard&#39;);<br>});</pre><p><strong>Use Data Attributes for Selectors: </strong>Using data attributes for selectors instead of relying on specific element IDs or classes improves the resilience of your tests to UI changes. Here’s an example:</p><pre>&lt;!-- HTML --&gt;<br>&lt;button data-testid=&quot;login-button&quot;&gt;Login&lt;/button&gt;</pre><pre>// Cypress Test<br>it(&#39;should allow users to login successfully&#39;, () =&gt; {<br>  cy.visit(&#39;/login&#39;);<br>  cy.get(&#39;[data-testid=login-button]&#39;).click();<br>  cy.url().should(&#39;eq&#39;, &#39;/dashboard&#39;);<br>});</pre><p><strong>Handle Authentication with Cypress Intercept:</strong> Use Cypress intercept to stub network requests and handle authentication in your tests. This helps simulate different server responses and speeds up test execution. Here’s an example of stubbing a successful login request:</p><pre>// Handle Authentication with Cypress Routes<br>it(&#39;should allow users to login successfully&#39;, () =&gt; {<br>  cy.intercept(&#39;POST&#39;, &#39;/api/login&#39;, (req) =&gt; {<br>    req.reply((res) =&gt; {<br>      // Mock a successful login response with a JWT token<br>      res.send({<br>        status: &#39;success&#39;,<br>        token: &#39;example_jwt_token&#39;<br>      });<br>    });<br>  }).as(&#39;login&#39;);<br><br>  cy.visit(&#39;/login&#39;);<br>  cy.get(&#39;#username&#39;).type(&#39;valid_username&#39;);<br>  cy.get(&#39;#password&#39;).type(&#39;valid_password&#39;);<br>  cy.get(&#39;form&#39;).submit();<br><br>  cy.wait(&#39;@login&#39;);<br>  cy.url().should(&#39;eq&#39;, &#39;/dashboard&#39;);<br>});</pre><p><strong>Use Environment Variables for Configurations</strong>: Utilize Cypress’s support for environment variables to manage configurations such as base URLs, credentials, or API endpoints. Here’s an example:</p><pre>// Set environment variables in cypress.json or through CI/CD pipeline<br>{<br>  &quot;env&quot;: {<br>    &quot;BASE_URL&quot;: &quot;https://example.com&quot;,<br>    &quot;API_URL&quot;: &quot;https://api.example.com&quot;,<br>    &quot;USERNAME&quot;: &quot;test_user&quot;,<br>    &quot;PASSWORD&quot;: &quot;test_password&quot;<br>  }<br>}<br><br>// Access environment variables in your tests<br>it(&#39;should login using credentials from environment variables&#39;, () =&gt; {<br>  const username = Cypress.env(&#39;USERNAME&#39;);<br>  const password = Cypress.env(&#39;PASSWORD&#39;);<br>  <br>  cy.visit(&#39;/login&#39;);<br>  cy.get(&#39;#username&#39;).type(username);<br>  cy.get(&#39;#password&#39;).type(password);<br>  cy.get(&#39;form&#39;).submit();<br>});</pre><p>There are different ways to set environment variables. Each has a slightly different use case.</p><p><strong><em>To summarize you can:</em></strong></p><ul><li><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-1-configuration-file">Set in your configuration file</a></li><li><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-2-cypressenvjson">Create a </a><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-2-cypressenvjson">cypress.env.json</a></li><li><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_">Export as </a><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_">CYPRESS_*</a></li><li><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-4---env">Pass in the CLI as </a><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-4---env">--env</a></li><li><a href="https://docs.cypress.io/guides/guides/environment-variables#Option-5-Test-Configuration">Set an environment variable within test configuration.</a></li></ul><p>Don’t feel obligated to pick just one method. It is common to use one strategy for local development but another when running in <a href="https://docs.cypress.io/guides/continuous-integration/introduction">CI</a>.</p><p>There are lot more good practices to follow, but above are basic and must be done to have good experience while maintaining a framework. Feel free to customize the code snippets and examples to better fit your specific use cases and preferences. Happy testing!</p><p>Ref: <a href="https://docs.cypress.io/">https://docs.cypress.io/</a></p><p><a href="https://www.linkedin.com/in/tarunmaini9/">LinkedIN</a> ^ <a href="https://github.com/tarunmaini16">Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e40650e0654f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notifications for Out-of-Stock essentials during covId_19]]></title>
            <link>https://medium.com/@mainitarun7/notifications-for-out-of-stock-essentials-during-covid-19-ce5183727ee1?source=rss-d7d6a694ec7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce5183727ee1</guid>
            <category><![CDATA[flipkart]]></category>
            <category><![CDATA[grofers]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[shopping]]></category>
            <dc:creator><![CDATA[Tarun Maini ⚡️]]></dc:creator>
            <pubDate>Sat, 23 May 2020 17:57:01 GMT</pubDate>
            <atom:updated>2020-05-23T17:57:01.985Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Are you tired waiting for the availability of your essential products at e-stores?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*H8_r68G1q34kBVhkh0feng.gif" /></figure><p>If <strong>YES</strong>, then try <strong>Upalabdh</strong> (<strong>chrome Extension</strong>) : Utility to monitor the availability of products at E-Commerce Stores. <a href="https://chrome.google.com/webstore/detail/upalabdh/lmddecfpppmaomiopmlgbeemkdpllhmh">Link to Download</a></p><p>This will let you know as soon as some product is available for purchase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*cIrY1QilSjF8Wz52qhyM5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*iwAjLK1mZcMKiEkV7YwR8w.png" /></figure><p><strong>Some of the features are as follows:</strong></p><ol><li>Allows to save list of products.</li><li>Receive push notifications when the product status changes.</li><li>Coloured indicators to show status of product.</li><li>Ability to add/delete products.</li><li>Supports Amazon, Flipkart and BigBasket</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*B9k4kSlTR0j18SWKFxmZ4A.png" /></figure><p><a href="https://chrome.google.com/webstore/detail/upalabdh/lmddecfpppmaomiopmlgbeemkdpllhmh"><strong>Download from Chrome Web Store</strong></a></p><p>For more details visit webpage: <a href="https://tarunmaini16.github.io/upalabdh.html"><strong>https://tarunmaini16.github.io/upalabdh.html</strong></a></p><p>*This was developed while experiencing the problem of placing orders for essentials during this peak time and for learning purpose. No more waiting now!</p><p>If you want me to add support of moRe E-stores, then just let me know in comment section below</p><p>Feedbacks are welcome :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce5183727ee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[My] “Testing AI / ML Apps” Workshop Experience | Pune]]></title>
            <link>https://medium.com/@mainitarun7/my-testing-ai-ml-apps-workshop-experience-pune-360818fdc3db?source=rss-d7d6a694ec7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/360818fdc3db</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Tarun Maini ⚡️]]></dc:creator>
            <pubDate>Tue, 25 Jun 2019 18:15:25 GMT</pubDate>
            <atom:updated>2020-02-05T17:14:36.178Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Aj1ghXy4ImXX0qjGu-rmA.jpeg" /><figcaption>With Interactive Attendees</figcaption></figure><p>First of all, I would also like to thank <a href="https://twpune.github.io/vodqa/">VodQA Pune</a> community for giving me an opportunity to present &amp; share my knowledge with QA community.</p><p>In this first blog of mine, i want to share my workshop experience with you. This was a hands-on workshop conducted in Pune, titled <br> <strong>“How to test AI/ML Applications”.</strong></p><ol><li>It was a great experience to prepare for workshop when you know that attendees are coming up with different OS at their machines. For this we have to come up with a generic strategy to prevent hiccups during prerequisite installations. So we used almighty docker, and burned all our content inside same, just image-pull was enough to boot-up systems ;)<br>(We also created a temp slack channel in advance to help people with pre-setup installations, which proved really helpful)</li><li>Out prepared workshop activities were targeting to community of all experience types from rookies, intermediates to skilled.</li><li>Workshop consists of three activities</li><li>The main thing to learn here is to know how to manage time when your audience is highly enthusiastic, as we were getting bombarded with lots of real time interesting questions.</li><li>We divided the workshop in two part theory and hands-on<br>First we made them walkthrough following:<br>➢ What is AI/ML<br>➢ How technology is shifting towards AI, ML<br>➢ Where does a QA steps in<br>➢ Challenges while testing AI,ML application<br>and then some more details along with workshop.</li></ol><p><strong>It was a wonderful experience, some of the feedback is as follow:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-dylu3bJeUfboahvOYhcJg.png" /><figcaption>Feedback received</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFwfU6KlKULqNcsWDeoIOA.jpeg" /><figcaption>Post session feedback over Slack channel</figcaption></figure><p><strong>Real Time Image Classification of images(See Video below):</strong></p><p><a href="https://photos.app.goo.gl/wBvmbqfbUKYt89GK8">Untitled</a></p><p>To perform this hands-on exercise, feel free to go through links and ReadMe available @ github and docker hub.</p><p><strong>Github Links:</strong><br><a href="https://github.com/tarunmaini16/beer-wine-classifier">https://github.com/tarunmaini16/beer-wine-classifier</a><br><a href="https://github.com/tarunmaini16/image-classifier">https://github.com/tarunmaini16/image-classifier</a><br><a href="https://github.com/tarunmaini16/android-image-classifier">https://github.com/tarunmaini16/android-image-classifier</a></p><p><strong>Docker Image Links:</strong><br><a href="https://hub.docker.com/r/tarunmaini/wine-beer-classification">https://hub.docker.com/r/tarunmaini/wine-beer-classification</a><br><a href="https://hub.docker.com/r/tarunmaini/image-classifier">https://hub.docker.com/r/tarunmaini/image-classifier</a></p><p>Feel free to contact/ask queries/share knowledge/correct in case of any concerns at below:<br><a href="https://www.linkedin.com/in/tarunmaini79/"><strong>Linkedin</strong></a><strong> . </strong><a href="https://github.com/tarunmaini16"><strong>Github</strong></a><strong> . mtarun@thoughtworks.com</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=360818fdc3db" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>