<?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 Aqsa Tahir on Medium]]></title>
        <description><![CDATA[Stories by Aqsa Tahir on Medium]]></description>
        <link>https://medium.com/@aqsa.tahir_19595?source=rss-c3353cebaa46------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Aqsa Tahir on Medium</title>
            <link>https://medium.com/@aqsa.tahir_19595?source=rss-c3353cebaa46------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:00:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aqsa.tahir_19595/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[Dynamic Token Refresh in K6: A Step-by-Step Guide]]></title>
            <link>https://medium.com/emumba/dynamic-token-refresh-in-k6-a-step-by-step-guide-a8e3ff44d0ea?source=rss-c3353cebaa46------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8e3ff44d0ea</guid>
            <dc:creator><![CDATA[Aqsa Tahir]]></dc:creator>
            <pubDate>Thu, 30 Oct 2025 07:48:53 GMT</pubDate>
            <atom:updated>2025-10-30T07:48:53.787Z</atom:updated>
            <content:encoded><![CDATA[<h4>A practical guide to managing authentication token expiry in K6 performance tests.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J8yOm6NvVSU_7-cj12H4eA.png" /></figure><p><strong>Picture this:</strong> you’ve set up your new k6 performance tests, eager to see how your APIs hold up under load. The scripts fire up, requests start flowing, everything looks smooth… until suddenly, requests begin to fail. Not because your API broke, but because your <strong>authentication token quietly expired mid-test</strong>.</p><p>It’s one of those frustrating moments where your load test results are ruined by something that has nothing to do with the performance of the application being tested. If your tokens expire every few minutes, but your tests run for a longer duration, you’re guaranteed to hit this wall.</p><p>In this blog, I’ll show you how we combined <strong>Node.js, Puppeteer, and Express</strong> to automatically refresh tokens in the background and make sure our <strong>k6 tests always run with valid authentication</strong>.</p><h3>Problem Statement</h3><p>Our challenge:</p><ul><li>API tests take between <strong>1–15 minutes</strong>.</li><li>The <strong>auth token expires after 5 minutes</strong>.</li><li>K6 runs in its own <strong>Go-based JavaScript engine (Goja)</strong>, which means <strong>Node.js modules (like fs)</strong> don’t work.</li></ul><p>If we ignore this issue, our <strong>performance test results become unreliable</strong> because tests fail due to expired tokens instead of system performance.</p><h3>Solution: Step-by-Step Process</h3><p>Here’s the approach we took to keep tokens fresh during long-running K6 tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*0EAEXuWrX3aTEzVF6lXL8A.png" /></figure><p><strong>Step 1: Scheduled Token Refresh Using Node.js</strong></p><p>We already had a login method using <strong>Puppeteer</strong> to fetch tokens. We extended it to <strong>save tokens in a file</strong> and refresh them every 4.5 minutes using setInterval( duration should be close to token expiry).</p><pre>import fs from &#39;fs&#39;;<br><br><br>const tokenFilePath = &#39;./token.json&#39;;<br><br><br>export async function tokenRefresh() {<br>// Assume your login function returns the auth token<br>const authorization = await login();<br>fs.writeFileSync(tokenFilePath, JSON.stringify({<br>access_token: authorization,<br>expires_at: new Date(Date.now() + 4.5 * 60 * 1000).toISOString()<br>}, null, 2));<br>}<br><br><br>setInterval(async () =&gt; {<br>await tokenRefresh();<br>}, 4.5 * 60 * 1000);</pre><p>At this point, we have a <strong>token.json</strong> file that always contains a fresh token. But how do we access this from K6?</p><p><strong>Step 2 : Setting Up a Token Server with Express</strong></p><p>Since K6 does not support Node.js modules like fs, we couldn’t directly read the token from token.json during test execution. To address this, we introduced a lightweight <strong>Express server</strong> that exposes the token via an API endpoint, making it accessible to K6 whenever needed.</p><p>Additionally, we embedded the <strong>token refresh logic (</strong>setInterval<strong>)</strong> within the server itself. This way, the server automatically refreshes the token at regular intervals, eliminating the need to keep a separate login script running in parallel.</p><pre>// token-server.ts<br>import express from &#39;express&#39;;<br>import fs from &#39;fs&#39;;<br><br>const app = express();<br>const port= 4000;<br><br>app.get(&#39;/token&#39;, (req, res) =&gt; {<br>try {<br>const data = JSON.parse(fs.readFileSync(&#39;./token.json&#39;, &#39;utf8&#39;));<br>res.json({ access_token: data.access_token });<br>} catch (err) {<br>res.status(500).json({ error: &#39;Failed to read token&#39; });<br>}<br>});<br><br><br>app.listen(port, () =&gt; {<br> await refreshToken();<br>    setInterval(async () =&gt; {<br>        try {<br>            console.log(&#39; Auto-refreshing token...&#39;);<br>            await refreshToken();<br>        } catch (err) {<br>            console.error(&#39;Token refresh failed:&#39;, err);<br>        }<br>    }, 4.5 * 60 * 1000);<br>});</pre><p>This server:</p><ul><li>Reads the token from the file.</li><li>Exposes it at <a href="http://localhost:4000/token.">http://localhost:4000/token.</a></li><li>Keeps refreshing it in the background.</li></ul><p><strong>Note:</strong> You can either keep the <strong>login and refresh functions</strong> in one file and the <strong>server code</strong> in another, or combine them into a <strong>single file</strong> that handles login, token refresh, and serving the token. Combining everything into one file can simplify setup and reduce the overhead of managing multiple files.</p><p><strong>Step 3: Fetching Fresh Tokens Inside k6</strong></p><p>We created a <strong>separate helper script</strong> (fetchFreshToken.js) that k6 can use to fetch tokens from our local server. This avoids direct file reading (which k6 doesn’t support).</p><pre>// fetchFreshToken.js<br>import http from &#39;k6/http&#39;;<br><br>let authToken = &#39;&#39;;<br>let lastTokenReadTime = 0;<br>const tokenRefreshInterval = 4 * 60 * 1000;<br><br>export function getAuthToken() {<br>  const now = Date.now();<br>  if (!authToken || (now - lastTokenReadTime &gt; tokenRefreshInterval)) {<br>    const res = http.get(&#39;http://localhost:4000/token&#39;);<br>    authToken = JSON.parse(res.body).access_token;<br>    lastTokenReadTime = now;<br>  }<br>  return authToken;<br>}<br><br>export function getParams() {<br>  return {<br>    headers: { Authorization: `Bearer ${getAuthToken()}` }<br>  };<br>}</pre><p><strong>Notice the separation:</strong></p><ul><li>getAuthToken() talks to the local token server and caches the token.</li><li>getParams() updates request headers with the latest token.</li></ul><p>Then, in our actual k6 test scripts, it’s super simple. We are simply calling getParams().</p><pre>import http from &#39;k6/http&#39;;<br>import { getParams } from &#39;./fetchFreshToken.js&#39;;<br><br>export default function () {<br>  const res = http.get(`${__ENV.BASE_URL}/api/data`, getParams());<br>  console.log(`Response: ${res.status}`);<br>}</pre><p>Behind the scenes, getParams() makes sure the header always contains a valid token.</p><p><strong>Step 4: Running k6 &amp; Token Server in Parallel</strong></p><p>At first, we ran the <strong>token server</strong> and <strong>K6 script</strong> in separate terminals. But that was messy. To fix this, we automated both into a <strong>single command</strong> inside package.json:</p><pre>&quot;scripts&quot;: {<br>  &quot;run:k6&quot;: &quot;cross-env TOKEN_SCRIPT=$TOKEN_SCRIPT K6_SCRIPT=$K6_SCRIPT bash -c &#39;ts-node $TOKEN_SCRIPT &amp; PID=$!; trap \&quot;kill $PID 2&gt;/dev/null\&quot; EXIT INT TERM; sleep 20; k6 run --env $K6_SCRIPT; kill -0 $PID 2&gt;/dev/null &amp;&amp; kill $PID 2&gt;/dev/null; wait $PID 2&gt;/dev/null&#39;&quot;<br>}</pre><p>Run it like this:</p><pre>TOKEN_SCRIPT=&lt;path to login file&gt; K6_SCRIPT=&lt;path to k6 script&gt; npm run run:k6</pre><p>This starts the <strong>token server</strong>, waits a bit, runs the <strong>K6 test</strong>, and cleans up afterward.</p><h3>Key Takeaways</h3><ul><li>K6 doesn’t support Node.js modules, so you can’t directly refresh tokens inside K6.</li><li>A <strong>separate Node.js token server</strong> is a reliable workaround.</li><li>By fetching tokens via HTTP inside K6, you ensure your tests <strong>never fail due to expired tokens</strong>.</li><li>Running everything in parallel with an npm script makes the workflow seamless.</li></ul><h3>Final Thoughts</h3><p>Token expiry during performance tests is a <strong>common but solvable challenge</strong>. By combining Puppeteer, Express, and some scripting, we built a reliable pipeline that keeps k6 tests running <strong>without interruptions from expired tokens</strong>.</p><p>If you’re running performance tests on APIs with short-lived tokens, try this approach — it’ll save you a lot of headaches.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8e3ff44d0ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/dynamic-token-refresh-in-k6-a-step-by-step-guide-a8e3ff44d0ea">Dynamic Token Refresh in K6: A Step-by-Step Guide</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unraveling the Secrets of Chatbot Testing]]></title>
            <link>https://medium.com/emumba/unraveling-the-secrets-of-chatbot-testing-fda7f9620ad9?source=rss-c3353cebaa46------2</link>
            <guid isPermaLink="false">https://medium.com/p/fda7f9620ad9</guid>
            <dc:creator><![CDATA[Aqsa Tahir]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 07:53:24 GMT</pubDate>
            <atom:updated>2024-11-12T07:53:24.738Z</atom:updated>
            <content:encoded><![CDATA[<p>In the dynamic landscape of technological advancements, chatbots have emerged as indispensable tools for businesses seeking to enhance customer interactions and streamline communication. Testing chatbots can be tricky and might leave us scratching our heads to figure out HOW?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*xnhnPaVuKVfZCP3sdO4hCw.gif" /></figure><p>Well, Welcome aboard testing enthusiasts. In this blog post, we’ll delve into the intricacies of chatbot testing, exploring its best practices along with its challenges.</p><h4>Best Practices in Chatbot Testing:</h4><ol><li><strong>Define Test Scenarios:</strong></li></ol><p>Before diving into testing, it’s crucial to define the various scenarios that your chatbot will encounter. Categorize them into scripted scenarios (predefined inputs and expected outputs) and unscripted scenarios (real-world, unpredictable inputs).</p><p><strong>2. Test Chabot’s Ability To Validate Inputs:</strong></p><p>Test whether it can handle unexpected or unusual situations, such as when a user inputs gibberish or ambiguous input.</p><p><strong>3. Natural Language Processing (NLP) Testing:</strong></p><p>We need to assess the model’s language understanding capabilities. Test the chatbot’s ability to handle synonyms, variations, and colloquial language. Ensure it can accurately interpret and respond to diverse user inputs.</p><p>Chatbot should be able to recognize human intentions and respond accordingly.</p><p><strong>4. Adhoc Testing:</strong></p><p>It is unstructured and unplanned software testing done to check for flaws or bugs in the chatbot. This type of software testing seeks to identify any potential flaws or errors in the bot functionality.</p><p><strong>5. Domain-specific testing:</strong></p><p>We need to ensure that chatbot is able to answer domain specific queries. In the case of an e-commerce retailer, there could be queries related to types of shoes etc.</p><p><strong>6. Test Chatbot’s Performance:</strong></p><p>Evaluate the chatbot’s performance under different loads to ensure it can handle concurrent user interactions without compromising response time or causing system failures.</p><p><strong>7. Graceful Failure:</strong></p><p>The BOT should always respond with a polite message when it doesn’t understand the query’s intent or the question itself.</p><p><strong>8. Parameters Tweaking:</strong></p><p>In case, the user is given the authority to tweak model parameters then the impact of these parameters on responses needs to be analyzed and tested.</p><p><strong>9. Usability Testing:</strong></p><p>Enlist real users to interact with the chatbot and provide feedback on the user experience. This type of testing uncovers issues that might not be apparent in scripted tests and ensures the chatbot aligns with user expectations.</p><h4>Key Challenges in Chatbot Testing:</h4><ol><li><strong>Ambiguous User Inputs:</strong></li></ol><p>Users can input queries in a multitude of ways, incorporating synonyms, colloquial language, or even typos. Testing must account for these variations to prevent the chatbot from misunderstanding or providing inaccurate responses.</p><p><strong>2. Continuous Learning and Adaptation:</strong></p><p>Some chatbots employ machine learning to improve over time. Testing should address the bot’s ability to adapt, learn from interactions, and continuously enhance its performance.</p><p><strong>3. Ensuring Chatbot has learned sufficient Data:</strong></p><p>We need to ensure that chatbot has access to sufficient amount of data in order to generate accurate responses for all sorts of user queries.</p><p>In conclusion, Testing chatbots is a nuanced process that requires a holistic approach. By combining different testing techniques , prioritizing the usability aspect, and addressing specific challenges we can ensure that chatbots not only meet but exceed user expectations. In the ever-evolving landscape of digital communication, mastering the art of chatbot testing is essential for delivering seamless, efficient, and user-friendly conversational experiences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fda7f9620ad9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/unraveling-the-secrets-of-chatbot-testing-fda7f9620ad9">Unraveling the Secrets of Chatbot Testing</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>