Salesforce Load Testing using SOAPUI

API Load Testing using SOAPUI

Previously, I have added multiple posts in this blog on how you would face governor limit errors on each step of Salesforce implementation and how we can leverage selenium to perform load testing of Salesforce to some extent.

SOAP UI is powerful tool and in this post we will see how it can be used to perform load testing of Salesforce API.

Step 1 : Download PartnerWSDL from your Salesforce instance and create SOAP UI Project.

Step 2 : Create a Test Suite in SOAP UI

Step 3 : Create a Groovy script to generate random Account Name

def generator = { String alphabet, int n ->
  new Random().with {
    (1..n).collect { alphabet[ nextInt( alphabet.length() ) ] }.join()
  }
}

def accName = generator( (('A'..'Z')+('0'..'9')).join(), 9 )
testRunner.testCase.getTestStepByName("AccParameter"). setPropertyValue("AccountName",accName)

def accNumber = testRunner.testCase. getPropertyValue("AccountNumber")

Step 4 : Create a Login request in SOAP UI using Partner WSDL, sample request looks like

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
   <soapenv:Header>
      <urn:CallOptions>
         <urn:client>?</urn:client> 
      </urn:CallOptions>
      <urn:LoginScopeHeader> 
         <!--Optional:--> 
      </urn:LoginScopeHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>SFUsername</urn:username>
         <urn:password>SFPassword</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

Step 5 : Create property step to create two parameter as shown in below

Step 6 : Create Step with property transfer. In this step, we would read Salesforce session Id returned by Login API and pass it to create Account API. To compute X-Path, we can use xmlGrid website.

XPath to read Session of Salesforce

/*:Envelope/*:Body/*:loginResponse/*:result/*:sessionId

X-Path to pass Session Id in Create request

/*:Envelope/*:Header/*:SessionHeader/*:sessionId

Step 7 : In this step we would insert Account using SessionId transferred from previous parameter transfer step

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com" xmlns:xsi="xsi">
   <soapenv:Header>
      <urn:PackageVersionHeader/>
      <urn:LocaleOptions/>
     <urn:MruHeader>
      </urn:MruHeader>
      <urn:SessionHeader>
         <urn:sessionId>Salesforce Session Id</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
      	<urn:sObjects xsi:type="urn1:Account" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      		<Name>${AccParameter#AccountName}</Name>
      		<AccountNumber>${AccParameter#AccountNumber}</AccountNumber>
      		<TextField__c>InsertedViaSoapUI</TextField__c>
      	</urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

In this step, you might get this error “Destination URL not reset. The URL returned from login must be set in the SforceService“. To resolve this, change URL of request in SOAP UI address bar. Shown in 30 Min Video below

Step 8 : Final step is to create a Groovy script to auto increment Account Number

def accNumber = testRunner.testCase.getTestStepByName("AccParameter"). getPropertyValue("AccountNumber").toInteger() 
accNumber = accNumber + 1 

testRunner.testCase.getTestStepByName("AccParameter"). setPropertyValue("AccountNumber", accNumber.toString()) 
log.info(accNumber)

Related posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.