Thursday, 3 May 2012

Functional Testing and Loop Request

To archive such needs use test soapUI capabilities.

In that project there’s included a test case that can be configured to insert n users defined in a properties file.

The script will then create n user joining n to user id (i.e. j.doe23).

To be able to execute this step perform  the following steps:

1.       Edit service endpoint
2.       Expand testsuite existant inside testcase SoapUI project
3.       Expand Test Steps
4.       Double-Click CreateUserProperties
5.       Change the properties according to your needs and saves to the selected properties target file
6.       Double-clicktest-case
7.       Select Run this Test Case (Green play button on left top corner of click test-case)

NOTE: To implement WSSecurity Header on request please change CreateUserRequest test step on test-case.

Groovy code snipped to perform a loop request

// run ten random requests
log.info("In the BC2 Create User Setup Script")

def userIdInStep = testRunner.testCase.getTestStepByName( "CreateUserProperties" )
def firstName = userIdInStep.getPropertyValue( "FirstName" )
def lastName = userIdInStep.getPropertyValue( "LastName" )
def userId = userIdInStep.getPropertyValue( "userId" )
def nTests = userIdInStep.getPropertyValue( "UsersToCreate" )

log.info("Number total of tests: " + nTests)
log.info("Company Mkey: " + nTests)
log.info("Company Address MKey: " + nTests)

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

for( i in 1..nTests.toInteger())
{
  def holder = groovyUtils.getXmlHolder( "CreateUserRequest#Request" )
  holder.setNodeValue( "//urn:userId", userId + i)
  holder.setNodeValue( "//urn:lastName", lastName + i)
  
  testRunner.runTestStepByName("CreateUserRequest")
  
  node = holder.getNodeValue("//urn:userId")
  log.info ("Created user: " + node)
  node = holder.getNodeValue("//urn:lastName")
  log.info ("Created user last name: " + node)
}

To use properties directely on request xml

...
               <urn:firstName>${Properties#FirstName}</urn:firstName>
               <urn:lastName>lastName</urn:lastName>
               <urn:language>en</urn:language>
...

No comments:

Post a Comment