How to bypass UI login for Salesforce UI automation

Hey, this is more of an FYI than a question, but maybe we could still discuss other methods that have worked for you.

Basically, Salesforce changed something in our sandboxes so that every login via the UI now requires you to input a verification code that’s sent by email. Naturally, this caused all our tests to fail.

Setting the IP address ranges used to work, but now it doesn’t. What we’ve now done is to use an external client app to generate a JWT, then we use that to open an already logged in browser and continue as normal.

Here are two resources I used to help me along the way:

The first one isn’t “totally correct” - some additional access permissions are required, as are some adjustments to get the browser working. I obviously can’t share the exact code we implemented, but hopefully this still helps anyone coming across the same issue.

  1. Create permission set for connected app
  2. Create connected app
  3. Use encrypted server.key.enc and decryption key as environment variable
  4. Generate JWT
  5. Use JWT to open logged in browser session
  6. Continue UI automation

:victory_hand:

2 Likes

We used to use salesforce test system the place I worked a long time ago, it was a dark art is all there is to it. The platform creates enough friction to get you to buy their testing products as an upsell. I never worked directly on it, but yes, very similar problems, and always as the security environment changes, your test code needs to change with it. We had a email wrapper api around a mailbox in the mix too, to get around some flows we had imposed on ourselves as a security check on our side. So the testers then faked the emails in the services on our side by dumping them into a huge table that contained the email fields.

Some great hints you have found there.

Thanks for sharing. You’re totally right about the friction thing. I feel it for sure, but I’m determined to find other ways [shakes fist] :upside_down_face: