REST/SOAPUI based Web Services Testing in Selenium WebDriver

We came very far in our Selenium WebDriver learning journey and it’s very hard to find that we have left any topic untouched. Still, if I missed anything, then you can suggest them through our communication channels. Well, today we are going to discuss Rest and SoapUI based Web Services Testing using Selenium WebDriver. This article has its uniqueness as we are suggesting a different way to perform Web services testing with Selenium scripts; but, above all, I would like to clear your fundamentals of Web Services, SOAPUI & REST.

Suggested Readings: How to create and use Firefox profiles in Selenium WebDriver?

What is Web Service?

A Web Service is a way to establish communication between two data sources over world wide web (WWW), irrespective of their architecture, technology, and behavior. The exchange of information takes place through XML or JSON files.

What is the protocol used in Web services?

Generally, the exchanges of information take place over HTTP or HTTPS protocol at the application layer between two computers. One computer sends the request and other responds with XML or JSON data.

Here there are no dependencies on OS, application or the programming languages. One application which is built on .Net language may request data from another application which is built on Java. All the data transfer would take place either in XML or JSON format.

Web services testing

Features of Web Services

Some of the features of web services are listed below:

  • Services will be available on the internet, intranet, VPN or cloud
  • It is platform independent services and OS and programming independent as well
  • This basically uses standard XML message
  • This service is triggered with simple URL available over the internet

What are the components of Web services?

The basics of the following components are XML data parsing and communication using HTTP or HTTPS protocol.

  1. SOAP (Simple Object Access Protocol)
  2. WSDL (Web Services Description Language)
  3. UDDI (Universal Description, Discovery, and Integration)
  4. REST (Representational State Transfer)

A glimpse on Web Services Testing

We perform web services testing in different ways either through manual or automation. We will discuss all the aspects of the theoretical part separately. Let’s stick to today’s agenda. Before that, let’s have a quick look at the process that we follow to perform web services testing. We will follow the same process through automation as well. Followings are the test steps:

  1. Understanding the file definition of WSDL
  2. Getting operations performed by different web services
  3. Determination of XML message which we need to send through SOAP
  4. Determining received XML message through SOAP
  5. A tool or program which is used to send and received an XML message

Click here to get Open Source Project code

SOAPUI

Pre-Requisites to integrate SOAPUI based Web services testing with Selenium

Your Automation framework should be ready with following pre-requisites to perform web services testing with Selenium WebDriver

  1. SOAP tool (Click here to download)
  2. SOAPUI Jar file (Click here to download)
  3. WSDL4J Jar file (Click here to download)

After downloading these JAR files, extract them and Import inside the build path of your Selenium project.

SOAPUI Validation

                SoapUITestCaseRunner soapuitest = new SoapUITestCaseRunner();
		soapuitest.setProjectFile("C:\\Users\\blogg\\Documents\\REST-Project-1-soapui-project.xml");
		soapuitest.getLog();
		soapuitest.setTestSuite("TestSuite1");
                soapuitest.setTestCase("TestCase1");
                soapuitest.getDomain();
		System.out.println(soapuitest.getLog());
		System.out.println(soapuitest.getProjectFile());
		soapuitest.run();

WSDL Validation

                WsdlProject project = new WsdlProject();
		WsdlInterface[] wsdlInterfaceArry = WsdlImporter.importWsdl(project, "URL of WSDL");
	        WsdlInterface wsdlFirst = wsdlInterfaceArry[0];
	        for (Operation ops : wsdlFirst.getOperationList()) {
	        WsdlOperation wsdlOperation = (WsdlOperation) ops;
	        System.out.println("OP:"+wsdlOperation.getName());
	        System.out.println("Request:" +wsdlOperation.createRequest(true));
	        System.out.println("Response:"+wsdlOperation.createResponse(true));
	    }

Sample Program

package Test;

import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;
import com.eviware.soapui.tools.SoapUITestCaseRunner;

public class SoapUISelenium {

	public static void main(String[] args) throws Exception {
		
		//SOAPUI Validation
		SoapUITestCaseRunner soapui = new SoapUITestCaseRunner();
		soapui.setProjectFile("C:\\Users\\blogg\\Documents\\REST-Project-1-soapui-project.xml");
		soapui.getLog();
		soapui.setTestSuite("TestSuite1");
                soapui.setTestCase("TestCase1");
                soapui.getDomain();
		System.out.println(soapui.getLog());
		System.out.println(soapui.getProjectFile());
		soapui.run();
		
		//WSDL Validation
		WsdlProject project = new WsdlProject();
		WsdlInterface[] wsdlInterfaceArry = WsdlImporter.importWsdl(project, "URL of WSDL");
	        WsdlInterface wsdlFirst = wsdlInterfaceArry[0];
	        for (Operation ops : wsdlFirst.getOperationList()) {
	        WsdlOperation wsdlOperation = (WsdlOperation) ops;
	        System.out.println("OP:"+wsdlOperation.getName());
	        System.out.println("Request:" +wsdlOperation.createRequest(true));
	        System.out.println("Response:" +wsdlOperation.createResponse(true));
	    }
	
	}

}

This was all about Web services testing in Selenium WebDriver. Send your queries in any doubts. Don’t miss to join us on social media.

Join Inviul fb group

One Response

Leave a Reply