How to automate API using SoapUI
In this article, we will delve into the world of automating API testing with SoapUI, explicitly focusing on running tests from the command line. By the end of this guide, you will have a thorough understanding of how to set up and execute SoapUI tests in an automated and efficient manner.
Table of contents
- Why automate API testing?
- SoapUI overview
- Setting up your environment
- Configuring the TestRunner
- Automating API tests
- Best practices for automated API testing
- Migration from SoapUI to Postman
Why automate API testing?
Automated testing has become an essential part of the software development life cycle. It helps reduce manual testing efforts, find defects early in development, and ensure the software’s overall quality. Regarding API testing, SoapUI is a robust tool that simplifies the process. In this article, we’ll explore how to automate API testing with SoapUI, explicitly focusing on running tests from the command line.
Before diving into the technical details, let’s understand the importance of automating API testing.
Automated API testing helps ensure that your APIs work as expected, preventing bugs and issues from making their way into production.
Time and cost efficiency
Automated tests can be run as often as needed without incurring additional costs. This reduces the time required for manual testing, allowing faster development and releases.
Automated tests provide consistent and repeatable results, reducing human error and variability in testing.
Automated tests are invaluable for performing regression testing, ensuring that new code changes do not break existing functionality.
As your software grows, so do the required tests. Automation allows for scalable testing processes.
Before we dive into automation, let’s briefly introduce SoapUI.
SoapUI is a widely used open-source tool for testing web services and APIs. It offers a graphical user interface (GUI) for designing and running tests and a command-line interface for automation. SoapUI supports SOAP, REST, and other web service protocols and provides features for testing, mocking, and monitoring APIs.
Setting up your environment
To automate API testing using SoapUI, you need to set up your environment. This includes installing SoapUI and preparing your test projects.
You can download SoapUI from the official website. Install it according to your operating system. SoapUI is available in both free and paid versions. For basic automation, the free version is usually sufficient. You can refer to our article on SoapUI installation if you need detailed steps.
Preparing your test projects
Creating or importing test projects in SoapUI to automate tests would be best. A test project typically contains one or more test suites, each containing test cases. You can create these projects using the SoapUI GUI.
Create a Project: Open SoapUI, click File, and select New SoapUI Project. Follow the wizard to create your project.
Create Test Suites and Test Cases: You can create test suites and test cases within your project. Test cases contain individual API test steps.
Define Test Steps: Define the test steps for your test cases. These steps include making requests to APIs, verifying responses, and handling assertions.
For a detailed explanation, refer to our article on SoapUI Test Steps.
Configuring the TestRunner
To automate API testing using SoapUI, you must use the TestRunner tool. Below, you’ll find instructions on how to obtain and configure it effectively:
Obtaining the TestRunner
The TestRunner tool is typically bundled with your SoapUI installation. To access it, follow these steps:
Right-click on the desired Test Case within your SoapUI project.
Select Launch TestRunner. This action will open the TestRunner tool, which offers many configuration options.
It includes the following options:
- Basic: For fundamental test run settings, including the test suite, test case, and project password.
- Overrides: To adjust various test settings, including environments, endpoints, and credentials.
- Reports: For configuring report generation and exporting options.
- Properties: To manage global, system, and project properties.
- Custom Args: To pass custom arguments to your tests.
- Test Suite and Test Case: Specify the test suite and test case you intend to execute.
- Enable UI Components in UI Checkbox: This option turns UI components on or off during the test run.
- Test Runner Path: Specify the path to the TestRunner executable.
- Project Password: If your project is password-protected, enter the password here.
- User-Settings.xml Password: Define the password for user settings, if required.
- Launch Button: Click this button to initiate the test run.
- Environments: Configure test environment settings.
- End Point: Override the endpoint URL.
- Host Port: Specify a different host port if required.
- Username: Override the username for authentication.
- Password: Override the password for authentication.
- Domain: If applicable, specify the domain for authentication.
- WSS Password Types: Customize Web Service Security (WSS) password types.
- Print Report: Toggle this option to print the test report.
- Export JUnit Results: Enable this option to export JUnit results.
- Export JUnit Results with Test Properties: Export JUnit results and test properties.
- Export All: Export all available reports.
- Root Folder: Specify the destination folder for your reports.
- Global Properties: Configure global properties for your test run.
- System Properties: Define system-specific properties.
- Project Properties: Manage properties specific to your project.
Custom Args tab
- Tool Args: If you need to pass custom arguments to your tests, you can specify them here.
Mastering these TestRunner argument options allows you to customize your API test runs to suit your specific requirements. With your environment correctly configured and the TestRunner understood, you’re now well-prepared to move on to automating your API tests.
Automating API tests
In the context of automating API testing with SoapUI, the most critical phase begins after clicking the Launch button within the TestRunner tool. Once this action is taken, SoapUI’s TestRunner executes the test suite and test case, triggering events and validations.
Let’s delve into what transpires after initiating the test run:
The TestRunner tool executes the specified test suite and test case, running through the defined test steps. These steps typically include making requests to APIs, validating responses, and performing various assertions.
As the tests are executed, SoapUI collects data, including response times, status codes, and the outcomes of assertions. This data is crucial for analyzing the test results and identifying any issues or discrepancies.
SoapUI generates comprehensive test reports based on the test results. These reports often include details about which test steps passed or failed and any error messages or issues encountered during the test run.
The TestRunner can be configured to export results in the desired format, such as JUnit reports, PDFs, or HTML documents. These reports can be crucial for sharing test results with team members and stakeholders or for further analysis.
During the test run, SoapUI logs various events and activities, helping debug and troubleshoot any issues that might arise during testing. The level of logging can be adjusted based on your specific requirements.
Custom Args (if used)
If you’ve included custom arguments in your test configuration, they are applied during the test run, allowing you to pass additional parameters or options to your tests.
Overall, the TestRunner tool automates the execution of your API tests, making the process efficient, repeatable, and scalable. Once the tests are complete, the results and reports can be analyzed to identify any issues and ensure the reliability and quality of your APIs.
If your execution has failed, you will get an error pop-up, and you can see the error in the error log tab.
Best practices for automated API testing
Automated API testing can be a powerful asset, but it’s essential to follow best practices to maximize its effectiveness:
Test data management
- Data Isolation: Ensure that each test case operates on its own data set. Avoid shared data between tests, leading to unintended dependencies and failures.
- Data Cleanup: Implement data cleanup routines to remove any changes made during testing, returning the environment to a consistent state after each test run.
- Data Masking: When handling sensitive data, consider data masking techniques to protect privacy and comply with data security regulations.
Reporting and logging
- Customized Reports: Create customized test reports with meaningful, easy-to-understand visuals and descriptions to facilitate quicker issue identification and resolution.
- Log Levels: Utilize different log levels to categorize log messages, enabling you to filter and focus on specific aspects of test execution.
- Log Aggregation: Aggregate logs from multiple test runs and store them centrally for trend analysis and long-term performance monitoring.
- Alerting: Implement alerting mechanisms to receive immediate notifications when tests fail or API performance deviates from expected benchmarks.
- Thresholds and Baselines: Define performance thresholds and baselines to establish what constitutes normal behavior, making it easier to identify anomalies.
Test case modularity
- Reusable Functions: Create functions and libraries for common testing tasks, such as making HTTP requests or parsing JSON responses, and reuse them across multiple test cases.
- Maintenance Efficiency: Modularity simplifies test maintenance; if a change occurs, you only need to update a single function rather than modifying every test case.
- Data-Driven Testing: Embrace data-driven testing using different datasets to validate input scenarios. This approach expands test coverage without creating numerous individual test cases.
- Test Data Sources: Connect your test cases to various data sources, including databases, spreadsheets, or CSV files, to facilitate parameterization.
Automating API test migration from SoapUI to Postman
Indeed, you can export your API test cases from SoapUI and import them into other API testing tools like Postman. Here’s how you can export and import API test cases between SoapUI and Postman:
Exporting API test cases from SoapUI
Launch SoapUI and open the project containing the API test cases you want to export.
Select the test case
Choose the specific API test case you want to export from your project.
Export test case
In SoapUI, you can export a test case as a .xml file. To do this, right-click on the test case in the Navigator panel, select Export, and save it as an XML file.
Repeat for multiple test cases
If you have multiple test cases to export, you can repeat the process for each test case individually.
Importing API test cases into Postman
Launch Postman and ensure you have a workspace where you want to import the API test cases.
Create a New Collection
In Postman, you work with collections, which can be considered a group of API requests or test cases. If you don’t have a suitable collection, create a new one within your workspace.
Import API Test Case
- Click on the collection in Postman where you want to import the test case.
- Click the Import button.
- Choose Import from a file.
- Select the XML file you exported from SoapUI.
- Click Import.
Review and modify
After importing, you may need to review and modify the imported test case in Postman to align it with Postman’s structure and test flow. The structure of Postman collections and requests might differ from SoapUI, so some adjustments may be necessary.
Run the test case
Access the Collection Runner
To run the imported API test case, you must access the Collection Runner. You can click the Runner button in the toolbar at the top of the Postman window.
Select the Collection
You will see a list of available collections in the Collection Runner interface. To run your imported test case, choose the collection that contains the test case. You can click on the collection name or drag the respective collection to the Collection Order tab.
Configure Additional Settings
Postman’s Collection Runner provides various settings to fine-tune your test runs. These settings may include:
- Number of Iterations: Specify how often you want to run the collection.
- Delay Between Requests: Set a time delay in milliseconds to control the pace of your API requests.
- Data Files (if applicable): If your test case requires data files for different inputs or scenarios, you can select and configure them here.
Start the Run
After configuring the necessary settings, you can initiate the execution of your requests by clicking the Run button in the Collection Runner interface. Postman will execute the requests in your collection according to the specified settings.
Following these additional steps, you can effectively run the imported API test case in Postman using the Collection Runner and tailor the execution to your needs.
Final thoughts on automating API testing with SoapUI
Automating API testing with SoapUI and running tests from the command line can significantly enhance your software development process. Follow best practices, maintain your test data, and continuously monitor your APIs to maximize the benefits of automation. With the knowledge and tools discussed in this article, you can take your API testing to the next level and confidently deliver high-quality software.
Follow our blog
Be the first to know when we publish new content.
- Automated API testing in Postman
- Intro to API testing
- API mocking in SoapUI
- SoapUI load testing
- Groovy scripting in SoapUI