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.
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:
- Start up SoapUI.
- Start a new test case.
- Add a new Groovy step.
- Copy and paste the sample code into the step.
- Click on Play.
- You can see Firefox starting up and navigating to Google. After that, you can see the SoapUI log entries.
- 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.
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.
When you open this log file by clicking on it, it will look similar to the screenshot below.
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.



