Building a Salesforce Test Framework with RPA in Robot Framework

 
 
 

It was a challenge trying to find a Salesforce library that I could use inside Robot Framework with the PyCharm IDE. I was interested in finding a library that would provide a starting point to enable REST API interfaces with Salesforce.  I finally found one buried inside http://PYPI.ORG. The framework is RPA and is supported by Robocorp. To download the library into PyCharm, use the pip command pip install rpaframework. At the time of this writing the latest release is 10.4.0.

The install is large because it contains many libraries that cover Salesforce, Excel, SAPGUI, Email, database, and other application support. For a complete list go to this web page: https://pypi.org/project/rpaframework/#libraries. If you are not familiar with the PYPI Organization, they provide a repository of software for the Python programming language. It also includes some libraries for Robot Framework.

The RPA Salesforce library is a compilation of open-source libraries and tools for Robotic Process Automation (RPA). It is designed to be used with both Robot Framework and Python. The aim is to offer well-documented and actively maintained libraries for Robot Framework development. From these libraries you can develop your own Salesforce REST API framework for testing purposes.

The following links provide much more detail than I am covering in this document.

After completing the PIP install, the libraries can be used in both Robot Framework and Python. I like this approach because sometimes it is better to create functions in Python that become keyword functions in Robot Framework.

My building block approach to developing Robot Framework scripts including the following.

  • What code is needed to access my instance of Salesforce?
  • What Salesforce operations are a good start for test code?
  • Do I need a RF resource file? If so, what should be in it?
  • Could the code support multiple Salesforce objects or just one?
  • Is it possible to code with Excel as the test driver?

The diagram below describes the framework I built using Robot Framework.

 

 

The Robot Framework solution is comprised of three components: a main script, a resource file, and a python script. The main script provides the library imports, Suite Setup and Teardown references, the data driver for controlling Excel input, and the REST API scenarios processing based on Salesforce operators.

There are two main conditional processes that determine what further functions will be engaged in the test script. One was just mentioned which regards checking the Salesforce operators. The other involves examining the Salesforce objects.

For those not familiar with Salesforce operators and objects. Let me mention here what they are, and the ones added into the main script for processing. The Salesforce operators are actions that can be applied to the Salesforce objects. The objects come in two flavors: standard and custom. My reference here is to standard objects. Common business objects like Account, Contact, Lead, and Opportunity are all standard objects. The common operators that can be applied to them are Get, Update, Create, Delete, Describe, and Query. For example, for an account I can apply each of the operators mentioned to obtain or manipulate an object record.

Salesforce has a very robust GUI interface that is great for its user community. However, this RPA Salesforce REST API interface provides a nice alternative to the need for Selenium. This approach bypasses the need for detecting GUI screen objects to functionally test Salesforce standard or custom functions. Instead, RPA.Salesforce supports REST API functions to get and manipulate object data without going through the presentation layer. Here is an example before I get into a live demonstration. This script begins with importing a library called RPA.Salesforce which provides some simple keywords to interact with Salesforce data objects. The script is using Excel to provide data input and DataDriver to drive the test case rows in Excel.

Salesforce requires user credentials to open a dialog. For each row in Excel a test case is processed. This main processing is identified in the keyword function called REST API SCENARIOS. A series of condition statements check one of the Excel spreadsheet columns to determine the action required on the test case. Before an action is taken the script does some setup requirements and the testing begins.

 

*** Settings ***
Library  RPA.Salesforce
Library  SeleniumLibrary
Library  ExcelLibrary
Library  DataDriver    .xlsx
Library  RPASalesforce.py
Resource  Resource.robot

Documentation    Salesforce Script for object data REST API Testing
#robot -d ARAPI\Results ARAPI\RPASalesforce.robot

Suite Setup  Open Salesforce and Launch Excel
Suite Teardown  Stop Excel
Test Template  REST API Scenarios

*** Variables ***

*** Test Cases ***
Test Case – ${testcase} – ${description}

*** Keywords ***
REST API Scenarios
    [Arguments]  ${sObject}  ${operators}  ${value1}  ${value2}  ${value3}
    Define Variables as Global  ${sObject}  ${operators}  ${value1}  ${value2}  ${value3}
    Setup Data  ${sObject}  ${operators}  ${value1}  ${value2}  ${value3}
    Run Keyword If  ‘${operators}’==’Create’  Create Object  ${sObject}  ${operators}  ${value1}  ${value2}  ${value3}
    Run Keyword If  ‘${operators}’==’Get’  Get Object  ${sObject}  ${operators}  ${value1}
    Run Keyword If  ‘${operators}’==’Update’  Update Object  ${sObject}  ${operators}  ${value1}  ${value2}
    Run Keyword If  ‘${operators}’==’Query’  Query Object  ${sObject}  ${operators}  ${value1}
    Run Keyword If  ‘${operators}’==’Describe’  Describe Object  ${sObject}

 

Let us move on to the demonstration and further discussion on what it takes to interact with Salesforce using the RPA solution available for Robot Framework.

 

For more detail watch the video here.