REST API testing using Rest Assured

In this REST API testing using Rest Assured post, You will learn what is API and API testing, what is the little difference between SOAP and REST services, and how to test REST APIs using Rest Assured Library.


Rest API Testing using Rest Assured with Examples


What is API?


API full form is Application Programming Interface. It comprises of a set of functions that can be accessed and executed by another software systems. It is an interface between different systems and establishes interaction with systems and data exchange process.

What is API Testing?


In the modern development world, many web applications are designed based on three-tier architecture model. Those are:

1) Presentation Tier – Occupies the top level and displays information related to services available on a website ,User Interface (UI)
2) Application Tier – Also called Middle Tier or Logic Tier ,Business logic is written in this tier which is pulled from Presentation tier. It is also called Business Tier. (API)
3) Data Tier – Here information about database and data is stored and retrieved from a Database. (DB)

REST vs SOAP

REST (Representational State Transfer)


REST is an architectural style that uses simple HTTP calls for inter-machine communication. REST does not contain an additional messaging layer and focuses on design rules for creating stateless services. A client can access the resource using the unique URI and a representation of the resource is returned. With each new resource representation, the client is said to transfer state. While accessing RESTful resources with HTTP protocol, the URL of the resource serves as the resource identifier and GET, PUT, DELETE, POST and HEAD are the standard HTTP operations to be performed on that resource.

SOAP (Simple Object Access Protocol)


SOAP relies heavily on XML, and together with schema, defines a very strongly typed messaging framework. Every operation the service provides is explicitly defined, along with the XML structure of the request and response for that operation. Each input parameter is similarly defined and bound to a type: for example, an integer, a string, or some other complex object. All of this is codified in the WSDL – Web Service Description (or Definition, in later versions) Language. The WSDL is often explained as a contract between the provider and the consumer of the service. SOAP uses different transport protocols, such as HTTP and SMTP. The standard protocol HTTP makes it easier for SOAP model to tunnel across firewalls and proxies without any modifications to the SOAP protocol.

Trending Posts:



REST API Testing Using Rest Assured

What is Rest Assured?

In order to test REST APIs, I found REST Assured library so useful. It is developed by JayWay Company and it is a really powerful catalyzer for automated testing of REST-services. REST-assured provides a lot of nice features, such as DSL-like syntax, XPath-Validation, Specification Reuse, easy file uploads and with those features we will handle automated API testing much easier.

Rest Assured has a gherkin type syntax which is shown in below code. If you are a fan of BDD (Behavior Driven Development).

Rest Assured Example:

public class RestAssured{

@Test
public void appRestTest() {
given()
.contentType(ContentType.JSON)
.pathParam("name", "suresh")
.when()
.get("/restapipath/{name}")
.then()
.statusCode(200)
.body("firstName", equalTo("Suresh"))
.body("Lastname", equalTo("Narayana"));
}
}

Also, we can get JSON response as a string and send it to the JsonPath class and we can use its methods to write flexible structured tests.

public class RestAssured{

@Test
public void appJsonPathTest() {
Response res = get("/RestAPiservice/customer");
assertEquals(200, res.getStatusCode());
String json = res.asString();
JsonPath jp = new JsonPath(json);
assertEquals("rajesh@gmail.com, jp.get("email"));
assertEquals("suresh", jp.get("firstName"));
assertEquals("Narayana", jp.get("LastName"));
}
}


Sikuli Guide For Beginners – Integrate Sikuli With Selenium Webdriver

Sikuli Guide For Beginners – Integrate Sikuli With Selenium Web driver,In this present article, you will learn Sikuli Graphical User Interface Automation Tool in-detail and how to integrate Sikuli tool with Selenium webdriver.

Sikuli Guide for Beginners - Integrate Sikuli with Selenium WebDriver



What is Sikuli Tool:

Sikuli is a Graphical User Interface open source Automation Tool. Using Sikuli Automation tool you could automate whatever we see on the computer screen. It is basically uses image recognition
technology to identify and control GUI elements on desktop. you all know that using Selenium can't automate windows/desktop objects. Integrating Sikuli with Selenium allows us to
overcome this issue. Using Sikuli tool with Selenium webdriver, we could automate windows/desktop objects,Sikuli can automate both Web and Windows based applications.
Most of testers are using Auto-IT tool to upload or download files in Selenium scripting but using Sikuli we can do it very easily.


Advantages of Sikuli Tool:


It is an open source tool for automation.
Easily to integrate sikuli with selenium.
Can automate Desktop / Windows application.
Easily automate Flash objects – Flash Testing.
It can be used on any platform such as Windows/Linux/Mac/Mobile.

Sample program to login to Remote Desktop:


public void normalTest() throws FindFailed {
ImagePath.setBundlePath("D:/Practicle/SikuliProject/src/test/resources/images/");

Screen s = new Screen();
s.type("r",Key.WIN);
System.out.println("Run window is open");
s.type("mstsc");
System.out.println("Run window entered mstsc");
s.click("ok.png");
System.out.println("Click on OK button");
s.wait("remote.png");
System.out.println("Wait for Remote desktop window appers");
s.type("ipaddress");
System.out.println("Remote Desktop entered ipaddress");
s.click("connect.png");
System.out.println("Remote Desktop clicks Connect button");
s.exists("windowsSecurity.png");
s.type("passsword");
System.out.println("Entered password in Windows Security");
s.wait("wok.png");
s.click("wok.png");
System.out.println("OK button is pressed in Windows Security");
s.exists("remoteWind.png");

}

}

How to send extent reports in email with screenshots

How to send extent reports in email with screenshots,While working with Extent Reports,we are able to take the screenshots ,able to attach into Extent html Reports,but while sending those reports in email screenshots not displays.

I've figured how to display screenshots in Extent Reports,if html file location is changed from one folder to another folder with the simple trick as per Extent Reports site directions.

How to send extent reports in email with screenshots