Skip to main content

Salesforce testing

Note:

This integration provides assistance for certain user-specific use cases, but it is not officially supported. Compatibility with all user requirements is not guaranteed.

This tutorial illustrates how Katalon Studio facilitates the automation of Salesforce applications, covering test cases for lead, case, and account management. Additionally, the dashboard management test cases include an example involving an iframe.

Use cases for Salesforce testing

Use CaseActions
Lead managementLog in - Create a new lead - Change status - Change owner - Search and delete a lead - Close application
Case managementLog in - Create a new case - Edit and change status - Search and delete by ID - Close application
Account managementLog in - Create an account - Close application
Dashboard managementLog in - Create a dashboard - Add components and reports - Create filter - Delete dashboard - Close application

Handling MFA and SSO within Salesforce orgs

Prerequisites

  • Access rights to create a Connected App within Salesforce.
  • Appropriate permissions and profiles to configure and use the Connected App.

Steps

  1. Create a Salesforce app.

    1. Make sure you enable the OAuth settings and add the required OAuth scopes as shown in the screenshot below:

      Create a Salesforce app
    2. To use the connected app in Salesforce, make sure you are added either via permission sets or you are assigned to the correct user profile to the connected app.

    3. Use the connected app to retrieve a refresh token which will be used to generate an access token during runtime, login to Salesforce, and perform test automation.

  2. Connect to connected app using Katalon Studio.

    1. Open a new or existing project in Katalon Studio.

    2. Create a new web service request of type - REST and name it as Retrieve Authorization code to access bearer token and refresh token. You can name the request as per your choice as well. This request will be used to retrieve the Authorization Code from Salesforce for our next steps.

    3. Enter the following below:

      Connect connected app using Katalon Studio
    4. Run this request using the test request button.

    5. Navigate to the header tab and copy the URL received under Location:

      Copy the connect app URL
    6. Paste the copied URL in the address field of your browser and follow the login instructions.

      Login to Salesforce
    7. Once logged in, the generated callback code is displayed in the address bar. The callback code is the value after the code. For example, the callback code in https://login.salesforce.com/services/oauth2/callbackcode=aPrxsdssXvusdaaJ4hOFlX4ZHYQMhdjsi9HOTTTw6mQZ%3D%3D is aPrxsdssXvusdaaJ4hOFlX4ZHYQMhdjsi9HOTTTw6mQZ%3D%3D.

      Get callback code
    8. Decode the retrieved code using any online URL Encode/Decoder.

    9. Create a new web service request in Katalon Studio and name it Retrieve Bearer Token and Refresh Token for the first time using Authorization code.

    10. Enter the following below:

      • Base URL: https://login.salesforce.com/services/oauth2/token.
      • HTTP Body: x-www-form-urlencoded
        • grant_type: authorization code
        • code: The code you decoded in the previous step.
        • client_id: Consumer key from your connected app.
        • client_secret: Consumer secret from connected app.
      • redirect_uri: As defined in the connected app during the setup.
      Retrieve Bearer Token and Refresh Token for the first time using Authorization code
    11. Run this request and retrieve the refresh token from the response. This refresh token will be used to generate the access token during runtime, which will allow users to log into Salesforce without the need to revalidate credentials via MFA or SSO.

    12. Create a new web service request in Katalon Studio and name it Retrieve Bearer Token using Refresh Token.

    13. Enter the following below:

      • Base URL: https://login.salesforce.com/services/oauth2/token.
      • HTTP Body: x-www-form-urlencoded
        • Authorization: Basic
        • client_id: Consumer key from connected app.
        • Client_secret: Consumer secret from connected app.
        • Grant_type: refresh_token
        • refresh_token: Retrieved from the response of the previous request.
      Retrieve Bearer Token using Refresh Token
    14. Run this request and retrieve the access token. Start by pasting this address in a new browser: https://kataloninc-dev-ed.develop.my.salesforce.com/secur/frontdoor.jsp?sid='accessToken'&retURL=, and then you will successfully log in to your Salesforce instance by passing MFA and SSO.

  3. Use this access token as part of your Katalon Studio test case.

    1. Create a new test case.

    2. Use the web service keyword Send Request and select the Retrieve Bearer Token using Refresh Token API requests under the Object column. Then, double-click on the Output column and add an output variable to store the response retrieve during runtime. You can do this by switching to Script mode in Katalon Studio as well.

    3. Add another test step to parse the response received and retrieve the Access Token and store it in a variable.

    4. Create another variable to create the Salesforce login URL (ex. sfURL) using this access token and the URL format.

    5. Add the Open Browser keyword in your test case and pass the sfURL to the keyword.

    6. Save the test case and run it.

    Manual view:

    Salesforce MFA SSO test case manual view

    Script view:

    Salesforce MFA SSO test case script view
Notes
  • With this method, we can log into Salesforce in a robust manner while adhering to both SSO and MFA. In this method, the Retrieve Authorization code to access bearer token and refresh token and Retrieve Bearer Token and Refresh Token for the first time using Authorization code requests need to be run manually from Katalon Studio and will only need to be ran when the refresh token is revoked.
  • Whenever the refresh token is revoked, you need to run the first two requests and update the refresh token in Retrieve Bearer Token using Refresh Token.The test case itself doesn’t need to be changed.

Automate Salesforce test cases

  1. Go to Project > Settings > Test Design > Web UI and change the priority of Xpath Locators.
    change Xpath Locators priority in Katalon Studio project settings
  2. Add Desired Capability to handle Popup (Show Notification). See Manage Desired Capabilities in Katalon Studio.
  3. Record test script via Katalon Recorder and save test objects and test cases. See Record Web utility in Katalon Studio.
  4. Update the application URL, username, and password inside the Default profile.Update URL, username, password in Default profile
  5. Run the test execution. You can refer to Execute tests with Katalon Studio overview.
  6. Verify the test execution result. You can refer to View test runs and execution logs.
If the test execution fails because of "Element not interactable" exception, you can change the keyword Click to Enhanced Click.KS enhanced click
Was this page helpful?