I have encountered rather strange behaviour. First some background: I am using batch file to run SoapUI testrunner on a set of projects, calling them like this (the parameters are name of tested web service, name of testing environment, type of soapui runner, endpoint base url and directory for output of results):
for /D %%a in ("\TestRequests\soap\*") do (
call ..\..\Run\runSoapUITest.bat %%~nxa environ test http://test.endpoint.com ../outputDir/
)
for /D %%a in ("\TestRequests\rest\*") do (
call ..\..\Run\runSoapUITest.bat %%~nxa environ test http://test.endpoint.com ../outputDir/
)
The "\TestRequests\soap" contains subdirectories (one for each web service tested), each containing xmls with test requests. The called runSoapUITest.bat looks like this:
set WSname=%1
set environementName=%2
set runner=%3
set endpoint=%4%
set output=%5%
...
"%SOAPUI_FOR_TEST_DIR%\bin\%runner%runner.bat" -sAutoTest -r -a -j -I -Pendpoint=%endpoint% -Penvironement=%environementName% -PoutputDir=%output% "%current_dir%\..\resources\TestProjects-Auto\%WSname%-soapui-project.xml"
As you can see, there are three project-level custom properties called endpoint, environment and outputDir. Each of the called projects contain one testsuite named AutoTest with one testCase named Test with three test steps:
Groovy script that calls script from my library that goes over the xml files in \TestRequests\soap[WSname] directory and feeds them to step 2. This script also loads the project properties to know where to find the test Request xmls and where to output the result. This script is universal across all soap web service projects and very similar script is used for the one rest service project that I use. The main difference is the rest version explicitly fills query parameters that it reads from json file. This is done using external library, so this steps looks like this:
import wstests.RunTests
def RT = new RunTests(context: context, log: log)
RT.Cycle()
testRunner.gotoStep(2)
for the soap projects, and like this for the rest project:
import wstests.RunTests
def RT = new RunTests(context: context, log: log)
RT.CycleRest()
testRunner.gotoStep(2)
- Request test step - basically empty shell which is filled by the script in step 1.
- Ending.
So, the problem is, when running the soap web service version, everything works. But when I run the rest web service version I encounter exception: java.lang.NullPointerException: Cannot get property 'testCase' on null object at line highlighted below:
def CycleRest() {
--> def environement = testRunner.testCase.testSuite.project.getPropertyValue( "environement" )
def endP = testRunner.testCase.testSuite.project.getPropertyValue( "endpoint" )
def outRoot = testRunner.testCase.testSuite.project.getPropertyValue( "outputDir" )
def projectName= testRunner.testCase.testSuite.project.getName();
context.projectName = projectName
...
The strange thing is, this opening part of the script is exactly the same for the soap projects, which work fine:
def Cycle() {
def projectDir = context.expand('${projectDir}');
def environement = context.testCase.testSuite.project.getPropertyValue( "environement" )
def endP = context.testCase.testSuite.project.getPropertyValue( "endpoint" )
def outRoot = context.testCase.testSuite.project.getPropertyValue( "outputDir" )
def projectName= context.testCase.testSuite.project.getName();
context.projectName = projectName
...
Is there any reason why soap projects (based on WSDL) should behave differently than rest project (based on WADL)?
Some remarks: This happens only when I run the script using my library. If I paste the script directly in the Groovy test step, it works. It seems like there is problem with setting the project parameters in the batch file runSoapUITest.bat, but the call is just the same with rest as with soap. I must be overlooking something, I just cannot find what.
Thanks in advance.
CodePudding user response:
OK, upon close inspection I found the key difference - although you can run
def environement = testRunner.testCase.testSuite.project.getPropertyValue( "environement" )
from inside the SoapUI client, when running solely by testrunner, the testRunner is missing. You have to exchange that for context - which can even be seen from my snippet of the working code.
When I replaced all instances of 'testRunner' with 'context', it worked as intended. You learn every day I guess. Even things you apparently already knew, but forgot.