Skip to main content

Posts

JSON to POJO

In case you have JSON or JSON-Schema (simple or complex) that you want to map into a POJO without hustling too much to write a complete POJO class, then you can use the jsonschema2pojo UI or library. It is an awesome library that lets you create Java classes using your input JSON. Plus, it supports many Annotation styles such as Jackson, Gson, etc. Using UI: http://www.jsonschema2pojo.org Or https://github.com/csanuragjain/extra/tree/master/convertJson2Pojo (Git Repo by Anurag Jain) P.S. There are many other ways to achieve this and this is just one of them.

Benefits of running your automation suite

In the agile world, the deployment window will continue to grow narrow and for sure you can’t catch every bug- so, always use the power of both i.e. on-demand (including webhook on every change) and scheduled automation test suite run.  On one hand, your on-demand test run will make sure that you get fast feedback (i.e. which change and by whom broke it) and also you will get the complete test coverage. And, on the other hand, your scheduled runs ensure that you get continuous feedback, don't push any broken pieces to the next environment and hence confidence in your code changes especially after the integration with the larger system(s). Keep your builds green (Organically).

Copy paste java code from clipboard to your Eclipse

Small but a cool and an old trick for copy-pasting Java code in Eclipse. I have seen so many folks are still doing this when they want to copy-paste the Java code from the net via clipboard in their Eclipse. >Right click on the target folder where you want clipboard Java code >New >Create Class >Give a name and then finally remove the default code in this class and paste the Java code from their clipboard. You don't need to do all this. Just Right-click on the target folder where you want this Java code and paste from the clipboard or directly CTRL+V. Nice- isn’t it? Sample code: package com.test.apiAutomation.test; import java.util.HashMap; import java.util.Map; import org.testng.annotations.Test; public class TestCopyPaste { @Test public static void testCopyPaste() { Map<String, String> formParams = new HashMap<String, String>(); formParams.put("grant_type", "hey"); System.out.println("It's working, TADA

Want to read something of your gmail (not only subject but body content too) using javax Lib?

Want to read something of your Gmail (not only subject but body content too) using javax Lib? For contentBody where MimeType is "text/plain" i.e. it's a plain text message, it works straight forward by using getContent() method but in case you have contentBody MimeType= text/html i.e. the message body only in HTML, you need to take care of Multipart for multipart/alternative and multipart/mixed based on your requirements. Here's the working code: Note * You still need to tweak the code based on your requirements like if there are more than 1 unread or read emails having the same subject that you are trying to look for in the subject like by setting Flags.Flag.DELETED=True before reading this new email or using Flags.Flag.RECENT=True. You may need to enable less secure apps to use JavaMail with Gmail: https://myaccount.google.com/lesssecureapps // userName is your gmail userName // password is your gmail password // subjectToContains is what you need to lo

Accessibility testing: Chrome DevTools

Though there are specifically designed tools like NVDA, Jaws, etc. for accessibility testing but if you would like to perform a quick Accessibility test on your website for below mentioned P1 checks, please go through this link : https://developers.google.com/web/tools/chrome-devtools/accessibility/reference - The user is able to navigate through the page with a keyboard or/and screen reader? - Are the page(s) elements properly marked up for screen readers?

JSON Server: Rest API

I get that a lot that there are so many folks especially college students who struggle to find Rest APIs where they can play not only with the GET but with POST, PUT, DELETE methods too. The JSON Server is a popular and handy tool that lets you play with the mock REST APIs. It helps you to set up a REST API with CRUD operations very fast. Please go through this link to know more about it: https://github.com/typicode/json-server From set-up >> installation >> usage- everything is so simple. I recommend to use it along with the faker library to make it more effective: https://github.com/Marak/faker.js , like by creating a js file to inject the fake data: module.exports = () => { var faker = require("faker"); const data = { users: [] } // Create 50 users for (let i = 0; i < 50; i++) { data.users.push({ id: i, name: faker.name.findName(),email:faker.internet.email(), zipCode: faker.address.zipCode()}) } return data } Here's th

RestAssured Vs Karate

RestAssured Vs Karate Initial Score: Rest Assured 0- Karate 0 1) RestAssured is really good but there is no built-in way to do a full equality match of a JSON payload in one step (not talking about extracting a particular field out of the response JSON). Contrary to this, Karate offers full JSON Comparison with so much ease (as shown in the first image below). And in case you have some node that shows dynamic value then you can simply ignore it by using hashtag # ignore for that node (as shown in the second image below). Note* There is no direct command to compare the whole response in RestAssured at once but we can still use JsonPath to parse the JSON file into a Map and then compare it with Hamcrest Matchers. Current Score: Rest Assured 0- Karate 1 2) Ease of using matchers: The powerful matching logic of Hamcrest is unbeatable in Rest Assured. Of course, we can use RegEx and Macros in Karate for the match but you need to learn that first. Final Score: Rest Assured 1