Testing login with PhantomJS

I’m trying to write simple tests for my login flow. Previously, my tests worked fine on Auth0 Lock v9, but some changes in Lock v10 have made it difficult for me to automate my tests.
Here’s what my code looked like in Lock v9:

window.auth0Lock.on('ready', function() {
  console.log('Auth0 ready');
  $('#a0-signin_easy_email').val('test@test.com');
  $('#a0-signin_easy_password').val('usemefortests');
  $(document).on('auth0-profile-available', function(e, profile) {
    // auth0-profile-available is fired by client-side JS on login
    console.log('profile available');
    var payload = {
      nickname: profile.nickname,
      exit: false
    };
    window.callPhantom(payload);
    $(document).trigger('login-complete');
  });
  $('.a0-primary.a0-next').click();
});

The recent changes seem to be more than just changes in the selectors:
For example, making the following replacements, does not seem to work.

  • $('#a0-signin_easy_email') --> $('input[name="email"]')
  • $('#a0-signin_easy_password') --> $('input[name="password"]')
  • $('.a0-primary.a0-next') --> $('.auth0-lock-submit')

Upon testing the code via browser console, Auth0 complains that the email and password fields are empty.

How can I create tests for my login workflow?

To my knowledge, there’s no supported way to set password programmatically so I don’t think what you’re trying to do will be easy or even feasible. Although you can set the input elements the underlying data model will likely not be updated and as such the data you set is not being used.

If I understand your situation correctly, you want to bypass the login step so that you can then perform automated testing of the parts of the application that require authentication. If that’s the case you could consider doing the login with test credentials through a non-interactive flow and then just make the the outcome (tokens and user profile information) available to your application so that it thinks the user already completed login. If you were more interested in just testing the login flow itself then this may not apply.