<?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 Clevin Dsouza on Medium]]></title>
        <description><![CDATA[Stories by Clevin Dsouza on Medium]]></description>
        <link>https://medium.com/@clevindsouza?source=rss-75fe6da16bd1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z7LvX_QyC7GPMf2Lc9_CaQ.jpeg</url>
            <title>Stories by Clevin Dsouza on Medium</title>
            <link>https://medium.com/@clevindsouza?source=rss-75fe6da16bd1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:30:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clevindsouza/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[What is an API ? Create a simple REST API using php and MySQL]]></title>
            <link>https://clevindsouza.medium.com/what-is-an-api-create-a-simple-rest-api-using-php-and-mysql-1eb54a8d0afb?source=rss-75fe6da16bd1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eb54a8d0afb</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Clevin Dsouza]]></dc:creator>
            <pubDate>Mon, 29 Mar 2021 07:30:04 GMT</pubDate>
            <atom:updated>2021-03-29T07:47:01.745Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is an API ? Create a simple REST API using php and MySQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIYNRnQhzDXC5QpgcL9hHQ.png" /></figure><p>Well, we have always been there especially those non technical ones..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*zw5MrCwgxB5E42D1R4d-hg.jpeg" /></figure><p>Let’s begin with something really simple here, What is an API ?<br>API stands for Application Programming Interface where it allows two applications to communicate with each other. The communication could handle data such as details or a transaction, numbers, strings or text, statuses and so on.. Example: Each time you like your friends post on Instagram or on Facebook you are actually fire up an API that sends this ‘Like’ to appear on the post.</p><p>API is an intermediary that speaks through a web server, retrieves information from a storage and then presents it back to the user. The below diagram can simplify it further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSTqHlr61wmAwXipSUDLOQ.png" /></figure><p>There are various types of APIs that you can develop as per your business need and they could be REST, SOAP, XML and so on.. The mostly commonly used APIs are REST.</p><p>REST stands for — representational state transfer which is a very popular web API architecture. To be a REST API, an API must adhere to certain architectural constraints, or principles. REST APIs can be developed using various server side technologies such as php, python, .NET, Node, Express and so on. To keep it simple and know how a basic REST API works, lets learn how to build a REST API using php.</p><p>What you need to cook up your 1st REST API locally / on your personal computer?</p><ul><li>install a web server — XAMPP (<a href="https://www.apachefriends.org/download.html">download here</a>)</li><li>install PHP (this should be installed by default with XAMPP)</li><li>install a database, such as MySQL (this should be installed by default with XAMPP)</li><li><a href="https://code.visualstudio.com/">Download Visual Studio Code </a>or <a href="https://www.sublimetext.com/">Sublime Text</a> [whatever suits your needs- I prefer VS Code as its light and has plugins that help you auto complete and debug faster ;) ]</li></ul><p>Before we move ahead let me tell you a bit about our webserver — XAMPP. It is a package that contains X — which means its cross platform, Apache as a web server — that will serve your application, M — formerly called as mySQL but in recent times its termed as MariaDB, P — Perl and finally P — php.</p><p>Once you have installed XAMPP you should be able to a screen that looks like .. this is the XAMPP Control Panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*-19PIUXFoAxivTCDN_byoQ.png" /></figure><p>Usually in online shared hosting agents such as GoDaddy, you will have something similar but more browser intuitive and it will be called cPanel.</p><p>The Module column will be grey and it denotes the status of the services, in the above case all services are currently inactive. To activate lets start by clicking Start next to Apache (our web server) and MySQL (our database).</p><p>As soon as they are started this is how it should look (in Windows , you may get an additional popup that asks you permission to Allow Access on activating Apache)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*osa0uq4tARVkVfLU0yUR1A.png" /></figure><p>The section below will always keep updating (kind of a logging) that will tell you if Apache / MySQL is running or not. To verify whether the site is working, go to your browser and type in ‘localhost’ in the address bar. This is what it you should see..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHqdqzmXgGrmLEwBxOQizg.png" /></figure><p>If you click on phpMyAdmin you will be redirected to ..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymy2KfvdSOQ0EDL-Ba2OBg.png" /></figure><p>This is where we will create our database table and store some data into it ..</p><p>Lets create a new database and add data to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*-AR1z68kMgALq7GP45BKpA.png" /></figure><p>Click on new, the left hand of the screen should have an empty text box where you will enter your database name, for our example I have named our database as <strong>api-tutorial</strong> and format selected is <strong>utf8mb4_general_ci</strong></p><p>After submitting the above you will be asked to create tables within your database and should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*-H0bDkuQHUcAl3vBjzHzOg.png" /></figure><p>Tables as in general have rows and columns, in our case lets create a users table with 4 columns in it. This represents each user will have 4 different attributes : user_id, username, email_id, contact_number below is how it should be filled in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyHano1qtVgT0AVS33hG7g.png" /></figure><p>The column type is an important factor here as it determines what kind of data type will be assigned to the column name so for example contact_number will be assigned to the datatype integer. For more details on various data types you can <a href="https://dev.mysql.com/doc/refman/5.7/en/data-types.html">refer to this article</a> There are other attributes such as string length and so on that can be added to, but we wont be going indepth in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*3vugGdIU0fdtQ8pucMN58w.png" /></figure><p>Above we have assigned the various columns their respective datatypes and length of each of the entries that we expect. Click on save and you will return to the main page, lets add values / data to our newly create table- users.</p><p>There are two ways of adding data into tables, the manual way using the UI —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*D4SUn5TKJpGGKqSf_G91TA.png" /></figure><p>or a SQL query, this has to be entered into the text box available in the SQL tab -</p><p>INSERT INTO `users` (`user_id`, `username`, `email_id`, `contact_number`) VALUES (‘1’, ‘clevin’, ‘<a href="/service/mailto:mail@mail.com">mail@mail.com</a>’, ‘1234567890’);</p><p>Click on Go — and you should see these values in the table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*x50OK173TG6Do0INpEep9g.png" /></figure><p>Accordingly you can add as many as records you wish to. For now lets go with 2 more records- 3 in total and this is how it should look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*Pkhoe-6QW0J5f75Gn1STnQ.png" /></figure><p>Open a new file in VS code and name it api.php, remember the php file will run through XAMPP using Apache, location should be C:\xampp\htdocs</p><p>Note: host = localhost, username = root, password =&lt;blank&gt;, db name = api-tutorial</p><p><em>This is probably the most default connection parameters you will need to connect with any database locally on any machine. They can be replaced with a real time database by replace the credentials and host where the database is being hosted.</em></p><p>In our api.php file, we will type the below code using Visual Studio Code</p><pre>&lt;?php<br>$con = mysqli_connect(&quot;localhost&quot;, &quot;root&quot;,&quot;&quot;,&quot;api-tutorial&quot;); <br>if($con) {</pre><pre>echo &quot;Database connected&quot;; <br>}</pre><p>in your browser you should browse the file localhost/api.php and you should see Database Connected as a message in your browser. Our first success!</p><p>Next lets continue to write our API below the above code. (I have removed the Database Connected response in the below code to provide a clean JSON response.)</p><pre>&lt;?php</pre><pre>$con = mysqli_connect(&quot;localhost&quot;, &quot;root&quot;,&quot;&quot;,&quot;api-tutorial&quot;);</pre><pre>$response = array();</pre><pre>if($con) {</pre><pre>$sql = &quot;select * from users&quot;;</pre><pre>$result = mysqli_query($con,$sql);</pre><pre>if($result) {</pre><pre>header(&quot;Content-Type: JSON&quot;);</pre><pre>$i=0;</pre><pre>while($row = mysqli_fetch_assoc($result)){</pre><pre>$response[$i][&#39;user_id&#39;] = $row[&#39;user_id&#39;];</pre><pre>$response[$i][&#39;username&#39;] = $row[&#39;username&#39;];</pre><pre>$response[$i][&#39;email_id&#39;] = $row[&#39;email_id&#39;];</pre><pre>$response[$i][&#39;contact_number&#39;] = $row[&#39;contact_number&#39;];</pre><pre>$i++;</pre><pre>}</pre><pre>echo json_encode($response, JSON_PRETTY_PRINT);</pre><pre>}</pre><pre>}</pre><p>refresh the page localhost/api.php and you should see the response of your API thus fetching data from our Database api-tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*pm0v5S5m-GZHDDItpoq9rw.png" /></figure><p>Hurray! we have created our first API and retrieved the data in a JSON format. You can use the above code as a base and keep adding variations in your data. This data can also be represented in the form for a simple table in a html file. Please comment below in case you want me to make an extended version of this tutorial to consume APIs in the frontend and I will try to keep it as simple as possible. Thank you for your time.</p><p><em>Please note: This is a very basic explanation of how a REST API works and how it can be achieved using just 1 php file. In live environments you should avoid keeping the database connection settings in your php file and rather store it in a hidden ENV file or a encrypted string.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eb54a8d0afb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Automation (visual regression test) for UI comparison on web applications using BackstopJS.]]></title>
            <link>https://clevindsouza.medium.com/test-automation-visual-regression-test-for-ui-comparison-on-web-applications-using-backstopjs-789ebe709926?source=rss-75fe6da16bd1------2</link>
            <guid isPermaLink="false">https://medium.com/p/789ebe709926</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[backstop]]></category>
            <dc:creator><![CDATA[Clevin Dsouza]]></dc:creator>
            <pubDate>Thu, 25 Mar 2021 13:35:43 GMT</pubDate>
            <atom:updated>2021-03-29T15:12:52.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pqbM7ChTOcPlLAk81dseA.png" /><figcaption>Test Automation (visual regression test) for UI comparison on web applications using BackstopJS.</figcaption></figure><p>Before I get into helping you set up this application, please allow me to explain a simple scenario at work where this solution was useful and how it made my life easier. PS: I am not a QA Engineer although I thought this could be something that could be introduced in any web project or application as a testing automation process when it comes to visual regression.</p><blockquote><strong>When and How this occurred ?</strong></blockquote><p>It was the usual deployment day and a very strange issue took place, where some of the frontend UI changes in the UAT / QA environment was not being reflected on the Production / Live environment. These kind of issues are hard to be spotted on the day of deployment, as there are higher priority features that need to be tested. Although, when we rectified some logos on the site were moved to the right, some images were not correctly indented and so on.. Nightmare! The first thing our developer checked was, to compare the CSS files in the Chrome console that were on the UAT / QA server with the Live / Production server- and there it was .. the CSS classes were missing and some did not have the required changes. :(</p><blockquote><strong>Solution</strong></blockquote><p>After some research online, I did find one such tool that would avoid such a situation. It would scan the same pages from different environments and point out what are the differences at a CSS and pixel level. This was none other than <strong>BackstopJS.</strong></p><blockquote><strong>What is BackstopJS OR Visual Regression Testing?</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*gjfbYf-mUBlmf9Ktmzf9Pg.jpeg" /><figcaption>Taken from the official BackstopJS Github page.</figcaption></figure><p>BackstopJS is an open source automation developed by Garris and a bunch of other clever engineers. It automates visual regression testing of your responsive web UI by comparing DOM screenshots over time.</p><blockquote><strong>Impatient ? Let me show you what the end result looks like ;)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w9BGPDHHb5Su9bFRaldOWQ.png" /></figure><p>These are three screenshots from three different environments or URLs. Highlighted in pink are the ‘changes in UI’ that the tool detects. Interesting ?lets go ahead and set it up.</p><blockquote><strong>Installing nodejs and npm — dependencies for BackstopJS</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2DUUCOkayOA_Yd3u1gQctQ.png" /></figure><p>We have multiple ways to install BackstopJS, lets use npm in our case. What is npm ? Read here.. <a href="https://docs.npmjs.com/about-npm">https://docs.npmjs.com/about-npm</a></p><p>In short, what is <a href="https://docs.npmjs.com/about-npm"><strong>npm</strong> </a>? Its a Node package and dependency manager. There are millions of packages out there (imagine a library with many books), one such package is backstop JS. Although lets start from step 0.</p><p>To install npm you need a pre-requisite of NodeJS in your machine. Download the LTS version from here <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a> (you can choose Windows or Mac or Linux depending on your machine OS)</p><p>Once NodeJS is installed successfully you can verify by running this command in your terminal / Command Prompt. Lets begin..</p><ol><li>Windows &gt; Start &gt; CMD (better to right click and open as Administrator)</li><li>type node node -v OR node --version &gt; hit enter &gt; below is what you should see</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*-y4qdaAGmN3w8kdFEIXn4Q.png" /><figcaption>the current version while writing this article is 14.15.1, you may have a higher ver.</figcaption></figure><p>3. Install npm, npm install npm@latest -g this will install the latest version of npm on your machine.</p><p>4. Verify npm by typing npm -v in CMD same as step 2, below is what you should see</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*zcspktMGuRZRmvWfrlCA4g.png" /><figcaption>the current version while writing this article is 6.14.8, you may have a higher ver.</figcaption></figure><p>Now you have successfully installed NodeJS + npm on your machine.</p><blockquote><strong>Installing backstop, finally! :D</strong></blockquote><ol><li>Open terminal / command prompt and type npm install -g backstopjs (here g means, we are installing backstopjs globally and can be run through any part of the system) below is what you should see in your terminal as a result of running this command</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*KSEd2JxeZJhSqTT0bb_yMw.png" /></figure><p>2. As you see in the console / cmd along with backstopjs the package also installs a ‘headless chrome browser called chromium’. BackstopJS uses this headless browser to load the web pages and then compares them individually which is the final output for us.</p><blockquote><strong>Code Editor</strong></blockquote><ol><li>Before initializing BackstopJS I would highly recommend you to install any editor of your choice, although my preference would be Visual Studio Code. It is free, light, has intellisense to autofill your code, error handling and also supports almost all coding languages<em>(this way you don’t need to switch windows from an editor to cmd)</em> Download from here <a href="https://code.visualstudio.com/Download">https://code.visualstudio.com/Download</a></li><li>Create a new folder in your machine and open it in visual studio code. For this open visual studio code &gt; file &gt; open folder &gt; locate the folder you created. In my case I have created a backstop_medium and this is how it looks, its a blank canvas :)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HWMKIT5OOV1Tc3k4SJuPcw.png" /></figure><p>2. In the top bar click on Terminal &gt; New Terminal &gt; below is what you should see in the bottom window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYn9EsZsbMe1oT5_Q5QCVA.png" /></figure><p>3. Lets run those commands !</p><blockquote><strong>Initialize BackstopJS</strong></blockquote><ol><li>In the terminal we will type backstop init hit enter.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hTLSXfIWNns6jZI8KTCvvw.png" /></figure><p>There are two changes that you can see in your editor now,</p><ol><li>A successful initialization of backstop.</li><li>A new folder that is created under your main folder. backstop_data</li><li>A {}backstop.json file that is created separately. For now lets focus on this file in particular as it help us add configurations to run our test.</li></ol><blockquote><strong>The backstop.json file</strong></blockquote><ol><li>The backstop.json file is the control room for the configurations you enter and based on these configurations the tool performs its comparison.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*XtTgS4iCDSBSwznarmrftw.png" /></figure><p>Viewports are the screen sizes in which you want the browser to compare your website. This helps when your website is responsive and you can compare the screens at a mobile, tablet, iPad and desktop level.</p><p>You may keep adding viewports in the above format specifying the sizes of the screens that you want to compare and define a label for each of the screens.</p><p>2. Scenarios — here you can define multiple actions that backstop needs to consider- such as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*t1QY8ddNZ_CExN7KAITQlQ.png" /></figure><p>In the above screenshot you can see a “url” which is the live url you want to test and referenceURL is that you want to compare with. In our case we are testing + comparing the uat.website.com (test) with the website.com (Live working website). Other labels can be interpreted in the below definitions</p><pre>label                    // [required] Tag saved with your reference images<br>onBeforeScript           // Used to set up browser state e.g. cookies.<br>cookiePath               // import cookies in JSON format (available with default onBeforeScript see setting cookies below)<br>url                      // [required] The url of your app state<br>referenceUrl             // Specify a different state or environment when creating reference.<br>readyEvent               // Wait until this string has been logged to the console.<br>readySelector            // Wait until this selector exists before continuing.<br>delay                    // Wait for x milliseconds<br>hideSelectors            // Array of selectors set to visibility: hidden<br>removeSelectors          // Array of selectors set to display: none<br>onReadyScript            // After the above conditions are met -- use this script to modify UI state prior to screen shots e.g. hovers, clicks etc.<br>keyPressSelectors        // Takes array of selector and string values -- simulates multiple sequential keypress interactions.<br>hoverSelector            // Move the pointer over the specified DOM element prior to screen shot.<br>hoverSelectors           // *Puppeteer only* takes array of selectors -- simulates multiple sequential hover interactions.<br>clickSelector            // Click the specified DOM element prior to screen shot.<br>clickSelectors           // *Puppeteer only* takes array of selectors -- simulates multiple sequential click interactions.<br>postInteractionWait      // Wait for a selector after interacting with hoverSelector or clickSelector (optionally accepts wait time in ms. Idea for use with a click or hover element transition. available with default onReadyScript)<br>scrollToSelector         // Scrolls the specified DOM element into view prior to screen shot (available with default onReadyScript)<br>selectors                // Array of selectors to capture. Defaults to document if omitted. Use &quot;viewport&quot; to capture the viewport size. See Targeting elements in the next section for more info...<br>selectorExpansion        // See Targeting elements in the next section for more info...<br>misMatchThreshold        // Percentage of different pixels allowed to pass test<br>requireSameDimensions    // If set to true -- any change in selector size will trigger a test failure.<br>viewports                // An array of screen size objects your DOM will be tested against. This configuration will override the viewports property assigned at the config root.</pre><p>Puppeteer mentioned above is another kind of a headless browser with additional capabilities than chromium. In case you want to stick to Chromium, change “engine”: “puppeteer” to engine : “chromium”</p><p>You can install puppeteer using a npm command. Simply in your terminal type: npm i puppeteer</p><p>PS: I can explain any specific scenario in detail if you wish to, please mention in comments. In this article I am explaining a basic test run for any two pages / URLs. You can add multiple scenarios, set a delay time and cover more test cases for visual regression.</p><blockquote><strong>Run the test</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jfBpVQ7ycWnceJgw6uEkpA.png" /></figure><p>After all your settings are in place- remember to save the json file, post that in the terminal you can run backstop test . You will see various actions being processed in your terminal and your browser will automatically open your result html page with pass / fail, screenshots and more.. You can even click on any one particular file and compare each section of the screen using a scaler.</p><p>Feel free to comment in the comments below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=789ebe709926" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>