<?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 Arun Sarode on Medium]]></title>
        <description><![CDATA[Stories by Arun Sarode on Medium]]></description>
        <link>https://medium.com/@aruns_74972?source=rss-f160dbbc491c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*dYJFje3MbWO85AUJ</url>
            <title>Stories by Arun Sarode on Medium</title>
            <link>https://medium.com/@aruns_74972?source=rss-f160dbbc491c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:07:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aruns_74972/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[Handle Multiple Webviews — Mobile Application Automation]]></title>
            <link>https://medium.com/testvagrant/handle-multiple-webviews-mobile-application-automation-faaeea9aaac0?source=rss-f160dbbc491c------2</link>
            <guid isPermaLink="false">https://medium.com/p/faaeea9aaac0</guid>
            <category><![CDATA[webview]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[mobile-app-automation]]></category>
            <dc:creator><![CDATA[Arun Sarode]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 12:08:22 GMT</pubDate>
            <atom:updated>2023-06-23T10:29:34.812Z</atom:updated>
            <content:encoded><![CDATA[<h3>Handle Multiple Webviews — Mobile Application Automation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xtfklskOuotbXw4GYJ5VVQ.jpeg" /></figure><h3>Problem statement:</h3><p><a href="https://micro-frontends.org/">MFE(Micro frontend) architecture</a> is a design approach in which the front-end app is broken down into smaller independent micro apps. Usually in a project, there could be many teams working independently, each team could load their respective app in a separate <a href="https://developer.android.com/develop/ui/views/layout/webapps/webview">webview</a>.</p><p><strong>Context:</strong></p><p>The application undertest is a mobile app built on react native with MFE architecture. Application content is loaded as part of multiple Webviews to improve performance.</p><p><strong>Challenges:</strong></p><ul><li>Switch to appropriate webview if multiple webviews are loaded</li><li>Switch to appropriate webview if multiple webview with same title loaded</li><li>Switch back to parent webview and continue with the test</li></ul><h3>Solutions:</h3><blockquote><em>First Solution:</em><strong> Using Title of the Webview</strong></blockquote><p>Most of the webview would have title associated with it. In order to resolve above challenges, one of the solution is switch to webview based on title and continue further steps.</p><p>Steps To Inspect Device:</p><ul><li>Setup Emulator/Real device(For Real device make sure connected to computer via cable and Enable developer option)</li><li>Installed app on the device</li><li>Launch the app</li><li>Open chrome and go to url <em>chrome://inspect/#devices</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gnwzuOsPwpptop4qcYU07g.jpeg" /><figcaption>Multiple webview with unique title</figcaption></figure><p><strong>Note:</strong> Each webview will have Title and Url as shown in the above image</p><p><strong>Below sample code is written using WebdriverIO framework along with Typescript</strong></p><pre>  /**<br>   * switch to webview based on title<br>   */<br>  export async function switchToWebviewWithTitle(driver: Browser&lt;&#39;async&#39;&gt;, title: string) {<br>    try {<br>      // Add wait if webview loading takes time<br>      const windowHandles: string[] = await driver.getWindowHandles();<br>      console.info(&#39;below are window handles&#39;);<br>      windowHandles.forEach((windowHandle) =&gt; {<br>        console.info(windowHandle);<br>      });<br>      let foundWebview:boolean = false;<br>      for (let index = 0; index &lt; windowHandles.length; index += 1) {<br>        await driver.switchToWindow(windowHandles[index]);<br>        const currentTitle:string = await driver.getTitle();<br>        if (currentTitle === title) {<br>            foundWebview = true;<br>            console.info(`Switched to webview with title - ${title}`);<br>            break;<br>        }<br>      }<br>      if (!foundWebview) {<br>        console.warn(`Could not find the webview with specified title-${title}, switching to ${windowHandles[0]}`);<br>        await driver.switchToWindow(windowHandles[0]);<br>      }<br>    } catch (error) {<br>      console.error(&#39;switch to child window was not successful\n&#39;);<br>      console.info(error.stack);<br>      throw new Error(error);<br>    }<br>  }</pre><p><strong>Drawback</strong></p><p>There might be chances of loading multiple webview with same Title and could be a blocker issue. In this situation automation script might switch to inappropriate webview and test script might fail.</p><blockquote><em>Second Solution:</em><strong><em> </em>Using Webview Url</strong></blockquote><p>Since each of the webview will have Url associated with it. One more solution is switch to webview based on url. We need to switch webview which contains portion of url which we expect and continue further steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VZbKZ7fsPHqvSMWEqaKDg.jpeg" /><figcaption>Multiple webview with same title(trader-web)</figcaption></figure><pre>  /**<br>   * switch to webview which contains expected url path<br>   */<br>  export async function switchToWebviewWithUrl(driver: Browser&lt;&#39;async&#39;&gt;, urlContains:string) {<br>    try {<br>      // Add wait if webview loading takes time<br>      const windowHandles: string[] = await driver.getWindowHandles();<br>      console.info(&#39;below are window handles&#39;);<br>      windowHandles.forEach((windowHandle) =&gt; {<br>        console.info(windowHandle);<br>      });<br>      let foundWebview:boolean = false;<br>      for (let index = 0; index &lt; windowHandles.length; index += 1) {<br>        await driver.switchToWindow(windowHandles[index]);<br>        const currentUrl:string = await driver.getUrl();<br>        if (currentUrl.includes(urlContains)) {<br>          foundWebview = true;<br>          console.info(`Switched to webview with url containing-${urlContains}`);<br>          break;<br>        }<br>      }<br>      if (!foundWebview) {<br>        console.warn(`Could not find the webview with with url containing-${urlContains}, switching to ${windowHandles[0]}`);<br>        await driver.switchToWindow(windowHandles[0]);<br>      }<br>    } catch (error) {<br>      console.error(&#39;switch to child window was not successful\n&#39;);<br>      console.info(error.stack);<br>      throw new Error(error);<br>    }<br>  }</pre><h3>Conclusion:</h3><p>Approach to follow completely depends on the how application developed, below are the few points to consider.</p><ul><li>First solution will be suitable if webviews loaded at any point in time has unique titles.</li><li>Second solution will be suitable if multiple webview loaded with same title but different URL.</li></ul><p>I would recommend to use the Second solution, since it is more reliable works in most of the cases.</p><blockquote><strong>References:</strong></blockquote><ul><li><a href="https://developer.android.com/develop/ui/views/layout/webapps/webview">Build web apps in WebView | Android Developers</a></li><li><a href="https://www.toptal.com/front-end/micro-frontends-strengths-benefits">How To Build a Micro-frontend Framework | Toptal®</a></li><li><a href="https://webdriver.io/docs/api/">Introduction | WebdriverIO</a></li></ul><p><em>Happy Learning!!!…</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faaeea9aaac0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testvagrant/handle-multiple-webviews-mobile-application-automation-faaeea9aaac0">Handle Multiple Webviews — Mobile Application Automation</a> was originally published in <a href="https://medium.com/testvagrant">TestVagrant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Reusable Components in Test Automation]]></title>
            <link>https://medium.com/testvagrant/building-reusable-components-in-test-automation-6ac40eff8552?source=rss-f160dbbc491c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ac40eff8552</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Arun Sarode]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 05:09:14 GMT</pubDate>
            <atom:updated>2021-08-24T05:09:14.272Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kh4ImQGFgMt4UAhsvlW4AA.png" /></figure><p>When we work on big projects they usually are divided into sub-projects based on features/modules etc…</p><p>In this situation, our automation code also is divided based on multiple sub-projects and our automation tests will be in sync with the respective project&#39;s feature testing.</p><p>There will be some features in common for both sub-projects example login flow, logout flow, Navigation, Driver related activity(Closing driver, Getting cookie, Util methods, etc…)</p><p>We might end-up up writing different implementation/code for the same feature/function on different sub-projects.</p><h3>Approach:</h3><p>To avoid duplicate code and redundant effort, we can maintain common reusable code(common git repository) across projects.</p><p>For Example, Report Integration, Email Notification, Loggers, etc…<br>are common for all automation projects. we can keep these in a single repository and reuse them across all other internal sub-projects.</p><p><strong>Advantages:<br></strong>* Write once reuse across (<a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"><em>Dry Principle</em></a>).<br>* Save time and effort.<br>* One point control for common utilities of all the sub-projects.<br>* Easy to integrate with new sub-projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GRoozwnDhGLdsBfJuINJSQ.png" /><figcaption><strong>Pictorial Representation</strong></figcaption></figure><p><strong>Pre-requisites:</strong></p><ol><li>Node installation.</li><li>Know Javascript(Typescript).</li></ol><h3>Let’s start with steps:</h3><blockquote><strong>Create common utility project</strong></blockquote><p>Create project “CommonUtility”, which would be having most of the common reusable code/logic, as depicted in the image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inyROWBoZho2FqR-r2prmw.png" /><figcaption><strong>Common code arrangement</strong></figcaption></figure><p>Below is the sample tsconfig.json file</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;lib&quot;: [&quot;dom&quot;, &quot;ES2020&quot;],<br>    &quot;target&quot;: &quot;ES2020&quot;,<br>    &quot;module&quot;: &quot;commonjs&quot;,<br>    &quot;moduleResolution&quot;: &quot;node&quot;,<br>    &quot;noImplicitAny&quot;: true,<br>    &quot;noImplicitReturns&quot;: true,<br>    &quot;resolveJsonModule&quot;: true,<br>    &quot;esModuleInterop&quot;: true,<br>    &quot;declaration&quot;: true,<br>    &quot;allowJs&quot;: false,<br>    &quot;outDir&quot;: &quot;dist&quot;,<br>    &quot;sourceMap&quot;: true,<br>    &quot;types&quot;: [&quot;node&quot;, &quot;mocha&quot;, &quot;chai&quot;, &quot;webdriverio&quot;],<br>    &quot;skipLibCheck&quot;: true<br>  },<br>  &quot;compileOnSave&quot;: true,<br>  &quot;exclude&quot;: [&quot;node_modules&quot;, &quot;dist&quot;]<br>}</pre><p>Below is the sample .npmignore file, this file will help in what are the item’s we would like to ignore while publishing the package</p><pre>/node_modules<br>/PreviousVersions</pre><blockquote><strong>Publishing common utility:</strong></blockquote><p>Creating common code as a package(.tgz file) that can be used in other projects</p><p>below are the scripts we need to add under package.json</p><pre>{<br>  &quot;name&quot;: &quot;common-utility&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;description&quot;: &quot;common utility code base for reusable methods&quot;,<br>  &quot;main&quot;: &quot;dist/index.js&quot;,<br>  &quot;types&quot;: &quot;dist/index.d.ts&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;compile&quot;: &quot;tsc&quot;,<br>    &quot;generate-package&quot;: &quot;npm pack&quot;<br>  },<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>  .<br>  .<br>  },<br>  &quot;devDependencies&quot;:{<br>  .<br>  .<br>  }<br>}</pre><p>commands to execute to prepare a package</p><pre><strong>npm run compile</strong> (to compile code to for any error)</pre><pre><strong>npm run generate-package</strong> (to generate commonUtility-0.0.1.tgz file locally with all dependency)</pre><p>post generation of the .tgz file, we need to move under the “versions” folder and push the code to git</p><pre><em>Note: <br> * As of now publishing package within git repo, even we can publish the package to repositories as well(refer </em><a href="https://docs.npmjs.com/creating-and-publishing-scoped-public-packages"><strong><em>here</em></strong></a><em>).</em></pre><pre><em>* For every change in the code we need to modify </em><strong><em>version</em></strong><em> number in the </em><strong><em>package.json</em></strong><em> file execute above commands.</em></pre><blockquote><strong>Utilising common utility within sub-projects</strong></blockquote><p>Copy commonUtility-0.0.1.tgz file from the Common Utility git repo to sub-projects, and update package.json dependencies with respective common utility version numbers.</p><pre>&quot;dependencies&quot;:{<br>  &quot;common-utility&quot;:&quot;file:./commonUtility-0.0.1.tgz&quot;,<br>.<br>.<br>}</pre><p>After updating the above dependency execute the command <strong>npm install</strong></p><pre><em>If newly added methods doesn’t reflect in sub-projects after npm i try to run command<br></em><strong><em>npm cache clean — force</em></strong></pre><p>Use of methods exposed by Common Utility project in our Subprojects code</p><pre>import {BrowserUtil, DateTimeUtil} from &#39;common-utility&#39;</pre><pre>describe(&#39;demo on usage of common utility code&#39;,()=&gt;{<br>it(&#39;first test case&#39;, async ()=&gt;{<br>  let dummyConfig:{};<br>  let driver = await BrowserUtil.setupBrowser(dummyConfig,&#39;dummy spec name&#39;);<br>  await BrowserUtil.open(driver, &#39;sample url to open&#39;);<br>  <br>  // date time util<br>  let todayDate = await DateTimeUtil.getTodayDate();<br>  let addMinutes = await DateTimeUtil.addMinutesToDate(new Date(),10);<br>});<br>});</pre><blockquote><strong>References:</strong></blockquote><ul><li><a href="https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html">Documentation - Publishing</a></li><li><a href="https://docs.npmjs.com/creating-and-publishing-scoped-public-packages">Creating and publishing scoped public packages | npm Docs</a></li><li><a href="https://docs.npmjs.com/cli/v7/commands/npm-publish">npm-publish | npm Docs</a></li></ul><p><em>Happy Learning!!!…</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ac40eff8552" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testvagrant/building-reusable-components-in-test-automation-6ac40eff8552">Building Reusable Components in Test Automation</a> was originally published in <a href="https://medium.com/testvagrant">TestVagrant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>