Sunday, August 22, 2021

Post#140-API#9 Parsing Json String using GSON library

 ðŸ‘‡

To use GSON library you have to add maven dependency in your project.

GSON as a Maven dependency looks like this:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.8</version>
</dependency>

 Let's take the below JSON as an example:

Post#139-API#8 Rest Assured GET Test

 ðŸ‘‡

Before we create our REST Assured tests, make sure that you have added Rest Assured library and TestNG library in your Maven project.

In this tutorial I am using below URL for different request.

https://reqres.in/

Below code snippet shows how to call GET method and test response JSON elements.

package testcase2;

import org.testng.annotations.Test;

import io.restassured.RestAssured;

Post#138-API#7 The components of a URL

 ðŸ‘‡

A URL (Uniform Resource Locator) is a specific type of URI (Universal Resource Identifier). A URL normally locates an existing resource on the Internet. A URL is used when a web client makes a request to a server for a resource.

Briefly, a URI is defined as any character string that identifies a resource. A URL is defined as those URIs that identify a resource by its location or by the means used to access it, rather than by a name or other attribute of the resource.

Saturday, August 21, 2021

Post#137-API#6 Idempotency with HTTP Methods

 ðŸ‘‡

What Is Idempotent in REST?

In the context of REST APIs, when making multiple identical requests has the same effect as making a single request – then that REST API is called idempotent.

An idempotent HTTP method is an HTTP method that can be called many times without different outcomes. It would not matter if the method is called only once, or ten times over. The result should be the same.

Idempotency with HTTP Methods

If you follow REST principles in designing API, you will have automatically idempotent REST APIs for GET, PUT, DELETE, HEAD, OPTIONS and TRACE HTTP methods. Only POST APIs will not be idempotent.

Post#136-API#5 HTTP Methods

 ðŸ‘‡

Before we start scripting with Rest Assured Lets understand what are these methods GET, POST, PUT, PATCH , DELETE etc.

GET

GET requests are the most common and widely used methods in APIs and websites. Simply put, the GET method is used to retrieve data from a server at the specified resource. For example, say you have an API with a /users endpoint. Making a GET request to that endpoint should return a list of all available users.

Idempotent REST APIs

In the context of REST APIs, when making multiple identical requests has the same effect as making a single request – then that REST API is called idempotent.

An idempotent HTTP method is an HTTP method that can be called many times without different outcomes. It would not matter if the method is called only once, or ten times over. The result should be the same.

Post#135-API#4 Rest assured Introduction and set up

👇 

What is Rest assured?

Rest assured is java library for testing Restful Web services. It can be used to test XML & JSON based web services. It supports GET, POST, PUT, PATCH, DELETE, OPTIONS and HEAD requests and can be used to validate and verify the response of these requests. Also it can be integrated with testing frameworks like JUnit, TestNG etc.

Prerequisites: Java, IDE (Eclipse, IntelliJ, etc), Maven & TestNG

The benefits of REST Assured

There are three main aspects of REST Assured that make it a powerful library for API testing:

Post#134-API#3 API v/s Web Service

 API v/s Web Service

Web services facilitate communication between two web parties in compliance with communication standards and protocols like Extensible Markup Language (XML), Simple Object Access protocol (SOAP), Web Services Description Language (WSDL) and Universal Description, Discovery and Integration) UDDI and all of these collectively known as Web Services. API and Web service serve as a means of communication. The only difference is that a Web service facilitates interaction between two machines over a network. An API acts as an interface between two different applications so that they can communicate with each other. An API is a method by which the third-party vendors can write programs that interface easily with other programs. A Web service is designed to have an interface that is depicted in a machine- executable format usually specified in Web Service Description Language (WSDL- generally is an API). Typically, “HTTP” is the most commonly used protocol for communication. Web service also uses SOAP, REST, and XML-RPC as a means of communication. API may use any means of communication to initiate interaction between applications. For example, the system calls are invoked using interrupts by the Linux kernel API.

Post#133-API#2 API Testing Types

 ðŸ‘‡

Validation Testing

Validation testing occurs among the final steps and plays an essential role in the development process. It verifies the aspects of product, behavior, and efficiency. In other words, validation testing can be seen as an assurance of the correct development.

Functional testing

Includes testing particular functions in the codebase. These features are the representation of specific scenarios to make sure the API functions are handled well within the planned parameters.

Friday, August 20, 2021

Post#132-API#1 Introduction to API Testing

 

👇

Application Program Interface (API): Is the way of communication between two applications where applications may differ in their platforms or in terms of technology also.

Diagrammatically Representing And Understanding What Exactly API’s Are:


Wednesday, April 29, 2020

Post#131.How to find broken or invalid images on a web-page using WebDriver? Part 1


How to find broken or invalid images on a webpage using WebDriver? Part 1

There are several ways to accomplish this. Let's discuss one of the easiest available ways. I will keep update the other solutions regard to the same in my next posts..

Solution Statement:

To check if an image is broken, you can simply check if the naturalWidth of the element is 0. You would loop through the images on the page and do this check for each. As for doing this across an entire site, you would have to build a crawler or ideally find an existing one and that's out of scope for a question on SO.

Saturday, April 25, 2020

Post#130.How to handle 'Time out receiving message from the renderer' in chrome driver?


How to handle 'Time out receiving message from the renderer' in chrome driver?


Problem Statement: While executing selenium test cases you may encountered with below repetitive error message .

[1587832910.221][SEVERE]: Timed out receiving message from renderer: 0.100

Saturday, September 28, 2019

Post#129.Dependency Test in TestNG


Dependency Test in TestNG:
Sometimes, you may need to invoke methods in a Test case in a particular order or you want to share some data and state between methods. This kind of dependency is supported by TestNG as it supports the declaration of explicit dependencies between test methods.

Post#128.Data driven Testing using TestNG


TestNG Data Providers
Data Provider feature helps you to write data-driven tests, which essentially means that same test method can be run multiple times with different data-sets. It helps in providing complex parameters to the test methods as it is not possible to do this from testng.xml file.
Please note that @DataProvider is the second way of passing parameters to test methods (first way we already discussed in @Parameters example).

Post#127.Parallel Execution of test In multiple browsers using testNG


Parallel Execution of test In multiple browsers using testNG
Selenium WebDriver does not have any feature which will allow us to perform parallel execution in multiple browsers. So with the help of TestNG we can perform parallel execution in selenium. 
This can be done by using @parameters annotation.

Post#126.Parallel Execution of test methods in TestNG


Parallel Execution of test methods in TestNG

TestNG provides multiple ways to execute tests in separate threads. In testng.xml, if we set 'parallel' attribute on the tag to 'tests', testNG will run all the ‘@Test’ methods in tag in the same thread, but each tag will be in a separate thread.
If we want to run methods/classes in separate threads, we need to set 'parallel' attribute on the tag to 'methods' / 'classes'

Post#125.Exception Test in TestNG


TestNG – Expected Exception and Expected Message 

While writing unit tests there can be certain scenarios where we need to verify that an exception is being thrown by the program during execution or not. TestNG provides a feature to test such scenarios by allowing the user to specify the type of exceptions that are expected to be thrown by a test method during execution.

Post#124.Optional annotation in TestNG

Optional annotation in TestNG

As we know, we can pass parameter values to the test methods during run time from testng.xml file by specifying Parameters annotation to test method.
To do this, we need to declare parameters tag in xml file using 'name' and 'value' attribute. Where the name attribute of the tag defines name of the parameter and the value attribute defines the value of the parameter.

Post#123.TestNG Assertions


TestNG Assertions:
While using Selenium for automated testing of web applications, we need to add validations in our tests to report them as pass or fail. And assertions can let us do that within a single line of code. Here, you’ll learn how to use TestNG assertions and know the different methods to assert conditions.
Assertions give you a way, other than If-Else blocks, to test conditions. They are not only easy to use but also eliminate the chances of making any error in forming test conditions. Hence, it’s always beneficial to use them in Selenium WebDriver projects.

Post#122.Groups in TestNG

TestNG – Test Groups, Meta Group, Default Group 
Grouping test methods is one of the most important features of TestNG. In TestNG users can group multiple test methods into a named group. You can also execute a particular set of test methods belonging to a group or multiple groups. This feature allows the test methods to be segregated into different sections or modules. For example, you can have a set of tests that belong to sanity test where as others may belong to regression tests. You can also segregate the tests based on the functionalities/features that the test method verifies. This helps in executing only a particular set of tests as and when required.

Post#121.Class level annotations in TestNG


Class level annotations in TestNG
TestNG has the feature to define annotations on a class instead of each test method.
Let’s say there are 20 test methods, where adding @Test on a class level is simpler than adding @Test for each method.

When we make class level @Test annotation, all the public methods of this class will become test methods even if they are not annotated.