A common requirement for writing UI tests is the ability to switch to a specific user before interacting with the page or verifying that a field or button is visible.
In Gearset Automated Testing, you are able to switch to a specific user, profile or permission set when executing a test.
Switching user, profile or permission set in your UI test
To switch to a different login in your UI test, you will first need to configure the Login Access Policies on your Salesforce Org, then ensure your connection user has the correct permissions. You can then select a user, profile or permission set when starting to build a test or in the add step dropdown.
Configuring Login Access Policies on your Salesforce Org
You will need to ensure that the Administrators Can Log in as Any User setting is enabled in your Salesforce Org's Login Access Policies. You can access this in your Salesforce Setup menu.
Salesforce has a guide to Control Login Access Policies in their help center.
Adding the Correct Permissions to Your Connection User
In addition to requiring the Administrators Can Log in as Any User setting to be enabled on your Salesforce org, the Salesforce user of the connection you are using will need the following permissions:
Modify All DataCustomize ApplicationManage Users
Switching login when creating a test
When you open the test builder, the setup wizard will show you which user you are logged in as. If you would like to switch login, click the Edit button.
Clicking the Edit button will show the Switch login modal. Select the type of login, then what you would like to login as from the dropdown.
Logging in as the current connection will not switch user. If you subsequently run the test using a different connection, the test will be executed using this different user.
Click Save to close the modal, then Next in the setup wizard. The login will then be switched, which should be reflected with a banner at the top of the Salesforce window.
Switching login in an existing test
It is also possible to switch login in the middle of a test by using the add step dropdown.
Click on the dropdown arrow next to the Record screen button, then click Switch login.
This will show the Switch login modal. Select the type of login, then what you would like to login as from the dropdown.
Clicking Add step will create the new login step and automatically execute it to switch to the new user. This should be reflected with a banner at the top of the Salesforce window.
Frequently Asked Questions
Which users can I log in as?
You can log into any user as long as is an active, standard user. Community users are not currently supported.
What profiles or permission sets are shown?
Profiles and permission sets will only be shown if there is a user Gearset can login as with the corresponding profile/permission set.
When the step is executed, Gearset will search for any user that has this attribute and return an error if one does not exist.
How does this work across different Salesforce Orgs?
For profile and permission sets, Gearset will try to search for any user in the Salesforce Org that has this attribute. If one does not exist, the step will fail.
For users, Gearset will try to match the user from its username. If a user with that exact username does not exist, Gearset will try to match a user by comparing the base username without any sandbox suffix. For example:
joe.bloggs@gearset.com.uat,joe.bloggs@gearset.com.stagingandjoe.bloggs@gearset.comwould all match as they have the same base username ofjoe.bloggs@gearset.com.joe.bloggs@gearset.comandjoe.bloggs+staging@gearset.comwould not match as they have different base usernames.
How many times can I switch login?
You can create an unlimited number of switch login steps within your test.
Do I need the Login Access Policy and permissions if I don't need to switch login?
No, the Login Access Policy and user permissions are only required if you need to switch login in a UI test. If all your tests can solely be executed as the connection's user, these steps can be ignored.








