How do I write a behat test to go to user/UID/somewhere when I only know the username? I'm trying to write Behat tests to verify my Drupal Commerce store.
My test creates some users, so I know the usernames but not the UIDs (the UIDs are assigned by Drupal in the test, so they will be different each time).
So, I want to get the UID based on the username, and then redirect to the payment method page for that user with a step like When I go to the payment method page for username ABC.
Here's my code:
  /**
   * @Then I go to the payment method page for username :username
   */
  public function iGoToThePaymentMethodPageForUsername($username) {
    $user_object = $this-&gt;userManager-&gt;getUser($username);
    $uid = $user_object-&gt;id;
    if (!(is_int($uid))) {
      throw new Exception(&quot;UID is not a number ('$uid')&quot;);
    }
    $this-&gt;visitPath(&quot;user/$uid/payment-methods&quot;);
  }

However, this code fails with the following error message:
  No user with ABC name is registered with the driver.

When I checked this-&gt;userManager-&gt;getUsers(), I found that it only has the users generated by the Drupal extension in the current scenario; I cannot access the users who have been registered in other scenarios or users who have already registered outside of Behat.
What's the correct way to get the user object for such a user?
You could use Sub-pathauto which will allow you to use /user/username/somewhere instead.