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:

How to use date and timestamp in postman

Many times we need to pass timestamp or date as request parameter. One way is to use predefined variable like {{$timestamp}}. But this can not be used when it’s needed in specific format. So to achieve that we should use ‘Pre-Request Script’ option. Use below code in pre request script. Here we are using moment class to get specific formats. Then use these environment variables as parameter like {{timestamp}} or {{date}} Another need could be to access the time in milliseconds. Add below code in ‘Pre-Request Script’ tab and in it can be accesses as variable.

Testing SOAP Services with WS-Security using SOAPUI

Web Services Security (WSS): SOAP Message Security is a set of enhancements to SOAP messaging that provides message integrity and confidentiality. WSS: SOAP Message Security is extensible, and can accommodate a variety of security models and encryption technologies. WSS: SOAP Message Security provides three main mechanisms that can be used independently or together: The ability to send security tokens as part of a message, and for associating the security tokens with message content The ability to protect the contents of a message from unauthorized and undetected modification (message integrity) The ability to protect the contents of a message from unauthorized disclosure (message confidentiality). WSS: SOAP Message Security can be used in conjunction with other web service extensions and application-specific protocols to satisfy a variety of security requirements. In this article we will learn how to use different authentication options in SOAP UI. I’ll be using examples from test project on… Read more“Testing SOAP Services with WS-Security using SOAPUI”

Error while decryption of SOAPUI response- “Error Getting Response :null”

In SOAPUI in many cases when we apply the wss keystore for decryption it hits error and shows message: “Error Getting Response :null”. But shows nothing in SOAPUI logs and blank output screen. When you remove Incoming WSS it shows the encrypted response. To solve this you can try below steps: Go to C:\Program Files\SmartBear\SoapUI-5.3.0\lib Rename wss4j-1.6.16.jar to wss4j-1.6.16.jar.old Copy wss4j-1.6.2.jar from same location for SoapUI 4.5 to this folder. You can down load wss4j jars from : http://central.maven.org/maven2/org/apache/ws/security/wss4j/1.6.2/wss4j-1.6.2.jar Some other jar versions also may work. You may still face issue with decryption then check the logs at: C:\Program Files\SmartBear\SoapUI-5.3.0\bin\soapui.log. In case it’s showing “org.apache.xml.security.encryption.XMLEncryptionException: Illegal key size” error that suggests that JCE error due few jar files are missing from installation. This issue can be resolved by installing the Oracle® Java JCE unlimited strength jars. These jars can be downloaded from the following links depending on which Java version you are… Read more“Error while decryption of SOAPUI response- “Error Getting Response :null””

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”

Analyzing http and https traffic using fiddler

Fiddler tool can be used for analyzing HTTP and HTTPS (must be enabled from within the fiddler tool) transactions. This tool is a simple to use and by following below tips you can capture and analyze the request and network traffic causing any performance issue. Also you can send the captured logs to support team to get these analyzed if needed. It enables us to inspect all HTTP traffic, set breakpoints, and dig through the incoming or outgoing data. Using fiddler we can check reason for performance bottleneck of a web page, which cookies are being sent to server or what downloaded content is marked as cacheable etc. Installation, Firstly you need to download and install the fiddler tool (https://www.telerik.com/download/fiddler/fiddler4 ) and follow the screen instructions to get this installed. Enabling the traffic for https Open Fiddler and from the top menu click on Tools -> Options and click on the HTTPS tab Check… Read more“Analyzing http and https traffic using fiddler”

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?”

Bug Life Cycle

Life cycle of Bug   Log new defect When tester logs any new bug the mandatory fields could be: Build version, Submit On, Product, Module, Severity, Synopsis and Description to Reproduce In above list you can add some optional fields if you are using manual Bug submission template: These Optional Fields are: Customer name, Browser, Operating system, File Attachments or screenshots. The following fields remain either specified or blank: If you have authority to add bug Status, Priority and ‘Assigned to’ fields them you can specify these fields. Otherwise Test manager will set status, Bug priority and assign the bug to respective module owner. Look at the following Bug life cycle: Ref: Bugzilla bug life cycle The figure is quite complicated but when you consider the significant steps in bug life cycle you will get quick idea of bug life. On successful logging the bug is reviewed by Development or Test manager. Test manager… Read more“Bug Life Cycle”

How to sign SOAP request in Jmeter

In this post we will see how to test a SOAP web service in JMeter. Using JMeter, we can do both functional testing as well as load testing of a SOAP web services. As we know that web services are headless so, we can’t use the record and playback feature of JMeter to record the web service requests. Hence, we need to create the Sampler requests manually. In this tutorial, we will use the “SOAP/XML-RPC Request” sampler to create and send the SOAP request. SOAP/XML-RPC Request The SOAP/XML-RPC Request sampler is used to send a SOAP or an XML-RPC request to a webservice. This sampler creates an HTTP POST request(as SOAP is based POST method) with the request body specified in the “SOAP/XML-RPC Data” field. We can specify the SOAPAction in the SOAPAction field after checking the Send SOAPActioncheckbox. Steps to test a SOAP Web service using JMeter- Add a Thread… Read more“How to sign SOAP request in Jmeter”

How to write to local file system using a postman collection java script

Ensure that you have node and npm installed. Install newman with: npm install newman. Create a file with the following contents: var fs = require(‘fs’), newman = require(‘newman’), results = []; newman.run({ reporters: ‘cli’, collection: ‘/path/to/collection.json’, environment: ‘/path/to/environment.json’ // This is not necessary }) .on(‘request’, function (err, args) { if (!err) { // here, args.response represents the entire response object var rawBody = args.response.stream, // this is a buffer body = rawBody.toString(); // stringified JSON results.push(JSON.parse(body)); // this is just to aggregate all responses into one object } }) // a second argument is also passed to this handler, if more details are needed. .on(‘done’, function (err, summary) { // write the details to any file of your choice. The format may vary depending on your use case fs.writeFileSync(‘migration-report.json’, JSON.stringify(results, null, 4)); }); Here is another example: var express = require(‘express’); var fs = require(‘fs’); var bodyParser = require(‘body-parser’); var app = express(); app.use(bodyParser.urlencoded({ extended:… Read more“How to write to local file system using a postman collection java script”