<?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 Bothi Palani on Medium]]></title>
        <description><![CDATA[Stories by Bothi Palani on Medium]]></description>
        <link>https://medium.com/@bothees?source=rss-737bd6a5ed0f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*thRBzx1ewgb7E659cSzr_g.jpeg</url>
            <title>Stories by Bothi Palani on Medium</title>
            <link>https://medium.com/@bothees?source=rss-737bd6a5ed0f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:25:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bothees/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[Compare pdf reports using cypress & compre-pdf plugin]]></title>
            <link>https://bothees.medium.com/compare-pdf-reports-using-cypress-compre-pdf-plugin-812ea20490d6?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/812ea20490d6</guid>
            <category><![CDATA[pdf-comparison]]></category>
            <category><![CDATA[cypressio]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Sat, 22 Feb 2025 08:28:51 GMT</pubDate>
            <atom:updated>2025-02-22T08:28:51.642Z</atom:updated>
            <content:encoded><![CDATA[<p>It would be a boring task to compare different versions of pdf report after every release of the application.</p><p>I tried to automate comparing the pdf reports using cypress &amp; compare-pdf plugin.</p><p>I have put together everything in a repo and here is the link on the github.</p><p><a href="https://github.com/Bothees/cypress-pdf-compare">GitHub - Bothees/cypress-pdf-compare</a></p><p>It has 2 tests to compare same version / contents of the pdf files and different versions of the files and assert the outcome.</p><p>once the comparison done, it automatically creates a folder structure <strong>png </strong>inside fixtures. <strong>diff </strong>folder contains files with differences highlighted in red.</p><figure><img alt="png folder structure after the comparison" src="https://cdn-images-1.medium.com/max/615/1*Vx8Y6MmqFbXYtL7AuWZicA.png" /></figure><p>refer <a href="https://www.npmjs.com/package/compare-pdf">https://www.npmjs.com/package/compare-pdf</a> for setup instructions for different OS.</p><p>All the settings like path to actual and baseline files specified in <strong>comparePdfConfig.ts</strong></p><p>There are advanced options can be passed as parameters to the <strong>compare-pdf </strong>for comparison.</p><p>specific areas on the pdf page can be cropped / masked and specific page also can be skipped for comparison.</p><pre>const opts = {<br>    croppings: [ { pageIndex: 0, coordinates: { width: 600, height: 155, x: 0, y: 195} } ],<br>    skipPageIndexes: [1],<br>    masks : [{ pageIndex: 0, coordinates: { width: 600, height: 155, x: 0, y: 195} },<br>             { pageIndex: 0, coordinates: { width: 600, height: 155, x: 0, y: 195} },<br>             { pageIndex: 0, coordinates: { width: 600, height: 155, x: 0, y: 195} }<br>            ]<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=812ea20490d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lighthouse performance testing with Playwright]]></title>
            <link>https://bothees.medium.com/lighthouse-performance-testing-with-playwright-b6467a2d39c2?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6467a2d39c2</guid>
            <category><![CDATA[lighthouse]]></category>
            <category><![CDATA[playwright-automation]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Tue, 02 Apr 2024 14:45:39 GMT</pubDate>
            <atom:updated>2024-04-02T14:45:39.301Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>what is Lighthouse ?</strong></h3><p>Lighthouse is an open-source, automated tool for improving the performance, quality, and correctness of your web apps.</p><p>When auditing a page, Lighthouse runs a barrage of tests against the page, and then generates a report on how well the page did. From here you can use the failing tests as indicators on what you can do to improve your app.</p><p>There are different ways to run lighthouse tests against web pages, let us look at here, how to run it from playwright automation.</p><p>if you already have a playwright automation project setup then install the following npm module</p><pre>npm install unlighthouse dotenv</pre><p>Create a config file at the root level, <em>unlighthouse-config.ts</em></p><pre>import dotenv from &#39;dotenv&#39;;<br>dotenv.config();<br>const sitemapURL: string = process.env.BASE_URL!;<br>const device : string = process.env.DEVICE!;<br><br>export default {<br>    site: sitemapURL,<br>    scanner: {<br>        sitemap: [&#39;/sitemap.xml&#39; ],<br>        robotsTxt: false,<br>        // use mobile to scan<br>        device: device,<br>    },<br>    ci: {<br>        budget: {<br>            throttle: 90<br>        },<br>        buildStatic:true<br>    },<br>    cache: false,<br>    debug: true,<br>    extraHeaders: {<br>        // add any username, password or any security token <br>    },<br>}</pre><p>Get your project baseUrl and Device type { Mobile or Desktop } throguh environment variables.</p><p>Run the following command from root directory to run lighthouse and generate report</p><pre>npx unlighthouse</pre><p>You would see a report once the test is completed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*CCC1-_RymglO55wsZ-jfWw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6467a2d39c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to download SSL certs from kubernetes pod with cypress tests]]></title>
            <link>https://bothees.medium.com/how-to-download-ssl-certs-from-kubernetes-pod-with-cypress-tests-3591aef8b274?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3591aef8b274</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cypressio]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 21:32:25 GMT</pubDate>
            <atom:updated>2024-03-26T21:32:25.335Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*dY1VMEWe0D9WFVx5aHJT3Q.gif" /><figcaption>SSL authentication from Cypress tests</figcaption></figure><p>There are few automation tests needed to have the ssl certs configured for authentication. when you run the tests on pipeline, certs are mounted on the kubernetes pods however certs needs to be downloaded and kept in local folder for running it from local machine.</p><p>Certs can be downloaded manually using the following kubectl command</p><pre>kubectl cp &lt;certs path inside pod&gt; ./certs -n &lt;namespace&gt;<br><br>example<br><br>kubectl cp cypress-pod:/automation-tests/certs ./certs -n test</pre><p>But when the certs are updated on the server side &amp; if you forgot to download, your tests will be running with the old certs and fail.</p><p>So to avoid the problem, certs can also be downloaded programmatically before test execution started.</p><p>create a Javascript file with any name, I named it <strong>download-ssl-certs.js</strong></p><p><strong>Assumptions:</strong></p><p>There are pods with cypress docker image running on your kube namespace and any apps which contains the SSL certs.</p><p>below code written with pod name contains ‘cypress’, you have to change it for your needs.</p><pre>const fs = require(&#39;fs&#39;);<br><br>const args = process.argv;<br>const env = args[2];<br><br><br>async function importSSLCertsFromCypressPod(env) {<br>  new Promise((resolve, reject) =&gt; {<br>    exec(`kubectl config use-context ${env}`, async err =&gt; {<br>      if (!err) {<br>        exec(`kubectl get pods -o jsonpath={..metadata.name}`, async (err, stdout) =&gt; {<br>          if (!err) {<br>            const cypressPods = stdout.split(&#39; &#39;).filter(name =&gt; name.startsWith(&#39;cypress&#39;));<br>            exec(`kubectl cp ${cypressPods[0]}:/test-repo-name/certs/  ./certs`, async err =&gt; {<br>              if (!err) {<br>                await exec(`mv ./certs/..[A-Za-z0-9]*/** ./certs`, async (err, stdout) =&gt; {<br>                  if (err) {<br>                    console.log(&#39;error with moving files to certs folder&#39;, stdout);<br>                  }<br>                });<br>              } else {<br>                console.log(<br>                  &#39;There are no cypress pod running, please spin up pod using command kubectl scale deploy cypress --replicas=1&#39;,<br>                  stdout,<br>                );<br>              }<br>            });<br>            resolve(true);<br>          }<br>          reject(err);<br>        });<br>      }<br>    });<br>  };<br><br><br>async function downloadSSLCerts(env) {<br>  try {<br>    const path = &#39;./certs/&#39;;<br>    const regex = /^\..*$/;<br>    fs.readdirSync(path)<br>      .filter(f =&gt; regex.test(f))<br>      .map(f =&gt; fs.rmdirSync(path + f));<br>    const sslCertDownloadStatus = await importSSLCertsFromCypressPod(env);<br>    return !!sslCertDownloadStatus;<br>  } catch (error) {<br>    throw new Error(<br>      `There are no cypress pod running, please spin up pod using command kubectl scale deploy cypress --replicas=1`,<br>    );<br>  }<br>}<br><br>downloadSSLCerts(env).then(status =&gt; {<br>  if (status === true) {<br>    console.log(&#39;SSL certs are downloaded successfully into ./certs folder&#39;);<br>  }<br>});</pre><p>when you run the following command from root of your test repo, ssl certs are downloaded in <strong>certs</strong> folder</p><pre>node download-ssl-certs.js &lt;env-name&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3591aef8b274" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Import secrets from Kubernetes]]></title>
            <link>https://bothees.medium.com/import-secrets-from-kubernetes-829319b5e4d5?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/829319b5e4d5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[kubectl]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 14:42:49 GMT</pubDate>
            <atom:updated>2023-11-16T14:42:49.573Z</atom:updated>
            <content:encoded><![CDATA[<p>what if you need to run your test automation using the secrets used in the project but it is only available in the kubernetes clusters on remote machines, since there may be situations when the local copy is not always sync with the values in the remote machines.</p><p>we should be importing the secrets from kubernetes on the fly and use it when we run our test automation from local machine.</p><p>let us learn in this article about how to import the secrets from kubernetes ?</p><p>This article assumes, you have setup the kubernetes cluster and switched to the correct context on kube.</p><p><em>packages needs to be installed </em><br><em>node-jq &amp; exec</em></p><p>command to get the secrets and map into the json format</p><pre>kubectl get secret secret-name -o jsonpath={.data}</pre><p>use <em>node-jq</em> to run the command to decode the data from base64 encoding and map the json values.</p><pre>jq.run(&#39;. | map_values(@base64d)&#39;, path)</pre><p>create the modules to execute the kube command and jq command in a file called secret.js file and run the command node secret.js</p><pre>const path = &#39;./secret.json&#39;;<br>const jq = require(&#39;node-jq&#39;);<br>const { writeFileSync } = require(&#39;fs&#39;);<br><br>module.exports.importSecrets = () =&gt;<br>  new Promise((resolve, reject) =&gt; {<br>    exec(`kubectl get secret secret-name -o jsonpath={.data}`, async (err, stdout) =&gt; {<br>      if (!err) {<br>        const decode = JSON.parse(stdout);<br>        const temp = JSON.stringify(decode);<br><br>        try {<br>          writeFileSync(path, temp, &#39;utf8&#39;);<br>          resolve(true);<br>        } catch (error) {<br>          console.log(&#39;An error has occurred &#39;, error);<br>        }<br>      }<br>      reject(err);<br>    });<br>  });<br><br><br>module.exports.getDecodedSecrets = config =&gt;<br>  new Promise(resolve =&gt; {<br>    jq.run(&#39;. | map_values(@base64d)&#39;, path).then(output =&gt; {<br>      resolve({ JSON.parse(output.replace(/\r?\n|\r/g, &#39;&#39;)) }));<br>    });<br>  });<br><br><br>async function getSecrets() {<br>  const isSecretsDownloaded = await importSecrets();<br>  if (isSecretsDownloaded === true) {<br>    await getDecodedSecrets().then(async secrets =&gt; {<br>      try {<br>         return secrets;<br>      } catch (err) {<br>        console.log(&#39;Error writing the secrets file&#39;, err);<br>        return false;<br>      }<br>    });<br>  } else {<br>    console.log(&#39;Problem with importing secrets, check if you are on the correct kube context&#39;);<br>    return false;<br>  }<br>}<br><br>getSecrets();</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=829319b5e4d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cypress API request with aws4 signature]]></title>
            <link>https://bothees.medium.com/cypress-api-request-with-aws4-signature-48e4a320f44f?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/48e4a320f44f</guid>
            <category><![CDATA[aws-authentication]]></category>
            <category><![CDATA[aws4]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[cypress]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Tue, 07 Nov 2023 10:09:04 GMT</pubDate>
            <atom:updated>2023-11-07T10:09:04.650Z</atom:updated>
            <content:encoded><![CDATA[<p>I searched everywhere in the internet for how to make an API request using cypress with AWS version 4 signature authorisation but no luck then I referred few documents and found the solution.</p><p>So I am sharing how I have done cypress API request using aws4 sign, it might me saving someone’s time :)</p><p>package needs to be installed:</p><pre>npm install aws4</pre><p>Create a custom function inside Commands.js , I have used <em>service</em> parameter as <em>lambda, it could be any of the aws services like s3 etc.</em></p><pre>const baseUrl = &#39;Your base URL here&#39; ;<br><br>Cypress.Commands.add(&#39;postRequestWithaws4&#39;, (resourcePath, body) =&gt; {<br>   <br>   let options = {<br>     method : &#39;POST&#39;,<br>     body: JSON.stringfy(body),<br>     url: `https://${baseUrl}${resourcePath}`,<br>     data: body,<br>     headers: {<br>               &#39;Content-Type&#39;: &#39;application/json&#39;,<br>              }, <br>     service: lambda, <br>     region : eu-west-2,<br>     host: baseUrl<br>   }<br><br>   const awsCredentials = {<br>     accessKeyId: &#39;YOUR_ACCESS_KEY_ID&#39;,<br>     secretAccessKey: &#39;YOUR_SECRET_ACCESS_KEY&#39;,<br>   }<br><br>  // Merge options with default headers and AWS credentials<br>   options = aws4.sign(options, awsCredentials);<br>   <br>  // Make the HTTP request with the signed headers<br>   return cy.request(options);<br>  <br>});<br><br><br>Cypress.Commands.add(&#39;getRequestWithaws4&#39;, (resourcePath) =&gt; {<br>   <br>   let options = {<br>     method : &#39;GET&#39;,<br>     url: `https://${baseUrl}${resourcePath}`,<br>     service: lambda,<br>     region : eu-west-2,<br>     host: baseUrl,<br>     path: resourcePath  <br>   }<br><br>   const awsCredentials = {<br>    accessKeyId: &#39;YOUR_ACCESS_KEY_ID&#39;,<br>    secretAccessKey: &#39;YOUR_SECRET_ACCESS_KEY&#39;,<br>   }<br><br>   options = aws4.sign(options, awsCredentials);<br>   <br>   return cy.request(options);<br>  <br>});</pre><p>send the API request from your test and check the status code and response</p><pre>const resourcePath = &#39;/resourcePath/resource&#39;; something like /key/create-key/<br><br>const data = {<br>  example : &#39;data&#39;,<br>  something : &#39;something&#39;<br>}<br><br>cy.postRequestWithaws4(resourcePath, data).then((response) =&gt; {<br>    expecte(response.statusCode).to.be.eq(200);<br>});<br><br><br>cy.getRequestWithaws4(resourcePath).then((response) =&gt; {<br>    expecte(response.statusCode).to.be.eq(200);<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48e4a320f44f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to import environment variable from AWS secrets manager & use it for Cypress test automation]]></title>
            <link>https://bothees.medium.com/how-to-import-environment-variable-from-aws-secrets-manager-use-it-for-cypress-test-automation-dcd2b4c87340?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcd2b4c87340</guid>
            <category><![CDATA[aws-secrets-manager]]></category>
            <category><![CDATA[cypressio]]></category>
            <category><![CDATA[cypress-testing]]></category>
            <category><![CDATA[cypress-automation]]></category>
            <category><![CDATA[environment-configuration]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Mon, 09 Oct 2023 20:20:10 GMT</pubDate>
            <atom:updated>2023-10-09T20:20:10.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VV-mAZPdftfMMXRBDKOxDg.png" /></figure><p>I worked in a project for end to end automation where the application deployed on aws cloud so some of the details like auth_realm, auth_clientid , auth_base_url etc required for authentication were stored in aws secrets manager.</p><p>In this story, let us learn about importing secrets stored in aws and merge these values along with cypress default configuration.</p><p>As you know end to end tests have to be run across different environments, Cypress allows you define environment specific variables with different ways as outlined here, <a href="https://docs.cypress.io/guides/guides/environment-variables">https://docs.cypress.io/guides/guides/environment-variables</a></p><p>one of the ways to achieve multiple environment setup is to create environment specific json file to store the key &amp; value pair. For example create a file <em>dev.json </em>and add the values</p><pre>{<br>  &quot;env&quot;: {<br>    baseurl: https://dev.com<br>  }<br>}</pre><p>create another file, test.json</p><pre>{<br>  &quot;env&quot;: {<br>    baseurl: https://test.com<br>  }<br>}</pre><p>It is not recommended to put down and check-in the secrets in these files, so we have to import them and add on the fly during the test execution.</p><p>packages need to be installed : <em>@aws-sdk/client-secrets-manager</em></p><p>create a method in <em>cypress.config.ts</em> to load the environment variables from specfif file</p><pre>// Load configuration from an environment specific file.<br>// By default this will load from the &#39;ci&#39; environment file.<br>// Environment file is specified by the fileConfig Cypress env var.<br>async function getConfigurationByFile(config) {<br>  const file = config.env.fileConfig || &#39;ci&#39;;<br>  const pathToConfigFile = path.resolve(&#39;.&#39;, &#39;cypress&#39;, &#39;config&#39;, `${file}.json`);<br>  const fileConfig = await fs.readJson(pathToConfigFile);<br>  const merged = merge(config, fileConfig);<br>  return merged;<br>}</pre><p>create another method in <em>cypress.config.ts </em>to load secrets from aws secret manager. Prerequisite for this one AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY should be set in the <em>terminal before running the tests.</em></p><pre>const { SecretsManagerClient, GetSecretValueCommand } = require(&#39;@aws-sdk/client-secrets-manager&#39;);<br><br>// Load configuration from AWS secrets manager<br>// Useful for test secrets which are environment specific.<br>async function getConfigurationFromSecretsManager(config) {<br>  const client = new SecretsManagerClient({<br>    region: &#39;eu-west-1&#39;,<br>  });<br>  const command = new GetSecretValueCommand({<br>    SecretId: &#39;qa/secrets/test-secrets&#39;,<br>  });<br><br>  const secretData = await client.send(command);<br><br>  const secret =<br>    &#39;SecretString&#39; in secretData ? secretData.SecretString : Buffer.from(secretData.SecretBinary, &#39;base64&#39;);<br><br>  return merge(config, {<br>    env: JSON.parse(secret),<br>  });<br>}</pre><p>merge both the environment specific variables inside the setupNode events and all the variables loaded on environment variables section.</p><pre>const merge = require(&#39;lodash.merge&#39;);<br><br>module.exports = defineConfig({<br>  e2e: {<br>    setupNodeEvents(on, cypressConf) {<br>      const mergedConfig = getConfigurationByFile(cypressConf)<br>        .then(getConfigurationFromSecretsManager);<br>      return mergedConfig;<br>    },<br>  },<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcd2b4c87340" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to grep logs from Kubernetes pods using Cypress TAF]]></title>
            <link>https://bothees.medium.com/how-to-grep-logs-from-kubernetes-pods-using-cypress-taf-acb48fe2cc81?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/acb48fe2cc81</guid>
            <category><![CDATA[grep]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[cypress-automation]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Fri, 06 Oct 2023 15:53:08 GMT</pubDate>
            <atom:updated>2023-10-06T15:53:08.284Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever needed to connect to Kube pods from your automation tests to extract log messages and use it in the tests ? then this story is for you !</p><p>Let us learn about creating custom task in cypress commands.js file to execute command to connect with Kube pods and grep the log message with specific pattern.</p><p>we have to use Cypress <a href="https://docs.cypress.io/api/commands/exec"><em>exec</em></a><em> to run system commands.</em></p><p>Generally there would be more than one pod for a service. So following code snippet loops through each pod and execute the system command to tail the log &amp; grep for specific pattern.</p><p>If the grep command is successful then it returns code <em>0</em> else returns <em>1</em>.</p><pre>Cypress.Commands.add(&#39;getKubePodsLog&#39;, (path, grepString) =&gt; {<br>  let report;<br>  const podList = [&#39;pod1&#39;, &#39;pod2&#39;];<br>  podList.forEach(pod =&gt; {<br>    cy.exec(`kubectl exec -it  ${pod} -- //bin/sh -c &quot;tail -30 ${path} | grep &#39;${grepString}&#39;&quot;`, {<br>      failOnNonZeroExit: false,<br>    })<br>      .then(log =&gt; {<br>        if (log.code === 0) {<br>          report = log.stdout;<br>        } else {<br>          console.log(`Expected pattern not found on ${pod}`);<br>        }<br>      })<br>      .then(() =&gt; report);<br>  });<br>});</pre><p>Use the custom command in your test to get the actual log pattern and compare with the expected result.</p><pre>cy.getKubePodsLog(path, string).then((actualLog) =&gt; {<br>  expect(actualLog).contains(&#39;expected String&#39;);<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acb48fe2cc81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intercepting specific XHR request when there are more than one request with the same URL]]></title>
            <link>https://bothees.medium.com/intercepting-specific-xhr-request-when-there-are-more-than-one-request-with-the-same-url-17fe08d81006?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/17fe08d81006</guid>
            <category><![CDATA[intercepts]]></category>
            <category><![CDATA[xhr]]></category>
            <category><![CDATA[cypress-automation]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Thu, 05 Oct 2023 20:06:45 GMT</pubDate>
            <atom:updated>2023-10-05T20:06:45.277Z</atom:updated>
            <content:encoded><![CDATA[<p>This story is about using network wait in end to end automation tests.</p><p>when I was working for an end to end cypress tests for one of the projects, some tests were flaky because of test was looking for elements in the page but page is not loaded with the expected elements. There may be delay when Front end sends a query to get the data from Back end.</p><p>How can we wait for the request to be completed and continue with the next steps ?</p><p>Cypress framework has <a href="https://docs.cypress.io/api/commands/intercept">intercept</a> which can be used to wait for the network (xhr) requests. However what if there are more than one request with the same url but with different payloads needs to be intercepted ?</p><p>In my project, login users are created on AWS cognito user pool. Challenge for automation is to extract the Auth Token from one of the requests ( all the aws cognito login request URL looks the same except the headers and payload ) and store the token for using in API requests.</p><p>For example, when you look at the network tab after click on the login button there would be few request with this URL, <a href="https://cognito-idp.eu-west-1.amazonaws.com/"><em>https://cognito-idp.eu-west-1.amazonaws.com/</em></a></p><p>However I have to intercept the request with the header value, <em>‘X-Amz-Target’: ‘AWSCognitoIdentityProviderService.RespondToAuthChallenge’ and request body contains specific challenge name.</em></p><p>Following is the code snippet used to intercept the specific request.</p><pre>cy.intercept(<br>  {<br>    method: &#39;POST&#39;,<br>    url: &#39;https://cognito-idp.eu-west-1.amazonaws.com/&#39;,<br>    headers: {<br>      &#39;X-Amz-Target&#39;: &#39;AWSCognitoIdentityProviderService.RespondToAuthChallenge&#39;,<br>    },<br>  },<br>  req =&gt; {<br>    if (req.body.ChallengeName === &#39;NEW_PASSWORD_REQUIRED&#39;) {<br>      req.alias = &#39;token&#39;;<br>    }<br>  },<br>);<br>cy.wait(&#39;@token&#39;).then(({ response }: any) =&gt; {<br>  const authToken = response.body.AuthenticationResult.AccessToken;<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17fe08d81006" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to configure SSL certs for automation test with Cypress.io]]></title>
            <link>https://bothees.medium.com/how-to-configure-ssl-certs-for-automation-test-with-cypress-io-cd0b41f49a20?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd0b41f49a20</guid>
            <category><![CDATA[cypressio]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[cypress-automation]]></category>
            <category><![CDATA[cypress-testing]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Wed, 04 Oct 2023 22:20:48 GMT</pubDate>
            <atom:updated>2023-10-04T22:20:48.237Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bMh9pD7h3G6Od50YcDooXA.png" /></figure><p>As you know there are many ways to authenticate to APIs, One of the ways to authenticate to the API request is SSL certificates.</p><p>Let us learn about how to configure cypress automation tests to use SSL certs for making request to the APIs.</p><p>SSL certificates are stored in the server and you will be given *.crt and *.key files for authentication from client side.</p><p>First, we need to create a folder certs at the top level of the project and place the files inside.</p><p>certificates have to be configured in the cypress.config.js file so when you run the command to open / run cypress , it would verify the certs against the url, if the certs are invalid it fails to load.</p><p>How to configure the SSL certificates ?</p><pre>module.exports = defineConfig({<br>clientCertificates: [<br>    {<br>      url: &#39;https://a.host.com&#39;,<br>      certs: [<br>        {<br>          cert: &#39;certs/cert.pem&#39;,<br>          key: &#39;certs/private.key&#39;,<br>        },<br>      ],<br>     url: &#39;https://b.host.com&#39;,<br>      certs: [<br>        {<br>          cert: &#39;certs/cert.pem&#39;,<br>          key: &#39;certs/private.key&#39;,<br>        },<br>      ], <br>    },<br>  e2e: {<br>    setupNodeEvents(on, cypressConf) {<br>      <br>     on(&#39;task&#39;, {<br>       // custom tasks goes here. <br>    },<br>    specPattern: &#39;cypress/e2e/**/features/*.{feature,features}&#39;,<br>    excludeSpecPattern: &#39;**/integration/modules/*.js&#39;,<br>    experimentalWebKitSupport: true,<br>    experimentalRunAllSpecs: true,<br>  },<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd0b41f49a20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reduce your test automation execution time by login to your app using aws amplify & Cypress.io]]></title>
            <link>https://bothees.medium.com/reduce-your-test-automation-execution-time-by-login-to-your-app-using-aws-amplify-cypress-io-07a698f8de46?source=rss-737bd6a5ed0f------2</link>
            <guid isPermaLink="false">https://medium.com/p/07a698f8de46</guid>
            <category><![CDATA[cypress-automation]]></category>
            <category><![CDATA[aws-cognito]]></category>
            <category><![CDATA[aws-amplify]]></category>
            <category><![CDATA[cypress-testing]]></category>
            <category><![CDATA[login]]></category>
            <dc:creator><![CDATA[Bothi Palani]]></dc:creator>
            <pubDate>Tue, 03 Oct 2023 20:55:17 GMT</pubDate>
            <atom:updated>2023-10-03T20:55:17.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*9UxNmyPcTIZbnnOaZALKew.png" /></figure><p>Is your application hosted on AWS cloud &amp; are you responsible for test automation of your application ? then this story is for you !!</p><p>Users are created in the AWS cognito User pool and eventually stored in the Database.</p><p><strong>Packages needs to be installed</strong> : <em>@aws-amplify/auth, @aws-sdk/client-cognito-identity-provider, @aws-sdk/client-rds-data, aws-sdk and @faker-js/faker</em></p><p>let us use the aws sandbox domain name &lt;@simulator.amazonses.com&gt; to create test automation users in the database.</p><pre>import {<br>  AdminCreateUserCommand,<br>  AdminGetUserCommand,<br>  AdminSetUserPasswordCommand,<br>  CognitoIdentityProviderClient,<br>} from &#39;@aws-sdk/client-cognito-identity-provider&#39;;<br>import { ExecuteStatementCommand, ExecuteStatementCommandOutput, RDSDataClient } from &#39;@aws-sdk/client-rds-data&#39;;<br>import { faker } from &#39;@faker-js/faker&#39;;<br><br>import { Auth } from &#39;@aws-amplify/auth&#39;;<br><br>const userPoolId = process.env.cognitoUserPoolId;<br>const clientId = process.env.cognitoWebClient;<br>const dbDatabase = process.env.envAcct;<br>const { dbClusterArn } = process.env;<br>const dbClusterSecretArn = process.env.dbSecretArn;<br><br>// all the required values for aws configuration should come from environment variables.<br>const awsConfig = {<br>  accessKeyId: process.env.AWS_ACCESS_KEY_ID,<br>  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,<br>  sessionToken: process.env.AWS_SESSION_TOKEN,<br>  region: process.env.AWS_REGION,<br>  UserPoolId: process.env.cognitoUserPoolId,<br>  ClientId: process.env.cognitoWebClient,<br>};<br><br>const awsConfigAuthLogin = {<br>  aws_user_pools_id: userPoolId,<br>  aws_user_pools_web_client_id: clientId,<br>};<br><br>/**<br> * Create the Cognito IDP client<br> */<br>const cognitoClient = new CognitoIdentityProviderClient(awsConfig);<br><br>/**<br> * Create the RDS Client<br> */<br>const rdsDataClient = new RDSDataClient({<br>  apiVersion: &#39;2018-08-01&#39;,<br>  ...awsConfig,<br>});<br><br>Auth.configure(awsConfigAuthLogin);<br><br><br>export const createActiveUser = async ({<br>  password,<br>  userRole,<br>  userTeam,<br>  userEmail,<br>}: {<br>  password: string;<br>  userRole: string;<br>  userTeam: string;<br>  userEmail?: string;<br>}) =&gt; {<br>  const uniqueID = faker.datatype.number({ min: 0, max: 99999999 });<br>  const role = userRole.replace(&#39; &#39;, &#39;_&#39;).toLowerCase();<br>  const team = userTeam.replace(&#39; &#39;, &#39;_&#39;).toLowerCase();<br>  const activeUserEmail = userEmail || `success+cy-${role}-${team}-active-${uniqueID}@simulator.amazonses.com`;<br><br>  const firstName = faker.name.firstName();<br>  const lastName = faker.name.lastName();<br><br>  const params = {<br>    UserPoolId: userPoolId,<br>    Username: activeUserEmail,<br>    MessageAction: &#39;SUPPRESS&#39;,<br>    UserAttributes: [<br>      {<br>        Name: &#39;email&#39;,<br>        Value: `${activeUserEmail}`,<br>      },<br>      {<br>        Name: &#39;email_verified&#39;,<br>        Value: &#39;true&#39;,<br>      },<br>    ],<br>  };<br><br>  const command = new AdminCreateUserCommand(params);<br>  const result = await cognitoClient.send(command);<br>  createdUsernames.push(result?.User?.Username);<br><br>  // Set a permanent password<br>  const pwcommand = new AdminSetUserPasswordCommand({<br>    UserPoolId: userPoolId,<br>    Username: result?.User?.Username,<br>    Permanent: true,<br>    Password: password,<br>  });<br>  await cognitoClient.send(pwcommand);<br><br>  const sqlParamsCreateUser = {<br>    secretArn: dbClusterSecretArn,<br>    resourceArn: dbClusterArn,<br>    sql: `INSERT INTO users (username, first_name, last_name, email_address) VALUES (:USERNAME, :FIRST_NAME, :LAST_NAME, :EMAIL) RETURNING *`,<br>    database: dbDatabase,<br>    includeResultMetadata: true,<br>    parameters: [<br>      { name: &#39;FIRST_NAME&#39;, value: { stringValue: `Test-${firstName}` } },<br>      { name: &#39;LAST_NAME&#39;, value: { stringValue: `Test-${lastName}` } },<br>      { name: &#39;EMAIL&#39;, value: { stringValue: activeUserEmail } },<br>      { name: &#39;USERNAME&#39;, value: { stringValue: result?.User?.Username } },<br>    ],<br>  };<br><br>  const sqlcommand = new ExecuteStatementCommand(sqlParamsCreateUser as any);<br>  const user = await rdsDataClient.send(sqlcommand);<br>  return result;<br>};</pre><p>Create a Custom method in commands.js for login, configure a temporary password inside Cypress environment variables.</p><p>create a method for login with Auth from aws amplify.</p><pre>import { Auth } from &#39;@aws-amplify/auth&#39;;<br><br>export const loginAWS = async ({ userName, password }: { userName: string; password: string }) =&gt;<br>  Auth.signIn(userName, password);</pre><pre><br>Cypress.Commands.add(&#39;login&#39;, () =&gt; {<br>  cy.task(&#39;createActiveUser&#39;, { password: Cypress.env(&#39;tempPassword&#39;), userRole: role, userTeam: team }).then(<br>    newUser =&gt; {<br>      const newUserWithPassword = {<br>        ...newUser,<br>        User: { ...newUser.User, password: Cypress.env(&#39;tempPassword&#39;)},<br>      };<br>      cy.task(&#39;loginAWS&#39;, {<br>        userName: newUserWithPassword.User.Username,<br>        password: newUserWithPassword.User.password,<br>        role,<br>      }).then(cognitoUser =&gt; {<br>        const idToken = cognitoUser.signInUserSession.idToken.jwtToken;<br>        const accessToken = cognitoUser.signInUserSession.accessToken.jwtToken;<br>        const makeKey = name =&gt;<br>          `CognitoIdentityServiceProvider.${cognitoUser.pool.clientId}.${cognitoUser.username}.${name}`;<br><br>        cy.setLocalStorage(makeKey(&#39;accessToken&#39;), accessToken);<br>        cy.setLocalStorage(makeKey(&#39;idToken&#39;), idToken);<br>        cy.setLocalStorage(<br>          `CognitoIdentityServiceProvider.${cognitoUser.pool.clientId}.LastAuthUser`,<br>          cognitoUser.username,<br>        );<br>      });<br>      cy.saveLocalStorage();<br>    },<br>  );<br>});<br>});</pre><p>use the login() method in the step definition and it will be automatically redirected to the landing page.</p><pre>Given(/^I am logged in to the application$/, () =&gt; {<br>  cy.login();<br>  cy.visit(&#39;/&#39;);<br>});</pre><p>once the user is logged in, session has to be stored in the local storage for successive logins. JWT token can also extracted from the response once logged in to app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07a698f8de46" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>