• Jeff Fillegar
  • Posts
  • How to work with Lists from the Salesforce API using Tosca?

How to work with Lists from the Salesforce API using Tosca?

What are the testing requirements?

  • Reuse the SFDC Get Auth Token ReusableTestStepBlock

  • Pass the token to the Request Test Step of the GetRecentLeads SFDC API

  • Validate the SFDC API Response is valid – 200 OK

  • Search for a specific lead where Product Interest field == “Credit Card”

  • Work with Static and Dynamic Lists to Verify and buffer the lead data

Salesforce API Response we will be validating

Tosca - Salesforce SOQL Automated Test Case

We will be building the following automated test case:

GetMostRecentLeads_SOQL_LAST_N_DAYS_30

There are a couple of different ways to design and configure your Tosca test case depending on if you are working with Static or Dynamic Lists.

Below are 2 screen shots for the Tosca Test Step to handle both List types.

First one is changing the ActionMode to Verify on the Item Array Node and selecting Verify on the ProductInterest__c field.  The second screen shot uses the ActionMode Constraint.  Both yield same result.  The difference is in if the lists are dynamic or static.

Select Verify at the Parent Item Array Node

tosca-api-list-verify-item-array-node

Select Constraint to filter the item list data

SFDC API Get Auth Token

I am using a Reusable Test Step Block that returns a token from Salesforce’s Auth Token Service.  In Tosca, I will buffer that token value and pass it to any subsequent Tosca API Request test step.  The token value will be passed in the header of the Request.  To learn how to build the SFDC API Get Auth Token automated test case, check out my blog post on that topic here.

Salesforce SOQL used in this test case

Buffers Explained:

NumOfDays:  7

SOQL:  query?q=SELECT CreatedDate, Id, LastName, FirstName, Email, LeadSource, Status, ProductInterest__c FROM Lead WHERE CreatedDate = LAST_N_DAYS:{B[NumOfDays]}Translated Value of SOQL:query?q=SELECT CreatedDate, Id, LastName, FirstName, Email, LeadSource, Status, ProductInterest__c FROM Lead WHERE CreatedDate = LAST_N_DAYS:7

Tosca Test Configuration Parameters Used

WebserviceEngineLogRequestResponse: True

WebserviceEngineLogRequestResponse=true

I add this TCP to all of my Tosca API test cases. When the test case is executed, the raw  request and raw response are each saved as a text file to the directory that is defined by the setting Request/Response log directory. By default the directory is as follows:  %APPDATA%\Tricentis\Tosca Testsuite\7.0.0\logs\Automation\WSE

The time of sending or receiving, the HTTP header and the content of the message are displayed in the text file.  The file name consists of the following:<yyyyMMdd_hhmmssfff>_<Request|Response>.txt

Complete List of Tosca Test Configuration Parameters

To narrow down the search, replace Select with Verify

Using Index or Notations at the Item Array node level, results in Tosca throwing an error that 5 duplicate items were found.  

Now replace the ActionMode = Verify at the Item node level, and Tosca searches all 5 Item array nodes and finds the one where Product_Interest = ‘Credit Card’  

In the below screen shot, we can see that our test case is passing based on our test design requirements.  Additionally, I have highlighted the Details column.  This is where you can see the raw Request and raw Response file paths.

Conclusion

In this post, I demonstrated 3 automated test case design techniques using Tosca. 

  1.  Get a SFDC Token

  2. Build a dynamic Salesforce SOQL

  3. Validate the list of most recent leads in the API response using two different approaches to handle dynamic and static lists.

And always remember this:

Stop writing code to test code!  Use Tricentis Tosca to build enterprise grade automated test cases.

Tosca Subset Available for Download

You can download the Tosca subset from my git repo that contains the Tosca modules and test cases used in this post.  Just remember to populate the SFDC Get Auth Token test case with your credentials.  The TCPs in the subset will be blank.

Cheers!