如何用Groovy脚本运行soapUI免费版(5.4.0)的指定负载测试
Got it, let's break down exactly how to run your two load tests (LoadOne and LoadTwo) from a standalone Groovy script. I've done this plenty of times with soapUI Free, so here's a reliable step-by-step solution:
Prerequisite: Set Up Classpath
First, your Groovy script needs access to soapUI's core libraries. When running the script, you'll need to include all the JAR files from your soapUI installation's lib directory in the classpath. For example, if soapUI is installed at C:/Program Files/SmartBear/soapUI-5.4.0, the lib folder there has everything you need.
The Groovy Script
Create a new .groovy file (e.g., run-load-tests.groovy) with the following code. Be sure to adjust the project path and test case details to match your setup:
// Update this path to point to your soapUI project file def projectPath = "C:/path/to/your/your-project-soapui-project.xml" // Optional: If your load tests belong to a specific test case, define its name here def targetTestCaseName = "your-test-case-name" // Replace with your test case name (e.g., the one with steps one/two) // Load the soapUI project def project = new com.eviware.soapui.impl.wsdl.WsdlProject(projectPath) // List of load tests you want to run def loadTestsToRun = ["LoadOne", "LoadTwo"] // Iterate through each load test and execute it loadTestsToRun.each { loadTestName -> def loadTest // If your load tests are under a specific test case (most common scenario) if (targetTestCaseName) { def testCase = project.getTestCaseByName(targetTestCaseName) if (!testCase) { println "Error: Test case '${targetTestCaseName}' not found in the project!" return } loadTest = testCase.getLoadTestByName(loadTestName) } else { // Fallback: Search the entire project for the load test (use if load tests are top-level, rare) loadTest = project.getLoadTestByName(loadTestName) } if (loadTest) { println "=== Starting Load Test: ${loadTestName} ===" // Create a runner and start the load test def runner = loadTest.run(new com.eviware.soapui.support.types.StringToObjectMap(), false) // Optional: Wait for the load test to finish and print progress updates while (runner.isRunning()) { Thread.sleep(1000) println "${loadTestName} is running... Elapsed time: ${runner.getElapsedTime()}ms | Total runs: ${runner.getRunCount()}" } // Print final results println "=== Load Test ${loadTestName} Completed ===" println "Status: ${runner.getStatus()}" println "Total Executions: ${runner.getRunCount()}" println "Failures: ${runner.getFailureCount()}" println "Average Response Time: ${runner.getAverageTime()}ms\n" } else { println "Warning: Load test '${loadTestName}' not found! Skipping.\n" } } // Clean up: Release the project resources project.release()
How to Run the Script
Open a command prompt/terminal and execute the script with the Groovy command, specifying the classpath to soapUI's lib folder:
On Windows:
groovy -cp "C:/Program Files/SmartBear/soapUI-5.4.0/lib/*" run-load-tests.groovy
On Linux/macOS:
groovy -cp "/Applications/soapUI-5.4.0/lib/*" run-load-tests.groovy
Key Notes
- Path Adjustments: Double-check all file paths (project path, soapUI lib path) match your system's structure. On Windows, use either escaped backslashes (
\\) or forward slashes (/) in paths. - Test Case Scope: If your load tests are tied to a specific test case (which they almost certainly are, since you mentioned test steps one/two), make sure to set
targetTestCaseNamecorrectly. This avoids conflicts if multiple test cases have load tests with the same name. - Wait for Completion: The
while (runner.isRunning())loop is optional but helpful if you want the script to block until each load test finishes. Remove it if you want to start both load tests in parallel. - soapUI Free Limitations: soapUI Free doesn't support some advanced load test features, but basic execution like this works perfectly.
内容的提问来源于stack exchange,提问作者Dmitry

