Selenium Salesforce load Testing

Performing Load Testing in Salesforce using Selenium and TestNG

When we build any custom solution in Salesforce, key is to write an efficient and meaningful Apex test classes for sure. However sometime we may need to test how custom application would behave in maximum operating capacity. Here, I am talking about Load Testing of custom applications built on top of platform. Recently I needed to push my code to its limit to know how many concurrent users can use it before hitting any governor limits. Quickly I realize that its time to call my friends Selenium and TestNG.

Before doing any extensive stress or load testing on Salesforce, we must need to contact Salesforce support and explain them what we are trying to achieve. More detail available in this official Salesforce blog post.

I have published some blog posts about Selenium in past as well however whats different this time ? I need to determine after how many simultaneous user interactions, I would hit Concurrent Apex Limit error as shown in below image.

Salesforce Governor Limit error - Concurrent Apex Limit
Salesforce Governor Limit error – Concurrent Apex Limit

How to perform Parallel execution of browsers in Selenium

I needed to launch around 20 instances of browsers with unique session Ids to see how my long running Apex code will behave.

If you need quick tour, visit this repository for complete source code, jars and browser drivers. You can check this Youtube video as well to see how it works.

Key to solution is using Threadpool to instantiate drivers and using @Test annotation of TestNG framework.

Below sample Java class shows how to use Threadpool to instantiate selenium driver.

Open multiple browsers in Selenium using TestNG to perform Parallel Testing

@Test(invocationCount = 20,threadPoolSize = 20) annotation is used in class to open 20 chrome browsers using Selenium. This annotation is part of TestNG framework.

How to take screenshots of Fail Test cases using TestNG in Selenium

Once all test suites completes execution, we need a proof on why test execution failed. What would be better than automated screenshots being taken by TestNG framework? takeScreenShotOnFailure() method in class takes screen shot of failure test cases.

Hope this blog post will help you to some extend. Please don’t forget to leave a feedback.





Related Posts


2 responses to “Performing Load Testing in Salesforce using Selenium and TestNG”

  1. Venkata Sabbella Avatar
    Venkata Sabbella

    Hey Jitendra, Can I try this without contacting salesforce

  2. Mudit Avatar

    Hi Jitendra,
    Could you please suggest if selenium could be used to automate testing for managed package tasks as well? We have a managed package installed on sf and it has a loan origination flow which we need to automate. is it possible using selenium or any other tool?


Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading