Skip to main content

Using Assertions in Automated Testing

How to verify that your automated test ran successfully

Written by Josh Heng

Assert steps can be used in your tests to verify that a step or process has worked as expected.

Creating Assert Steps

With the Recorder

Assert steps can be created with the recorder by clicking on the element in the page that you would like to assert. These can be edited afterwards if the automatically-generated description isn't specific enough or if you want to change what is being checked (e.g. checking that the element isn't there instead).

To create an assert step whilst recording, click on the 'Add assertion' button in the top right of the Salesforce Org preview.

To create an assert step when not recording, click the 'Add assertion' button at the bottom of the steps panel.

You can also create an assertion mid-way through a test by using the step creation dropdown.

With the AI Test Builder

You can also prompt the AI test builder to create an assertion step for you.

Continue On Fail

By default, assert steps are set to 'Stop on Fail'. This means that if the step is unsuccessful, the whole test will fail early and stop further execution.

Sometimes you want the test to continue even if the assertion fails - for example, checking multiple values on a page which are not dependent on each other. You can do this by editing an assert step to be 'Continue on Fail'. If the step fails, the test will still continue execution until it reaches the end or encounters a failing 'Stop on Fail' assert.

'Continue on Fail' steps allow you to see the result of multiple failing assert steps at once so you can fix them all in one pass. If a 'Continue on Fail' assertion fails, the overall test status still shows as failed.

Steps that are configured to continue on fail will be shown with an icon.


Frequently Asked Questions

How many assert steps can I create?

You can create unlimited assert steps in your test. We would recommend that each test contains at least one assert step, but that each test only tests a single process or flow.

If you have a large test that contains multiple Salesforce flows or processes, we'd recommend using reusable tests instead.

Can I assert multiple values at once?

Yes, just edit the assertion step to assert on all the values you need. This can be useful when asserting on elements such as multiple picklist values or variables which contain multiple items.

Should I create one large assert step or multiple smaller assert steps?

We would recommend that you create multiple assert steps which each test a single thing. This means that if the step fails, you will know exactly what went wrong.

Can I view/download a screenshot of assert step results?

Yes, the test results page will show a screenshot captured after every step, including asserts.

How do I scroll the page to assert a value?

During test execution, Gearset will attempt to scroll automatically to the element before asserting and taking a screenshot. There is no need to create a specific scroll step.

Can I use variables in my assert steps?

Yes, variables can be used in assert steps like in any other step. You can find more information in using variables in your UI tests.

By using test case variables, you can also assert different outcomes across test cases. For example, testing elements which can and cannot be seen by different permission sets.

How can I assert something which isn't visible?

There are two ways to do this:

  • You can record an assertion step in the normal way, and then edit the step to be negative. For example, changing "Assert that a case is visible" to "Assert that a case is not visible"

  • You can use our agent to make a ‘negative’ assertion, such as an element not being visible or empty. Simply prompt the agent. For example, “Assert that the ID field is empty” or “Assert that the Target field is not visible”.

It is also possible to use test case variables in order to dynamically assert if something by giving them a value of either 'visible' or 'not visible'.

Did this answer your question?