Using SoapUI with Selenium for Web Service Testing

โšก Smart Summary

SoapUI with Selenium lets one suite check a web service and the browser that consumes it. Groovy is the bridge, because SoapUI runs Groovy natively and Groovy reaches every Java library Selenium ships.

  • ๐Ÿ”˜ Two tools, two layers: SoapUI exercises the SOAP or REST endpoint, while Selenium WebDriver drives the browser that calls it.
  • โ˜‘๏ธ Groovy is the glue: SoapUI supports Groovy extensively, and Groovy carries the whole Java library set, so Selenium code runs unchanged.
  • โœ… Runner class: SoapUITestCaseRunner opens a project file, selects a test suite and test case, and executes it from Java.
  • ๐Ÿงช Dynamic data: setProjectProperties() passes values such as city and zip code at run time instead of from a static property file.
  • ๐Ÿ› ๏ธ Prerequisites: The Groovy SDK, a JDK, Selenium and SoapUI must all be installed before the first run.
  • ๐Ÿ“Š Evidence trail: Every action is written to soapui.log in the bin folder of the installation directory.

Using SoapUI with Selenium for web service testing through Groovy

SoapUI is the most popular open source functional testing tool for API testing. It provides complete test coverage and supports all standard protocols and technologies.

What is SOAP?

SOAP is a simple XML-based protocol. It allows applications to exchange information over HTTP. It uses the Web Services Description Language (WSDL) for communication, and other applications can interact with web services through that WSDL interface.

SOAP vs REST Web Services in SoapUI

SoapUI began as a SOAP client, and its name still says so, but it tests REST endpoints too. Knowing which style you are pointing at decides how the test is built.

Aspect SOAP REST
Contract A WSDL file describes every operation, so SoapUI can generate requests automatically. Usually an OpenAPI or Swagger definition, or no formal contract at all.
Message format XML envelope only. Commonly JSON, though XML and other formats are allowed.
Transport Most often HTTP, but SOAP is transport-independent. HTTP, with the method and URL carrying the intent.
Assertions in SoapUI XPath and XQuery match against the response envelope. JSONPath and script assertions match against the payload.
Typical use Banking, telecom and other contract-heavy enterprise integrations. Public and mobile-facing services where payloads stay light.

The walkthrough below uses a SOAP weather service, but the same runner class drives a REST test case without any change to the Java code.

What is SOAPUI?

SOAPUI is an open source cross-platform web service testing tool. The SOAPUI-Pro edition has extra functionality for companies dealing with critical web services. Web services play a significant role in internet applications.

โš ๏ธ Product-name note: SmartBear discontinued SoapUI Pro as a standalone product and merged it, along with LoadUI Pro and ServiceV Pro, into ReadyAPI. The free edition keeps the SoapUI name and is still actively released. The steps below work in either, and existing SoapUI projects open in ReadyAPI.

What is Selenium?

Selenium is not one program but a family of tools for driving a browser the way a person would. Two members matter here:

  • Selenium โ€” a test tool that automates browsers across many platforms.
  • Selenium WebDriver โ€” it makes direct calls to the browsers, using each browserโ€™s native support for automation.

Why Combine SoapUI and Selenium in One Test

Checking the service and checking the screen are usually two separate jobs handled by two separate suites, which is why a defect in the seam between them tends to survive both. Running them together closes that gap.

  • Prove the round trip. A booking submitted in the browser should appear in the service response. Only a combined test can assert both halves.
  • Set up state quickly. Creating a customer through the API takes a second; creating one through twelve form fields takes a minute and fails more often.
  • Localise a failure. When the UI shows the wrong total, the API assertion in the same run tells you immediately whether the service or the page is at fault.
  • Reuse one data set. The zip-code and city pairs in the example below feed the service call and could equally feed the browser assertions.
  • Cut duplicate coverage. Validation rules already proven at the service layer do not need a slow browser test each.

The trade-off is a heavier test: two tools, two sets of dependencies and a longer run. Keep combined tests for the handful of journeys that genuinely cross the boundary, and leave the rest as pure API or pure browser checks.

Selenium with SoapUI

The simplest and easiest way to integrate Selenium with SoapUI is to use Groovy, which SoapUI supports extensively.

Groovy is an object-oriented scripting language that includes all the Java libraries, so every Java keyword and function can be used in a Groovy script directly. It runs on the JVM (Java Virtual Machine), which is what allows a Groovy step inside SoapUI and a Java Selenium test to share the same classes.

Pre-requisites for using Selenium with SoapUI

Install the following before writing any code:

โš ๏ธ Version note: Groovy 5.0 is the current stable release and requires JDK 11 or later, so install the JDK first and let the Groovy version follow it. Selenium is added to a Java project as a Maven or Gradle dependency rather than as a downloaded folder, and the SoapUI jar has to sit on the same classpath as your test โ€” that single point is where most first attempts fail.

Call the SoapUI Testcase runner in Selenium

The code below calls a SoapUI test case. It sets the properties for a city and its corresponding zip code, and when it executes it retrieves the value of each city and zip code, then reports the failure count for every pair that does not match. This code runs in Selenium.

Note: usePropertyFileFlag=true is used here instead of a static property file for storing the zip code and city. The zip code and city are passed at run time dynamically by the setProjectProperties() method.

Instructions to run the code:

  1. Start up SoapUI.
  2. Start a new test case.
  3. Add a new Groovy step.
  4. Copy and paste the sample code into the step.
  5. Click on Play.
  6. You can see Firefox starting up and navigating to Google. After that, you can see the SoapUI log entries.
  7. The code runs using JUnit.

Code Example

@when("<I use the weather service to get the weather information")						
    public void i_use_the_weather_service_to_get_the_information() {
        Set<Entry<String, string>> set = zipAndCities.entrySet();
        while (iterator,hasNext)) {
            Entry<String, String> entry = iterator.next();
            String zipCode = entry.getkey();
            String city = entry.getValue();
            String[] prop = {"usePropertyFileFlag=true","zipCode=" +zipCode, "city=" +city};									
            
            try{
                SoapUITestCaseRunner soapUITestCaseRunner = new	SoapUITestCaseRunner();
                soapUITestCaseRunner.setProjectFile("src/test/resources/WeatherSoapTest-soapui-project.xml");					
                soapUITestCaseRunner.setProjectProperties(prop);
                soapUITestCaseRunner.setTestSuite("TestSuite1");
                soapUITestCaseRunner.setTestCase("TestCase1");
                soapUITestCaseRunner.run();
                
            } catch (Exception e) {
                System.err.println("checking" + zipCode + " failed!");
                failureCount++;
                zipCodes.append(zipCode + " [" + city +"] ");
                e.printStackTrace();
            }finally{					
                totalCount++;
            }
}
}
}

โš ๏ธ Code note: this snippet is reproduced exactly as published and is a fragment rather than a compilable class. Before it will build you have to declare the iterator obtained from set.iterator(), correct while (iterator,hasNext)) to while (iterator.hasNext()) and entry.getkey() to entry.getKey(), capitalise the annotation as @When, remove the stray character at the start of the step text, and use String rather than string in the Set declaration. The original text is kept so the published example stays intact.

The console view lets you glance at all the test cases executed. You will find a list of the zip codes and cities fetched and passed into SoapUI Test Case 1.

View SoapUI Log file

Log files record every action that occurs in an operating system or software application. To view the SoapUI log file, go to the main directory, where you will see a file named soapui.log.

SoapUI installation directory listing with the soapui.log file visible

In SoapUI, the log file is located in the bin folder inside the installation directory, for example C:\Program Files\SmartBear\soapUI-Pro-4.0.1\bin. On a current install the version folder differs, and a ReadyAPI installation writes to its own bin folder instead.

bin folder of the SoapUI installation directory where the log file is stored

When you open this log file by clicking on it, it will look similar to the screenshot below.

Contents of the soapui.log file showing the logged test run entries

Where SoapUI and Selenium Integration Commonly Breaks

Almost every failure at this point is a wiring problem rather than a test problem. These are the ones to check first.

Symptom Likely cause What to check
NoClassDefFoundError or ClassNotFoundException on SoapUITestCaseRunner The SoapUI jar is not on the test classpath. Add the SoapUI dependency to the build file, or point the classpath at the jar in the SoapUI lib folder. A missing jar surfaces as an ordinary Selenium exception in the console.
The project file cannot be found setProjectFile() resolves a relative path against the working directory, which differs between an IDE and a build tool. Run from the project root, or pass an absolute path.
Test suite or test case not found The names in setTestSuite() and setTestCase() must match the project exactly. Copy the names straight out of the SoapUI project tree; they are case-sensitive.
The property never reaches the request setProjectProperties() ran after run(), or the request does not reference the property. Set every property before run(), and use the property placeholder syntax inside the request.
The browser does not start The driver and the installed browser are different major versions. Let Selenium Manager resolve the driver, or match the driver to the browser build.
A feature works in the IDE but not from the runner The step relies on a Pro-only feature such as a data source. Confirm the licence, or rebuild the step with open-source equivalents.

Once the runner exits cleanly and soapui.log shows the expected entries, the integration is working and can be folded into a wider automation testing suite.

FAQs

The open-source edition runs Groovy steps and exposes the test-case runner, so the integration itself needs no licence. Pro or ReadyAPI features such as data sources and the data-driven wizard are the parts that will fail without one.

Yes, and it is the mirror image of this walkthrough. A Groovy step can instantiate a WebDriver directly, provided the Selenium jars are placed in the SoapUI lib folder so the script can resolve them.

SoapUI executes Groovy natively in a script step, with no compile cycle, and Groovy reaches every Java class already on the classpath. Plain Java needs a build step, which is why Groovy wins for short integration code.

Wrap it as a JUnit or TestNG test and let Maven or Gradle invoke it, exactly as the example does. On the agent the browser must run headless, and the SoapUI project file has to be committed alongside the test code.

Assistants are useful for expanding a small set of city and zip-code pairs into wider coverage, and for spotting response fields no assertion touches. Generated values still need a real check, because a plausible zip code is not a valid one.

It is, within limits. Copilot handles Groovy syntax and common Java calls well, but it has little knowledge of the SoapUI scripting objects such as testRunner, context and log, so those suggestions need close review.

Store them as environment variables or in a secrets manager and read them into project properties at run time, the same mechanism setProjectProperties() uses here. A committed project file with a plain-text password is a leak waiting to happen.

Keep protocol-level checks โ€” status, schema, XPath on the envelope โ€” inside SoapUI, where the tooling is built for them. Assert in the Selenium test only what the browser itself must show, so a failure points at one layer.

Summarize this post with: