Skip to main content

Posts

Showing posts with the label RestAssured

Want to share Test Results to MS Teams using AdaptiveCards.io?

Steps to follow: Microsoft Teams WebHook: Follow this  https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook to create a webhook. Capture the  URL you will get from Step # 5 from the above article for Posting the Results in MS teams. Select a design from https://adaptivecards.io/samples/ or you can take the one that I created here:  https://github.com/dgambhir01/AdaptiveCards/blob/main/src/main/java/listeners/ResultBuilder.java Now implement the Builder Class and a POJO Class. Sample code:  https://github.com/dgambhir01/AdaptiveCards/blob/main/src/main/java/listeners/CardBodyStructure.java Last but not least add a Listener Class to send Results on Finish. Sample code:  https://github.com/dgambhir01/AdaptiveCards/blob/main/src/main/java/listeners/ResultListener.java Now you can add the above TestNG Listener to your TestNG XML File and run your test cases.  After the Execution, you should see your test results like:

How to upload a pdf file using REST Assured?

 If you use this code as mentioned in few other blogs and videos:   Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "multipart/form-data"); byte[] fileContent = FileUtils.readFileToByteArray(new File(filePath)); RestAssured.given().headers(headers).body(fileContent).post(url);   There are high chances that you will get errors related to content-type or "400 - Request is not a multipart request". So, the solution is to use: .multiPart("file", new File("/path/to/file"),"application/pdf"). Please note that I have used "application/pdf" as 3rd param in the multiPart method and this value should be passed as per the file type that you are uploading like for the png file it should be "application/octet-stream", for JSON file it should be "application/JSON". multiPart is an overloaded method that can take max 3 parameters:   a)

AWS Signature with RestAssured

  AWS Signature authentication support is not something that is available in RestAssured as out-of-box feature. At least I wasn't able to find any good documentation for the same. So, how we can implement AWS Signature Headers with Rest Assured? Signing AWS requests with Signature Version 4... This explains step by step how to create a signature and add it to an HTTP request to AWS: https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html Below given source code (AWSV4Auth.java) helps to calculate signature based on given data and return the headers. Once you get headers suing aWSV4Auth.getHeaders(), you just need to add these headers in your Rest API call (Sample for the same is given below: RATest.java) AWSV4Auth.java: public class AWSV4Auth {     private AWSV4Auth() {     }     public static class Builder {         private String accessKeyID;         private String secretAccessKey;         private String regionName;         private String serviceName;         private Str

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

Automation RoadMap (Selenium and Rest Assured)

Happy and healthy new year to everyone. A note to all the manual testers out there: Upgrade your skills not only for survival in today's dynamic IT world but mainly to feed your brain with new challenges. Shred your old self completely- Spend at least 45 minutes of the day, no matter how busy you are, block this time off your daily schedule in learning test automation. If you do not have interests per se, develop an interest by going through videos first and then jump to implementation by taking baby steps. Read. Get Mentors. Learn. Observe. Experiment. Reiterate until success. Wish you all the success and prosperity this year. I created this roadmap, see if this helps for Selenium with Java learning: https://www.linkedin.com/posts/dheerajgambhir_automation-selenium-git-activity-6568387687412273152-SjE8/ I created this roadmap, see if this helps for API automation using Rest Assured: https://www.linkedin.com/pulse/roadmap-learn-api-automation-testing-using-dheeraj

Why all API enthusiasts should know about GraphQL?

With GraphQL, what you queried is what you get, nothing more and nothing less. It is easy to use as it has a JSON like syntax and also provides lots of performance benefits. Here's a query for the Star Wars API: https://swapi.apis.guru/graphiql query{ allFilms { films { id title episodeID } } } This query returns the id, title, and episodeID of the 6 original Star Wars movies. Now consider that there are 2 vendors that are consuming this API and one of them wants id, title, and episodeID and the other one wants the only id, and title but NOT the episodeID. Now without GraphQL, we would have created 2 versions of this API i.e. the first one with the id, title, and episodeID in the response and the second version giving a response with id and title only. Isn't it a headache to maintain so many versions if you have different requests from various vendors that are consuming your APIs? That's where a GraphQL is a real lifesaver. Please check graphQLComplete method shown