Skip links

How to Securely Log In to Salesforce in Automated Tests Without a Verification Code or MFA

Updated October 2026

This article was first published in August 2023 and updated in October 2026 to reflect Salesforce’s MFA enforcement for all UI logins, which reached production orgs between July and September 2026. The update also covers single-use frontdoor URLs in Salesforce CLI and the September 2025 restrictions on uninstalled connected apps. The new screen recordings show the full flow working in October 2026.

Automated tests are the most dependable way to confirm a Salesforce org still works after each deployment and release update. They only pay off when they run unattended, and in Salesforce UI testing, the login screen is usually where that falls apart first.

When someone logs in from a browser or device Salesforce doesn’t recognize, it asks them to verify their identity. A person does this once, and a cookie remembers the browser. Automated test runs usually start with a clean browser profile, so every run looks like a brand-new device, and the script ends up facing a verification code or MFA prompt it has no way to answer.

As QA Lead at ENWAY, I kept running into this on our own projects. The approach I settled on uses Salesforce CLI: you log in once with MFA, and every test after that opens the org through a single-use frontdoor URL. The test code never handles a password, and MFA stays switched on for every user.

Why MFA Matters Even More for Test Automation in 2026

Salesforce made MFA a contractual requirement on February 1, 2022. Between the Spring ’23 and Spring ’24 releases, it switched MFA on automatically for direct logins in existing production orgs, and since April 2024 it’s on by default for every new production org.

In 2026, Salesforce moved from defaults to enforcement. MFA enforcement for all employee UI logins reached sandboxes in July 2026 and rolled out to production orgs in release-group waves from July 20 to early September 2026. For QA teams, these are the changes that count:

  • Admins can no longer turn off the org setting that requires MFA for direct UI logins.
  • The Waive Multi-Factor Authentication for Exempt Users permission no longer exempts anyone automatically. An exemption for automated testing tools now has to be approved by Salesforce Support.
  • The login page now works in two steps (username first, then password or passkey), so scripts written for the old single-form login need to be rewritten.
  • Privileged users, such as System Administrators and users with Modify All Data or Author Apex, must use phishing-resistant MFA. If your test user has admin rights, that applies to it too.

Salesforce’s own enforcement guide states that test automations using UI logins may need to be updated. If your suite still types a username and password into the login page, it’s probably already failing.

Why the Usual Workarounds Fall Short

When I first searched forums for a fix, two tips kept coming up: add the test runner’s IP addresses to the trusted IP ranges, or disable MFA for the test user’s profile or the whole org.

Trusted IP ranges only skip the device verification step, and they need constant upkeep. Cloud CI runners change addresses all the time, so someone has to keep adding new ones to the list. And anyone who reaches the org from a listed address with the right credentials gets in without a second check.

Disabling MFA is no longer possible in orgs that have reached enforcement, and the exemption permission now goes through a Support case. Even where you can still get an exemption, a test user without MFA is a weak spot: its password sits in your CI configuration, and anyone who copies it can log in.

So I built a flow that keeps MFA on and never sends a password through the login page.

Salesforce QA

Did MFA Enforcement Break Your Salesforce Tests?

ENWAY’s QA team can move your UI tests to CLI-based login and set up safe storage for auth URLs in your CI pipeline, so test runs stop failing at the login screen.

Since 2016Salesforce consulting
150+projects delivered
5/5AppExchange rating

How the Solution Works

Salesforce has a technical page called frontdoor.jsp that starts a browser session for a user who’s already authenticated. It works for regular orgs and for Experience Cloud sites. Salesforce CLI relies on it every time you run sf org open: the CLI holds an OAuth refresh token for the org, gets a fresh access token, and turns it into a frontdoor URL that drops the browser straight into Lightning Experience.

Current Salesforce CLI versions return single-use frontdoor URLs with an otp parameter. You can spot one in the browser’s address bar in the test demo further down. Salesforce documents these single-access frontdoor URLs as valid for up to one minute and usable only once, which suits a test well: it generates a fresh link right before the browser opens it.

The test user completes MFA exactly once, when you authorize the org through the CLI in your own browser. After that, tests reuse the stored authorization, and no UI login ever happens. The only thing you need installed is Salesforce CLI.

Step 1: Authorize Your Org in Salesforce CLI

You only need to do this once. Run the command below in your terminal. It opens the Salesforce login page in your browser, where you enter the test user’s credentials and complete MFA as usual. The alias gives the org a short name that you’ll use in every later command.

sf org login web --alias myOrgForAutotests

If everything is correct, the terminal confirms the authorization:

Terminal output of sf org login web confirming that the Salesforce org was authorized successfully

Salesforce CLI confirms the org is authorized and saved under the myOrgForAutotests alias.

Now you can open the org without typing a username or password:

sf org open --target-org myOrgForAutotests

Watch sf org open Log In Without a Password

The CLI resolves the org’s domain and opens Setup in the browser, with no login page in between.

Recorded by ENWAY on macOS with Salesforce CLI and Chrome, October 2026. No sound.

How does it work? During the first login, Salesforce issues an access token and a refresh token, and the CLI saves them locally. If you go to your $HOME directory and open the .sfdx folder, you’ll find a JSON file for each authorized username.

If sf org login web fails with an OAuth approval error

Since September 2025, Salesforce blocks uninstalled connected apps for most users, and that includes the default connected app Salesforce CLI logs in with. Ask your admin to give the test user the Approve Uninstalled Connected Apps permission, or to install the connected app in the org. Also avoid sf org login device: the device flow no longer works with the default Salesforce CLI connected app.

Step 2: Export the SFDX Auth URL

A test that runs on another machine or a CI runner can’t open a browser to log in. The SFDX auth URL solves that. It packs the refresh token and the org’s address into one string that Salesforce CLI can authorize with, so you don’t need a JWT certificate or a browser step.

To get it, run the command below. The --json flag formats the output as JSON:

sf org auth show-sfdx-auth-url --target-org myOrgForAutotests --json

The URL sits in the sfdxAuthUrl property of the result object. The CLI prints a warning next to it, and it’s worth reading: this string works like a long-lived key to the org.

Terminal output of sf org auth show-sfdx-auth-url with the refresh token in the sfdxAuthUrl value redacted

The SFDX auth URL contains a refresh token. I’ve redacted mine here, and you should never share yours.

Instead of copying the value from the terminal, you can save it straight to a file by adding > ./authFile.json to the end of the command:

sf org auth show-sfdx-auth-url --target-org myOrgForAutotests --json > ./authFile.json

Add authFile.json to your .gitignore right away so it never ends up in the repository. To authorize the org on any machine with that file, run:

sf org login sfdx-url --sfdx-url-file ./authFile.json --alias myOrgForAutotests

The sf org login sfdx-url command accepts the JSON file produced above, a JSON file with a top-level sfdxAuthUrl property, or a plain text file that contains only the URL.

Step 3: Generate the Frontdoor URL Inside the Test

To get the frontdoor URL, use the command you already know with one extra flag, --url-only. It returns the URL without opening a browser:

sf org open --target-org myOrgForAutotests --url-only --json

The URL is in the url property of the result object. Hand it to your browser automation tool, and the test lands in the org already logged in. Since the link expires after a minute and works only once, generate it right before the browser needs it.

Full Example: A WebdriverIO Test in Node.js

Here’s a small hands-on test that puts the whole flow together. It’s built on WebdriverIO and uses the executive package to run CLI commands. The test authorizes the org from authFile.json, generates a frontdoor URL, and opens it in the browser. The clearLogs helper strips terminal color codes from the CLI output so it can be parsed as JSON.

import exec from 'executive'

describe('Open an org only with sfdx url', () => {
    it('open org', async () => {
        await exec.quiet(
            'sf org login sfdx-url --sfdx-url-file ./authFile.json --alias myOrgForAutotests'
        )

        let frontdoor = await exec.quiet(
            'sf org open --target-org myOrgForAutotests --url-only --json'
        )

        let url = (await clearLogs(frontdoor.stdout)).result.url

        await browser.url(url)
        await browser.pause(3000)
    })
})

export async function clearLogs(str) {
    let result = str
        .replace(/\x1B\[97m/g, '')
        .replace(/\x1B\[94m/g, '')
        .replace(/\x1B\[93m/g, '')
        .replace(/\x1B\[92m/g, '')
        .replace(/\x1B\[91m/g, '')
        .replace(/\x1B\[90m/g, '')
        .replace(/\x1B\[39m/g, '')
        .replace(/\x1B\[34m/g, '')
        .replace(/\x1B\[32m/g, '')

    return JSON.parse(result)
}

I run the spec with this command:

npx wdio wdio.conf.js --spec ./test/specs/test.e2e.js

Here’s the run from start to finish:

Watch the WebdriverIO Test Open the Org

The test opens a single-use frontdoor link, and Lightning Experience starts loading with no login screen or MFA prompt.

Recorded by ENWAY on macOS with WebdriverIO, Salesforce CLI and Chrome, October 27, 2026. No sound.

From this point on, the rest of your test runs in a normal logged-in session.

Running the Tests in CI

On a CI runner, there’s no reason to keep authFile.json on disk. Store the SFDX auth URL in a protected, masked CI/CD variable (in GitLab, that’s Settings > CI/CD > Variables) and pipe it into the CLI with the --sfdx-url-stdin flag:

echo "$SFDX_AUTH_URL" | sf org login sfdx-url --sfdx-url-stdin --alias myOrgForAutotests

If the pipeline authorizes the org in a step like this, you can remove the first exec.quiet call from the test and keep only the frontdoor step.

This flow is meant for UI tests. For API tests and system integrations, the OAuth JWT Bearer and Client Credentials flows are the standard choice, and Salesforce’s UI login MFA enforcement doesn’t affect them.

Security Considerations

Salesforce has strong security measures to protect user accounts and confidential data, and this approach keeps all of them in place. The SFDX auth URL holds a refresh token. Anyone who gets it can open the org as your test user until that token is revoked, and MFA won’t stop them, because the token was issued after MFA was already passed. Treat it with the same care as a production password.

  • Create a dedicated test user with only the permissions your tests need, and run UI tests against sandboxes or scratch orgs whenever you can.
  • Keep the URL in a secret store or a protected, masked CI/CD variable that only authorized people can read. GitLab CI/CD variables work well for this.
  • Never commit authFile.json or print the URL in test logs.
  • If the URL leaks, open the test user’s record in Setup and revoke the Salesforce CLI entry in the OAuth Connected Apps section. Then authorize again and export a new URL.

Frequently Asked Questions

Does this approach bypass Salesforce MFA?

No. The test user completes MFA once, when you authorize the org with sf org login web. Every later session comes from the OAuth refresh token issued after that login, which is how Salesforce CLI and other OAuth clients normally work. MFA stays enabled for the user and the org.

Can I still disable MFA for a test user?

Not in orgs that have reached Salesforce’s 2026 MFA enforcement. Admins can no longer turn off the MFA requirement for UI logins, and the Waive Multi-Factor Authentication for Exempt Users permission no longer exempts users automatically. An exemption for automated testing tools now needs approval from Salesforce Support.

How long does a Salesforce frontdoor URL stay valid?

Salesforce documents single-access frontdoor URLs as valid for up to one minute, and each one works only once. Generate the URL right before the browser opens it, and generate a new one for every test session.

Does the SFDX auth URL expire?

It stays valid as long as its refresh token does. That depends on the refresh token policy for the Salesforce CLI connected app in your org, and the token stops working as soon as someone revokes it.

Which test frameworks can use this approach?

Any framework that can run a shell command and open a URL in a browser. The example in this article uses WebdriverIO, and the same two CLI commands work with Playwright, Selenium, or Cypress.

Related reading: Salesforce Consulting Services · AI in Software Development

Talk to our team

Need Help With Salesforce Test Automation?

If MFA enforcement broke your UI tests, or you’re planning a test suite for a new implementation, ENWAY’s QA team can help you set it up securely. Tell us about your org and your current tests.

Since 2016Salesforce consulting
150+projects delivered
5/5AppExchange rating