Using restassured to call API behind proxy

In most of the organisations we have proxies and while using restassured we face “java.net.ConnectException: Connection timed out” or “java.net.ConnectException: Connection refused” error as proxy does not allows the traffic. To resolve same we need to set the proxy settings before making the call. To do the same there are two methods – either use System.setProperty or use io.restassured.specification . While using System.setProprty again there are two ways. One is just use system proxy System.setProperty (“java.net.useSystemProxies”, “true”); Or set all properties manually as below // The hostname, or address, of the proxy server used by the HTTP protocol handler. System.setProperty(“http.proxyHost”, “myproxy.domain.com”); // The port number of the proxy server used by the HTTP protocol handler. System.setProperty(“http.proxyPort”, “8080”); // The hostname, or address, of the proxy server used by the HTTPS protocol handler. System.setProperty(“https.proxyHost”, “myproxy.domain.com”); // The port number of the proxy server used by the HTTPS protocol handler. System.setProperty(“https.proxyPort”, “443”);… Read more“Using restassured to call API behind proxy”

The import io.restassured.RestAssured cannot be resolved

While consuming restassured maven dependencies it has been observed that even after downloading the dependencies eclipse is not able to resolve io.restassured package. Maven repository (https://mvnrepository.com/artifact/io.rest-assured/rest-assured) has the scope set to test in the dependency tag. This limits your code from accessing that dependency’s classes within your source code. That is, you can access those classes only within your test sources (ex: ${project.dir}/src/test/java/, ${project.dir}/test/. Mostly that is not the intended use case, so just remove the scope attribute. <!– https://mvnrepository.com/artifact/io.rest-assured/rest-assured –> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>4.3.2</version> <!– <scope>test</scope> –> </dependency>

TestNG by default disables loading DTD from unsecure Urls

While executing TestNG sometime we hit below error: org.testng.TestNGException: TestNG by default disables loading DTD from unsecure Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true] at org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:102) This can be sol;ved using 3 ways. 1. First and ideal way is to use https url in TestNGXML.It should be like: Very first and ideal way is to use https URL in TestNG.xml file. <!DOCTYPE suite SYSTEM “https://testng.org/testng-1.0.dtd”>instead of <!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”> Second way is to update Run Configuration and add VM argument -ea -Dtestng.dtd.http=true: 3. Third way is to update the eclipse TestNG Preferences

Write to local file system using a postman collection

There are situations when you want to write the API response on local file system. So here I am explaining how to do that. Basically there are two ways to do it. One is by using node js scrip and another way to start a local server which accepts postman requests. Here I am explaining first method only. Ensure that you have node and npm installed. Install newman with: npm install newman. Create a file with the following contents: Here is another example:

Newman – Command line integration with Postman

To run the test from command line window, Postman has newly npm Package (Newman). Here quick steps to start with newman: Install latest version of Node (Node.js) in the computer. Download the Windows installer from the js® web site. To see if NPM is installed, type npm -v in command prompt. In case npm is already installed and want to update (To run Newman, ensure that you have NodeJS >= v4) run following command from cmd: npm install -g npm-windows-upgrade Set the path of Node Bin Folder (ex: C:\Program Files\nodejs\node_modules\npm\bin) in the Computer path Variable. Open the cmd and type following command “npm install -g newman”. It will install Newman in the PC. Postman provides a feature to download the collection as JSON Data. Download the collection from the Postman Open the command window in the downloaded path of collection and type following Command “newman run GetBalanceService.json -r html” Observe… Read more“Newman – Command line integration with Postman”

Postman Collections and organizing test using collections

A Postman Collection allow you to group together several APIs that might be related or perhaps should be executed in a certain sequence. You can organize these requests in folders as well. Basically collections server 4 purposes: Organization of tests, Documentation, Test Suit creation, and designing conditional workflows.  How to create collection Collections can be created by following two processes. One, while saving any request it shows option to create collection and/or folders. As per need one can created and organization those. Another way to create collection by using sidebar New Collection button or New Button at toolbar. While creating the collection it shows option to select authorization type, any pre-request script, any variable or any test script. Features of Collection Postman allows drag and drop feature to reorder and organize requests and folders. By using sub folders levels can be created and description can be added while will reflect… Read more“Postman Collections and organizing test using collections”

Writing Tests in Postman

Using postman we also can write test cases or build request using java script code. This code can use dynamic parameters, variables, or pass data between different requests. It allows us to write javascript code at two events: Before request sent to server, we call it Pre-request script and can be written in Pre-request Script After response is received from request, we call it test script. It lies under Test Script Script can be written at Collection, Folder or request level so questions comes what will be order of execution. To understand that let’s see this picture: Here I am describing test cases using newer PM API (pm.* API). Though Postman still supports old postman API but we should use newer one so that in case postman deprecate old API we don’t need to invest in maintenance. In previous article I already covered logging options in Postman which can be… Read more“Writing Tests in Postman”

API Testing with Postman

These days all new web applications are being developed using service based architecture. There are many tools for API testing like SOAP UI, Parasoft SOAtest and Postman. Postman is available as a native app for Mac, Windows, and Linux operating systems. In this tutorial, we’re going to walk through the different features that Postman provides and how we can organize them to make our API testing less painful. In comparison of other tools in the market, it is very lightweight and fast. Requests can be organised in groups, also tests can be created with verifications for certain conditions on the response. With its features it is very good and convenient API tool. It is possible to make different kinds of HTTP requests – GET, POST, PUT, PATCH and DELETE. It is possible to add headers in the requests. Installation To install Postman, go to the apps page and click Download… Read more“API Testing with Postman”

Automation advantages in Agile? Why automation is needed in Agile?

Now a day’s, agile development and testing are growing broadly and smart QA/Testing team always keep themselves with current trends and technology. Automation is a critical component to maintain agility. Continuous integration/builds, unit, functional & integration test execution and automated deployment are common examples of applying automation. While working in SCRUM/XP, you’re splitting up your work into iterations and one of the conditions here is that by the end of each iteration code needs to have production-like quality and it needs to be ready to be put in production. This means that if you’re working on a project that requires 4 sprints, the second sprint needs to be built on top of the first one, the third on top of the second one and at any given time by the end of each sprint you should be ready to put your code into production. You need to continuously and repetitively… Read more“Automation advantages in Agile? Why automation is needed in Agile?”