<?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 Subashini Meganathan on Medium]]></title>
        <description><![CDATA[Stories by Subashini Meganathan on Medium]]></description>
        <link>https://medium.com/@shubameg48?source=rss-2d58d5bdd7d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ptk4vEHGB78DYLkbfLPeUw.gif</url>
            <title>Stories by Subashini Meganathan on Medium</title>
            <link>https://medium.com/@shubameg48?source=rss-2d58d5bdd7d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 08:53:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shubameg48/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[Serialization and Deserialization in Rest Assured API Testing]]></title>
            <link>https://medium.com/@shubameg48/serialization-and-deserialization-in-rest-assured-api-testing-6e676c9adefa?source=rss-2d58d5bdd7d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e676c9adefa</guid>
            <dc:creator><![CDATA[Subashini Meganathan]]></dc:creator>
            <pubDate>Mon, 20 Sep 2021 17:45:35 GMT</pubDate>
            <atom:updated>2021-09-24T14:06:48.863Z</atom:updated>
            <content:encoded><![CDATA[<p>In Java, Serialization is a process of converting an object from its current state to a stream of bytes which can be written to a file or transported through a network or stored in a database.<br>De-serialization is rebuilding the object from stream of bytes.</p><p>Pre-requisites:</p><ul><li>Basic knowledge of making http calls with request payload using Rest Assured.</li><li>API service that I have used for my project here is LMS API service.</li><li><a href="https://lms-program-rest-service.herokuapp.com/programs">https://lms-program-rest-service.herokuapp.com/programs</a></li><li>The following should be installed in the system:-Java, IDE(I have used Eclipse), Maven</li></ul><p><em>Relevant</em> POM libraries-latest versions<br>Rest Assured 4.4.0<br>json Schema validator 4.3.3<br>jackson databind 2.12.5<br>jackson core 2.12.5<br>jackson annotations 2.12.5<br>gson 2.8.6<br>TestNG 7.3</p><p><em>and now</em> your project is ready to support serialization and deserialization.</p><p><em>Let’s</em> take an example of a json that we intend to send as request payload for a Post operation, to the end point while making an http Post call to the LMS server.</p><p>{<br> “online”: true,<br> “programDescription”: “String”,<br> “programId”: 0,<br> “programName”: “String”<br>}</p><p>There are several ways to construct our request payloads.</p><ul><li>We can provide the json directly into the body by providing special characters in a string</li><li>We can provide static json payload into a file and we can send that json file as an input by giving the path</li><li>Wrap up a full json payload into a method and sending the parameters dynamically into that method</li><li>We can create json using Hashmap</li><li>Creating a java object out of json — and This is what I’m going to demonstrate here!</li></ul><p>First, We can create a POJO class(Plain Old Java Object), which has better readability and serves re-usability purpose. How do we do this?</p><p>Observe the json payload again. Do you see the format in Keys and values?<br>For every key in the json, we will create a variable for the same, inside a class.</p><p>eg. private String programName;</p><p>Then for that particular variable, we need to create two methods which are getters and setters.</p><p>We can define the getter method as ‘get’ followed by variable name(see example). This method returns key “programName” passed through json payload. eg.</p><p>public String getProgramName()<br>{<br>return programName;<br>}</p><p>We can define the setter method as ‘set’ followed by variable name. This method helps in setting the value to the variable “programName” passed thro’ json payload.<br>public void setProgramName(String programName)<br>{<br> this.programName = programName;<br>}</p><p>Similarly, let’s create variables and methods for rest of the key and value pairs from our intended json request payload. Make sure to create all the variables as private and all methods as public. This is the standard for defining POJO class.</p><p>An alternate and EASY way of creating this getters and setters methods is-<br>First, declare all fields as private.<br>Next highlight on the fields, press ‘Alt+shift+s’ right click and choose “Generate Getters and Setters”<br>Rest Assured automatically creates all the methods without hassle.</p><pre>package funcTesting;</pre><pre>public class ProgramInfo {</pre><pre>private String programId;<br>private String programName;<br>private String programDescription;<br>private String online;</pre><pre>public String getProgramId() {<br>return programId;<br>}</pre><pre>public void setProgramId(String programId) {<br>this.programId = programId;<br>}</pre><pre>public String getProgramName() {<br>return programName;<br>}</pre><pre>public void setProgramName(String programName) {<br>this.programName = programName;<br>}</pre><pre>public String getProgramDescription() {<br>return programDescription;<br>}</pre><pre>public void setProgramDescription(String programDescription) {<br>this.programDescription = programDescription;<br>}</pre><pre>public String getOnline() {<br>return online;<br>}</pre><pre>public void setOnline(String online) {<br>this.online = online;<br>}<br>}</pre><p>Now, the POJO class is ready!</p><p>In the following Test class, we will create a Rest Assured Test to complete the serialization process by passing the above pojo class to the API.</p><p>First, We will create an object of the above pojo class as</p><p>ProgramInfo pinfo = new ProgramInfo();</p><p>RestAssured will automatically convert the POJO class into a json object and as of now the setters will be empty <br>{ <br> “programId”: “0”,<br> “programName”: “ ”,<br> “programDescription”: “ ”,<br> “online”: “ ”<br>}</p><p>In java, after we create the object, we can access the methods present in the class. Next, using the reference object, set the values with the help of setters methods. <br> pinfo.setOnline(“true”);<br> pinfo.setProgramDescription(“Intro to Sql by shu220”);<br> pinfo.setProgramId(“0”);<br> pinfo.setProgramName(“SQL220”);</p><p>These values are passed to the setter methods as arguments and are passed to the private variables through ‘this’ keyword (In java this keyword refers to the current class variables).<br>Now, once the values are assigned to the variables, automatically the values are filled inside the json object as in..</p><p>{<br> “programId”: “0”,<br> “programName”: “SQL220”,<br> “programDescription”: “Intro to Sql by shu220”,<br> “online”: “true”<br>}</p><p>Finally, write the Rest Assured test script and pass the ‘pinfo’ object as part of request payload body to make the Post call.</p><pre>package funcTesting;</pre><pre>import static io.restassured.RestAssured.given;</pre><pre>import org.testng.annotations.Test;</pre><pre>import io.restassured.RestAssured;</pre><pre>import io.restassured.response.Response;</pre><pre>public class PojoTest1_lms {</pre><pre>@Test</pre><pre>public void tosetProgramDetails(){</pre><pre>ProgramInfo pinfo = new ProgramInfo();</pre><pre>pinfo.setOnline(&quot;true&quot;);</pre><pre>pinfo.setProgramDescription(&quot;Intro to Sql by shu220&quot;);</pre><pre>pinfo.setProgramId(&quot;0&quot;);</pre><pre>pinfo.setProgramName(&quot;SQL220&quot;);</pre><pre>RestAssured.baseURI=&quot;https://lms-program-rest-service.herokuapp.com/programs&quot;;</pre><pre>Response res = given().log().all().auth().basic(&quot;admin&quot;,&quot;password&quot;)</pre><pre>.header(&quot;Content-Type&quot;, &quot;application/json&quot;)</pre><pre>.body(pinfo)</pre><pre>.when().post()</pre><pre>.then().assertThat().statusCode(200).extract().response();</pre><pre>String response = res.asString();</pre><pre>System.out.println(response);</pre><pre>}</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oeQc569H6mLCRV5Lqgrr_g.png" /><figcaption>Program created in the server using Pojo class</figcaption></figure><p>All these process of converting the java object(using POJO classes)into request payload is Serialization.</p><p>How good is serialization without understanding De-serialization. That follows …</p><p><strong>Deserialization in Rest Assured</strong> is converting Responsebody back to java object with the support of pojo classes.<br>If the response is wrapped as java object, then it is easy to parse and extract response using getters methods.<br>yes, POJO classes are created here too. Just that the variables in this pojo class is created for the Keys of json response body.</p><p>Let’s come to our LMS API sample.</p><p>Our LMS API responsebody looks something like this-<br>[</p><p>{<br> “online”: true,<br> “programDescription”: “String”,<br> “programId”: 0,<br> “programName”: “String”<br>}<br> {<br> “programId”: 338,<br> “programName”: “SQL220”,<br> “programDescription”: “Intro to Sql by shu220”,<br> “online”: “true”<br> }</p><p>]</p><p>Here, the endpoint ‘/Programs’ from the LMS api has similar data of multiple programs, hence the data has been designed to be stored in the array format.<br>Now, How do we convert this simple JSON Array response that we receive from hitting our LMS API to a POJO class, so that we can extract any response out of it easily?</p><p>First, we need to create a POJO class for the Keys from the response body. But wait, don’t we already have the pojo class for this with all the fields and getters and setters methods as in- programInfo.java</p><pre>package funcTesting;</pre><pre>public class ProgramInfo {</pre><pre>private String programId;</pre><pre>private String programName;</pre><pre>private String programDescription;</pre><pre>private String online;</pre><pre>public String getProgramId() {</pre><pre>return programId;</pre><pre>}</pre><pre>public void setProgramId(String programId) {</pre><pre>this.programId = programId;</pre><pre>}</pre><pre>public String getProgramName() {</pre><pre>return programName;</pre><pre>}</pre><pre>public void setProgramName(String programName) {</pre><pre>this.programName = programName;</pre><pre>}</pre><pre>public String getProgramDescription() {</pre><pre>return programDescription;</pre><pre>}</pre><pre>public void setProgramDescription(String programDescription) {</pre><pre>this.programDescription = programDescription;</pre><pre>}</pre><pre>public String getOnline() {</pre><pre>return online;</pre><pre>}</pre><pre>public void setOnline(String online) {</pre><pre>this.online = online;</pre><pre>}</pre><p>So we will just head to creation of Deserialization test-</p><p>We need to parse response using POJO class. But the current pojo class has only one program detail.</p><p>Then how do we handle multiple responses that is wrapped under a JSON array?</p><p>When we convert the response to pojo class, we need to convert the class as an array eg. .as(programInfo[].class) and store the results in a variable of arrayclass type.</p><p>Now we can easily call the response of the last added program using indexes.</p><pre>package funcTesting;</pre><pre>import org.testng.annotations.Test;</pre><pre>import com.fasterxml.jackson.core.JsonProcessingException;</pre><pre>import com.fasterxml.jackson.databind.JsonMappingException;</pre><pre>import io.restassured.RestAssured;</pre><pre>public class PojoTest2_lms {</pre><pre>@Test</pre><pre>public void getPojoFromProgramInfoObject() throws JsonMappingException,JsonProcessingException</pre><pre>{</pre><pre>//Deserialization</pre><pre>ProgramInfo[] allprogramdetails = RestAssured.given().auth().basic(&quot;admin&quot;, &quot;password&quot;).log().all()</pre><pre>.when().get(&quot;https://lms-program-rest-service.herokuapp.com/programs&quot;).as(ProgramInfo[].class);</pre><pre>System.out.println(&quot;no of programs: &quot;+ allprogramdetails.length);</pre><pre>System.out.println(&quot;Program Name: &quot;+allprogramdetails[allprogramdetails.length-1].getProgramId());</pre><pre>System.out.println(&quot;Program Name: &quot;+allprogramdetails[allprogramdetails.length-1].getOnline());</pre><pre>System.out.println(&quot;Program Name: &quot;+allprogramdetails[allprogramdetails.length-1].getProgramName());</pre><pre>System.out.println(&quot;Program Description: &quot;+allprogramdetails[allprogramdetails.length-1].getProgramDescription());</pre><pre>}</pre><pre>}</pre><p>A variation — In real time, we might mock the data for API testing.</p><p>Here, We will mock our LMS service sample response to use in our Rest Assured test.</p><p>Use Postman or swagger to make a get call to the LMS service and copy as many responses you want to use for mocking.</p><p>Verify it in jsoneditoronline.org</p><p>Using any Api mocking tool, get the mock url(https://medium.com/I%20used%20designer.mocky.io)<br>Note that we are not hitting the real server but replacing with the mock url.</p><p>So, your test looks like this.. (make sure to change your mock url)</p><pre>package funcTesting;</pre><pre>import org.testng.annotations.Test;</pre><pre>import com.fasterxml.jackson.core.JsonProcessingException;</pre><pre>import com.fasterxml.jackson.databind.JsonMappingException;</pre><pre>import io.restassured.RestAssured;</pre><pre>public class PojoTestMock {</pre><pre>@Test</pre><pre>public void getPojoFromMockUrlofsimplejsonArray() throws JsonMappingException,JsonProcessingException</pre><pre>{</pre><pre>//Deserialization using sample mock</pre><pre>// you paste your mock url</pre><pre>ProgramInfo[] allprogramdetails = RestAssured.given().log().all()</pre><pre>.when().get(&quot;https://run.mocky.io/v3/cf3fb516-8429-4e5e-8fc0-2cfbde6b6ff9&quot;).as(ProgramInfo[].class);</pre><pre>System.out.println(&quot;no of programs: &quot;+ allprogramdetails.length);</pre><pre>System.out.println(&quot;Program Name: &quot;+allprogramdetails[0].getProgramId());</pre><pre>System.out.println(&quot;Program Name: &quot;+allprogramdetails[3].getProgramId());</pre><pre>System.out.println(&quot;Program Name: &quot;+allprogramdetails[0].getProgramName());</pre><pre>System.out.println(&quot;Program Description: &quot;+allprogramdetails[3].getProgramName());</pre><pre>}<br>}</pre><p>Execute and check your results!</p><p>Explore more! Happy Learning!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e676c9adefa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My attempt to show a glimpse of Page Object Model in Selenium using Page Factory for the curious…]]></title>
            <link>https://medium.com/@shubameg48/my-attempt-to-show-a-glimpse-of-page-object-model-in-selenium-using-page-factory-for-the-curious-41e5295cd6f5?source=rss-2d58d5bdd7d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/41e5295cd6f5</guid>
            <dc:creator><![CDATA[Subashini Meganathan]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 18:11:04 GMT</pubDate>
            <atom:updated>2021-09-07T18:11:04.256Z</atom:updated>
            <content:encoded><![CDATA[<p>My attempt to show a <strong>glimpse of Page Object Model in Selenium using Page Factory</strong> for the <em>curious</em> <em>beginners</em>..</p><p>I’m trying to show -</p><ul><li>Same application in three views- simple Java, TestNg, Pom pattern</li><li>Passing of a driver in Page Object Model</li></ul><p><em>Let me compare</em> POM concept to something that is close to our minds. The story starts like this…Here imagine yourself navigating and checking your premises.</p><p><strong>First Scenario:</strong> JAVA Application<br><em>Assume</em> you own a single room called your home in New York City which serves all your purposes.<br>Use your key to enter that room. <em>Compare</em> the key to the process of a WebDriver that communicates to the specific browser through its respective driver for launching of a browser and logging into the site — all done within<br> a class under a main method inside a java project.<br><em>Back to your room</em>, you might have all utensils, appliances, furniture in your room to meet your needs.<br>You might just sleep and get out of the room or cook, eat, sleep, before leaving the room. <br><em>Back to your java project</em>, relate your utensils and appliances to the web elements on the webpage and the actions that you do with it as different workflows on the webpages in the sequence of your preference, before logging out of the site and closing the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6O3MDIIxyTSKIU-4d4aNLg.png" /><figcaption>simple Java Application</figcaption></figure><p><strong>Second scenario:</strong> TestNG Application<br><em>Entering an other similar house as above</em>, just that you have a foyer and a garage additionally. <br>Now <em>compare</em> it to a creation of TestNG class with default <a href="http://twitter.com/BeforeTest">@BeforeTest</a> and <a href="http://twitter.com/AfterTest">@AfterTest</a> annotations or a regular java class where you have added the same TestNG annotations respectively. <br><em>Relate</em> the opening of your front door at the foyer with a key, to the process of WebDriver’s communication through browser-specific driver in launching of a browser under a method implementation tagged with <a href="http://twitter.com/BeforeTest">@BeforeTest</a> annotation.</p><p><em>As in the first scenario</em>, using various properties in this house you might do several combinations of actions as you feel appropriate. Similarly, using the driver in locating various elements in the web pages you might perform various combination of actions. The<em> difference</em> <em>here</em> is that these actions are defined as various methods tagged with different <a href="http://twitter.com/Test">@Test</a> annotations.<br> <br><em>Lastly</em>, relate the locking of the Garage door before you step out of your home with an aftertest method implementation where you close the browser, tagged with <a href="http://twitter.com/AfterTest">@AfterTest</a> annotation.</p><p>The point to note in this TestNg application is that every method implementation tagged by <a href="http://twitter.com/TEST">TEST</a> annotation is preceded by method implementation tagged with <a href="http://twitter.com/BeforeTest">BeforeTest</a> annotation and succeeded by the implementation of method tagged by <a href="http://twitter.com/AfterTest">AfterTest</a> annotation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h2vuIKHG7uZ_REgCeNtJUA.png" /><figcaption>TestNG application</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcQarmfj7ppbBXSdrpqQ5Q.png" /><figcaption>An alternate sample TestNG</figcaption></figure><p>Third Scenario: POM (Page Object Model)<br><em>Assume</em> you own a house with several rooms- open living room, a bedroom, along with a foyer and a garage.<br><em>Compar</em>e this to a Maven Project with default folder structures within which we create packages and classes. <br><em>The emphasis</em> in this POM Design pattern is that different pages in the application is represented as separate java class files for each and every page.<br>Here, <em>visualize</em> the rooms in your home as to the page classes in respective packages under source folders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYSXRE5xXJeQy1rEmildYQ.png" /><figcaption>Maven folder Structure in POM</figcaption></figure><p><em>Now, driver journey starts</em>…let’s relate the opening of the front door with the master key, to the driver object launching a browser and logging into a site.<br> <em>Unlike in the above two scenarios</em> the browser script for this is kept under a separate class called as Base Page class.<br><em> Make sure to define</em> the driver variable in this Base page with access specifier as “public static WebDriver driver” so that it holds always the last reference to the driver.</p><p>Reverting to our Home analogy, let’s not under estimate the capabilities of a <em>Switch Board in your home</em>!</p><p>Same holds true for Constructor concept in Java which is created for <em>initialization of variables/Web Elements</em> in an application.<br>The point to be observed here is that the Code for initializing the driver is done <em>inside a</em> <em>constructor</em> of that page. This helps <em>avoid redundancy</em> of WebDriver object declaration and initialization in each of the other pages which we will discuss later while creating those pages. Also constructor takes the responsibility to get the driver instance from the Test class. Here, the driver instance declared as null within an if condition will be true only for the first time there by opening a new browser window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXIU76YIzGwzq69EZLzbzQ.png" /><figcaption>BasePage</figcaption></figure><p>Now the same driver navigates across all other pages. How does this happen? you will understand this in the later part of the story…</p><p><em>Before that</em> let’s make sure every other page of the website/application will have a separate class of its own and make sure each page extends BasePage. Every page must have the following significant aspects-<br> <br>1.<em>Identification</em> of WebElements is done for its respective pages’ using <a href="http://twitter.com/FindBy">@FindBy</a> annotation, object location strategy, belonging to Selenium<br>2.Constructor is invoked to <em>initialize </em>the WebElements belonging to this page using PageFactory class with its initElements method <br>3.thirdly, the page holds <em>methods</em> relating to the actions that could be performed in that specific page.</p><p><em>A point to note</em>, these pages do not have to declare WebDriver object of its own as it is served from the BasePage through the concept of inheritance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJ043NBiPv3-Ncts__kGow.png" /><figcaption>LivingRoom Page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMQFvLuIuMxqcVVk9GHm1A.png" /><figcaption>BedRoomPage</figcaption></figure><p>Establishing relationship between Pages-<br> <em>Resuming to our home analogy</em>, often we need to run into other rooms to finish our chain of works, right?<br><em>In the same fashion</em>, execution of one action/method will land us in an other page. To recognize this aspect the return type of that method will be declared as the landing page object. This helps in establishing the relationship between pages.(Imagine the implementation of toswitchofflights method in livingroom page example lands you on bedroompage. Then by using the return statement, the return type of this method could be changed to Bedroom object instead of void. You can explore this <em>page chaining in POM </em>concept further online)</p><p>Now comes the actual testing -</p><p>Create a HomePOMTest class inside a Test package under source folder- src/test/java.<br><em>First and foremost</em>, make sure to extend the BasePage class to this HomePOMTest class to inherit the properties of Parent class as per the java inheritance OOPS concept. <br><em>Next</em>, Create an instance of an Object of each page class.<br>The <em>reference object</em> of each page class instance helps in calling all the data members and the methods from the related pages as needed while executing the tests for validation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v52_aTXWKUU0K513jlc-pQ.png" /><figcaption>HomePOMTestPage</figcaption></figure><p><em>Last but not the least</em>, let me draw your attention to closing of the garage door before leaving the house just not to leave it vulnerable. That’s right! you got to invoke the lock method to close the browser and if you had observed that method is accommodated in the lock() inside Base Page itself.</p><p>If you could understand the difference in the above three scenarios, You at least got partially <em>POM in your PALM</em>!!</p><p>As this is just the beginning, explore more to learn further in this topic! <em>Happy Learning!!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41e5295cd6f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>