<?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 Sambhav Dave on Medium]]></title>
        <description><![CDATA[Stories by Sambhav Dave on Medium]]></description>
        <link>https://medium.com/@mr_possible?source=rss-52be34804467------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5G_wPSjlULt_WhAcAZORTQ.jpeg</url>
            <title>Stories by Sambhav Dave on Medium</title>
            <link>https://medium.com/@mr_possible?source=rss-52be34804467------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:06:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mr_possible/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[Test Automation: Instantiating the webdriver, the right way! [PART 1]]]></title>
            <link>https://medium.com/@mr_possible/test-automation-instantiating-the-webdriver-the-right-way-part-1-f9f1cefcef3b?source=rss-52be34804467------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9f1cefcef3b</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[selenium-webdriver]]></category>
            <category><![CDATA[test-automation-framework]]></category>
            <dc:creator><![CDATA[Sambhav Dave]]></dc:creator>
            <pubDate>Thu, 16 Jun 2022 06:39:56 GMT</pubDate>
            <atom:updated>2024-10-23T06:55:50.371Z</atom:updated>
            <content:encoded><![CDATA[<h3>Test Automation: Instantiating the web driver, the right way! (Part 1)</h3><p>In this blog, I am going to talk about how one can set up t driver setup infrastructure using the functional interface — Suppliers in Java.</p><h4><strong>Prerequisites</strong></h4><p>Java 8 or above, Selenium (for web frontend testing), TestNG knowledge, any IDE, and will to learn something new.</p><ol><li>First, we will make a small maven project for web UI automation— let’s call it ‘<em>SampleProject</em>’. I will be using IntelliJIDEA IDE for demonstration in this blog. The project structure looks like this :</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LsdKBSDiHMvr47Y5yIDHQg.png" /><figcaption>Our Project Structure — Initial</figcaption></figure><p>2. Let us add the required dependencies now. I will be using the following :<br>a ) Selenium 4 (Library for Web UI automation)<br>b ) TestNG (Our Test Runner)<br>c) WebdriverManager (Library for avoiding boilerplate code to setup driver)</p><p>Our <strong>pom.xml </strong>should look like this now (after adding dependencies) :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXyuHJ1Dx4DIAcg0Roz6IQ.png" /><figcaption>Added Dependencies — POM dependency structure</figcaption></figure><p>Once done with this — kindly reload your project, or if you are using Eclipse IDE, it is better to just restart the IDE after this step.</p><p>3. Let’s add our tests :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*4LLOjP33z5PrfBPmtrKX3g.png" /><figcaption>Typical Test Script Structure — Need to optimize</figcaption></figure><ul><li>Here, notice carefully. We are setting up our driver in the test script itself and tearing it down there only. Nothing is wrong here but when the question of the very popular factor ‘scale’ arises, then we should not be using this approach.</li><li>So, to optimize the code here, we shall move to our ‘<strong>main</strong>’ package and play there. Let’s hop on!</li></ul><p>4. Let’s create our <strong><em>Driver Manager — </em></strong>the class which will give us a thread-safe webdriver instance (which is the industry standard when it comes to best practices in test automation)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQtJU-TYuNdRE6vOrcLGvQ.png" /><figcaption>Thread-Safe GET&amp;SET webdriver instance</figcaption></figure><p>5. Now that we need not care about locking issues or ‘driver is null’ issues, we can finally head up to do our main work, i.e. Creating a <strong><em>Driver Factory — </em></strong>the factory which produces browser drivers, in a performant way.</p><ul><li>First, let’s create an empty class called <strong>DriverFactory.java.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzSvI9iUKP9wXqqLz60KQA.png" /><figcaption>Empty DriverFactory.java</figcaption></figure><ul><li>Second, let&#39;s create our ‘<em>setup</em>’ and ‘<em>teardown</em>’ methods which is what we want in the end.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwnVRCqtK9E595vEQUsMiw.png" /><figcaption>Creation of empty setup &amp; teardown methods.</figcaption></figure><ul><li>Third, let’s talk about SUPPLIERS of java for a minute here : <br>As Javadoc says and I quote: <a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html#:~:text=Interface%20Supplier&amp;text=This%20is%20a%20functional%20interface,lambda%20expression%20or%20method%20reference.&amp;text=Represents%20a%20supplier%20of%20results,time%20the%20supplier%20is%20invoked."><strong><em>This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. Represents a supplier of results. There is no requirement that a new or distinct result be returned each time the supplier is invoked.</em></strong></a></li><li>What the above quote means to say is basically the following : <br>a) Supplier does something. [the lambda function]<br>b) Suppliers give something. [the result]<br>c) We use what it produces. [get() method]</li></ul><blockquote>So, our agenda is to <strong><em>supply webdriver instances of different browsers </em></strong><em>to our test script, and we are going to use the Supplier concept to do just that.</em></blockquote><ul><li>Yes, you are guessing this right, we will be creating 4 browser suppliers namely CHROME_SUPPLIER, FIREFOX_SUPPLIER, EDGE_SUPPLIER, and SAFARI_SUPPLIER.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LDnoXZnXNzU0V6Sw3InsA.png" /><figcaption>Our WebDriver Suppliers</figcaption></figure><ul><li>Now, next question! How do we access the result of these suppliers? Umm, umm… Okay! For that, we would be creating a <strong>HashMap</strong> with <em>key</em> as <strong>String</strong> &amp; <em>value</em> as <strong>Supplier&lt;Webdriver&gt;</strong>. [Tip: Map is always a good choice because it possesses constant time complexity]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3OoyEiuvLeczmwqbS2ABQ.png" /><figcaption>Our Hashmap</figcaption></figure><ul><li>Next question — How would we let this map know about our suppliers? For that, we would have to let the map know about them at the time of class loading. Oh yes, you got that right! “<em>Static blocks”</em> to the rescue :)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*el6SDj9d9Skn3e_SxGJDjw.png" /><figcaption>Static Block &amp; Map Initialisation</figcaption></figure><ul><li>Now, every time this class loads, our map would be initialized with the respective webdriver suppliers with keys as ‘browser names’ (one can keep them as whatever they are comfortable with) and values as ‘browser suppliers’.</li><li>Since we are done with Supplier stuff, let’s use them in our setup method?</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GRd0vAUTMH5gkOvjTOaKlw.png" /><figcaption>Setup Method (revamped)</figcaption></figure><ul><li>Oops, I forgot about the teardown method and throwing an exception, Let&#39;s finish these off as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*fLyDmLEpV7xCwmLTQIj-eQ.png" /><figcaption>A quick look and minor refactoring.</figcaption></figure><ul><li>Let’s head back to our test class and utilize this <strong>DriverFactory.java </strong>class there.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNKFv5DeMuXSEf0z0PSt8g.png" /><figcaption>Test Script — revamped!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_sOYpuECVjQnC4eH5mFMMw.png" /><figcaption>Test Passed!</figcaption></figure><ul><li>You might be thinking — But Sambhav, the before and after annotations are still there. What miraculous have we done here?</li><li>I get you! This article focuses more on the driver factory part. Please wait for the <strong>second</strong> part of this article where I talk about : <br>- Using listeners &amp; custom annotations<br>- Logging into the test framework</li></ul><p>I hope this article was of some meaning to you. If so, do give a like. I take it as feedback only. And if you have any doubts, suggestions, etc — please do comment. I’ll be happy to learn/help.</p><p>Stay tuned for the 2nd part!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9f1cefcef3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the scenes — docker run]]></title>
            <link>https://medium.com/devopssquare/behind-the-scenes-docker-run-e4fd3ea09aa7?source=rss-52be34804467------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4fd3ea09aa7</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Sambhav Dave]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 18:11:20 GMT</pubDate>
            <atom:updated>2024-10-23T06:56:38.919Z</atom:updated>
            <content:encoded><![CDATA[<h3>Behind the scenes — docker run (macro view)</h3><p>Hello everyone !</p><p>This article talks about a very useful DevOps tool — Docker and one of its very crucial commands.</p><blockquote><em>In simple terms, </em><strong><em>Docker</em></strong><em> is a software platform that simplifies the process of building, running, managing, and distributing applications.<br>(Source: </em><a href="https://medium.com/free-code-camp/docker-simplified-96639a35ff36#06d9"><em>Another Medium post</em></a><em>)</em></blockquote><blockquote><strong><em>Note:</em></strong><em> I assume you know the basics of Docker. Otherwise, please clap and learn the nitty-gritty of it first. :)</em></blockquote><p>In the process of learning Docker, I came across this command called → <strong>docker run</strong> which in fact is the elephant in the room for us while reading this article. I wanted to know how it works in the backend, or in other words, I wanted to know, how an image is basically downloaded in so less time by Docker.</p><p>So, I spent around 1 hour drawing this least useful image in order to describe my article, please bear with me :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NBlFLztigfEEyti0cypUvQ.png" /><figcaption>docker run hello-world (for the layman)</figcaption></figure><p>A little bit of background :</p><p>In my head, Docker basically helps you to build a scalable lightweight infrastructure using a couple of nifty commands and not worrying about alot of settings as such.</p><p>For example, You want to run Unix on a windows laptop OR you want to practice Unix commands for your mid-term examinations. Let’s just assume you are like me and you use a Windows laptop.</p><p>There are 2 ways you can achieve this: By either going to a shop and requesting them to install some kind of a dual boot setup in your machine.<br>Or by installing Docker Desktop on your machine.</p><p>Docker desktop allows you to download (let&#39;s just say that) <strong>images. </strong>Now pay attention, it is not a jpeg/jpg/png image that we are talking about. It basically is software that you intend to install for your own purposes.</p><p>So, let us say I want to install (or download) Ubuntu (image) in my Docker Desktop.</p><p>For pulling/downloading a particular image from &lt;<em>you will know later in this article</em>&gt;, we run the following command.</p><p><strong>docker run ubuntu</strong></p><p>Let me divide this process into steps :</p><p><strong>Step 1</strong>: Assuming you have installed Docker in your machine and you have admin rights, open the command prompt. In case you are a newbie to docker and its installation → <a href="https://docs.docker.com/engine/install/">tada</a> !</p><p><strong>Step 2</strong>: Now that you have opened your terminal, please type the following command to install Ubuntu :</p><p><strong>docker run ubuntu</strong></p><p><strong>Step 3</strong>: Once you hit enter, you should notice a couple of logs getting displayed in the console. This is basically the Docker Client making a request to the Docker hub and eventually getting the process done if you haven’t goofed upon any part.</p><p>Few terminologies nice to know :</p><blockquote><strong>Docker Hub</strong>:<em> This is basically a central repository that contains all the images to be downloaded as lightweight virtual machines. Lets just call it a database. <br>If you wanna dig deep → </em><a href="https://hub.docker.com/"><em>holy god </em></a><em>! (you have to have one account to enter)</em></blockquote><blockquote><strong><em>Docker Server:</em></strong> <em>It is a daemon. It is always up and running in our machine. It exposes some rest APIs.</em></blockquote><blockquote><strong>Docker Client:<em> </em></strong><em>This is basically a sort of driver for us (the developers) to check upon docker hub and the local machine for images. It is a program invoked (in a way) when you say ‘docker’ in the terminal.</em></blockquote><p><strong>Step 4</strong>: Let&#39;s say, you freshly installed docker. So you don’t have any image pulled already. So, once the command (docker run ubuntu) starts to run, the docker client accepts parameters from the terminal and then sends them to the docker server<em>.</em></p><p><strong>Step 5:</strong> Upon the docker client’s request, the docker server will first check its local image repository. If it does not find anything, then it raises a request to the docker hub. It pulls that image from the docker hub and places it in the local repository.</p><p>So the next time you don’t know whether you have an ubuntu image or not (let’s just say that), then you simply need to repeat the above steps. If you already have the image, then the process would take a couple of seconds to set up and run.</p><blockquote>Note : The pic in this article denotes to a different image, but that’s just another exemplar image -&gt; hello-world.</blockquote><p>Thanks for reading.<br>Bye.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4fd3ea09aa7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devopssquare/behind-the-scenes-docker-run-e4fd3ea09aa7">Behind the scenes — docker run</a> was originally published in <a href="https://medium.com/devopssquare">DevopSquare</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Few tips : API Testing using Python and BDD approach using ‘Behave’]]></title>
            <link>https://medium.com/@mr_possible/few-tips-api-testing-using-python-and-bdd-approach-using-behave-32f3f462f353?source=rss-52be34804467------2</link>
            <guid isPermaLink="false">https://medium.com/p/32f3f462f353</guid>
            <category><![CDATA[api-testing]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[api-test-automation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sambhav Dave]]></dc:creator>
            <pubDate>Thu, 22 Jul 2021 09:06:06 GMT</pubDate>
            <atom:updated>2021-07-22T09:08:40.615Z</atom:updated>
            <content:encoded><![CDATA[<h3>Few tips : API Testing using Python and BDD approach using ‘behave’</h3><p>So, it was a lazy Sunday, raining and 10 am in the morning. I had woken up with a nice hangover from last night (thanks to my mate who agreed on checking on the new pub that just had opened in town). Mom brought some coffee and I was just checking my emails / social media. It was around 10 minutes past 10 when I came across this LinkedIn post saying something about BDD framework.</p><p>I had heard about TDD (Test Driven Development) in the past, but what was this ? So, I closed the app thinking, who cares ! :P</p><p>But jokes apart, I freshened up. Had my lunch. And once everyone was having their afternoon nap, the silence in my house welcomed me with grace. I cleaned my table and opened my laptop. Searched google for the afore-mentioned and got to learn about the concept.</p><p>So long story short — what I understood from BDD (in my simple words) ?</p><p>First, it stands for <em>behavior driven development</em>.<br>And, it predominantly involves ‘layman’ language while scripting for test cases. It comes in handy, when you especially have a small team and the business analysts / product owners are also involved in the testing team. Since, these people are meant to be non-technical (not literally), they have to understand the nitty-gritty of the testing phase. Hence, for them to understand this smoothly, we should take BDD as an option.</p><p>So, I planned to make one small framework for testing api(s) based on BDD approach.</p><p>And one more thing, I wanted to use Python this time (to make it more short and easy to grab for beginners).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iNbSzN1k6z45k0X2" /><figcaption>Photo by <a href="https://unsplash.com/@goshua13?utm_source=medium&amp;utm_medium=referral">Joshua Aragon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>(A side note : Please put your favorite theme for Pycharm IDE in the comments :3 I need one desperately !)</blockquote><h3><strong>What can you expect from this article?</strong></h3><blockquote>Basically, how to start with any project belonging to API testing and that too, using BDD approach. I am not going to tell you, how to setup the project (follow git repo link for the same in case you want to know the folder structure and how to execute yada yada yada)</blockquote><h3>Questions one should ask before starting.</h3><p>One should start with following questions in mind before setting up the project :</p><ol><li>What kind of scale are we looking at ?</li><li>Is python really going to help ?</li><li>Is there even a library available for this whole thing ?</li><li>A working API for me to start (duh !)</li><li>Gotta look for reporting mechanism eh !</li><li>Please Sambhav, this time provide a nice README (okay ? )</li></ol><p>Answers to above (that I had) :</p><ul><li>This project is not going to be testing APIs for Tesla 🐦. (I wish one day ! )</li><li>I chose python just because of it’s simple syntax and particularly less verbose nature.</li><li>Yes, there is a library available for API testing using Python (particularly for BDD) → It is called <strong>‘behave’.</strong></li><li>I am using <a href="https://github.com/lukePeavey/quotable">this</a> as my working API. More about the API will be given in upcoming paragraphs.</li><li>I will be using Allure Reports to review my test results.</li><li>Forget about README, <a href="https://github.com/mr-possible/QuotableAPI-automationSuite">the whole git repo link</a> to follow for this article.</li></ul><p>Once you’re done with the above questions with yourself, please visit the git repo, clone it and then use your own working api for working.</p><p>Please raise pull requests for any changes / suggestions.</p><p>Chalo. Bye. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32f3f462f353" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UnboundLocalError in Python]]></title>
            <link>https://medium.com/analytics-vidhya/unboundlocalerror-in-python-edfe9aaf49e4?source=rss-52be34804467------2</link>
            <guid isPermaLink="false">https://medium.com/p/edfe9aaf49e4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[unboundlocalerror]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Sambhav Dave]]></dc:creator>
            <pubDate>Mon, 23 Mar 2020 18:27:06 GMT</pubDate>
            <atom:updated>2024-10-23T06:58:39.323Z</atom:updated>
            <content:encoded><![CDATA[<p>It is very irritating when a code that ran smoothly minutes ago, stops due to a stupid mistake and hence, shows an error that is popular or rather common among Python developers called “<em>UnboundLocalError</em>”.</p><p>This story or rather a blog post by me, describes the nature of this error by seeing HOW it occurs, WHY it occurs &amp; how you should SOLVE to remove it.</p><p><strong>The HOW?</strong></p><p>Consider the snippet below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*lbsT1GTyspgOTCiHOFsazA.png" /><figcaption>Smooth Case</figcaption></figure><p>In the snippet in the above screenshot, the value of <strong>num </strong>is 4 initially (treated as globally in Python because it is declared outside the method). In the method named <strong>myFunc()</strong>, we are simply printing its value. So the output is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*c9mqXsbQxVKLcIh25Xfi-Q.png" /><figcaption>Smooth Case (Result)</figcaption></figure><p>Now, let us modify the above smooth case, and let’s face the problem. Consider the snippet below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*WACu2dbGUPuCB1luUXx8ZA.png" /><figcaption>Problematic Case</figcaption></figure><p>Do note here that, we first are planning to print the value of <strong>num </strong>and then modify its value to let’s say <strong>8 (line 6).</strong> Let’s run the code again by calling the function <strong>myFunc()</strong> as before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*3l4BgJUSYORH6Tlg0xuSZw.png" /><figcaption>Problematic Case (Result)</figcaption></figure><p>It can be easily seen that the whole subject of this post is visible in the error above, the <strong><em>UnboundLocalError</em></strong>. Let’s understand the reason behind it by going through the more interesting WHY section…</p><p><strong>The WHY?</strong></p><p>This error arises due to a minor fault of scope. In python, all the variables inside a function are global if they are not assigned any value to them.</p><p>That means if a variable is only referenced outside a function, it is global. However, if we assign any value to a variable inside a function, its scope becomes local to that unless explicitly declared global.</p><p>In the first example (smooth case), we are not assigning any value to the x variable inside the function and just referencing it to print. Hence <strong>x</strong> is <strong><em>global</em></strong>.</p><p>In the second example (problematic case), we assigned the value 8 to x, hence x’s scope is <strong><em>local </em></strong>to function and we tried to print it before assigning any value to <strong>x</strong>.</p><p><strong>The SOLUTION ! :)</strong></p><p>You would need to use the keyword <strong>global</strong> before modifying it inside the function as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*0i1XU5L4afy49Tg6iroSRg.png" /><figcaption>Smooth Again!</figcaption></figure><p>Focus on <strong>line 5 </strong>where we have put the keyword <strong><em>global </em></strong>to tell the Python interpreter that, whatever change is being done ahead of this point to the value of <strong>num</strong>, reflects its global value. In other words, change it for every other occurrence of <strong>num. And that’s it. Done.</strong></p><p>There is one more solution to it, i.e. by using <strong><em>nonlocal </em></strong>keywords, but that is generally not advisable. Hence, I haven’t discussed it over here.</p><p><strong>Thanks for reading!</strong></p><p><strong>Cheers!!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edfe9aaf49e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/unboundlocalerror-in-python-edfe9aaf49e4">UnboundLocalError in Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>