Enrol the account in the browser in a course, the way a student does: the course's enrolment options, "Enrol me" and the enrolment key. The step fails when the site refuses the key. The browser ends on the course page.
Examples
When I enrol myself in the course "Software Testing 101" with the key "TEST101-key"
Then I enrol myself in the course "Software Testing 101" with the key "TEST101-key"
And I enrol myself in the course "TEST101" with the key "TEST101-key"
Given I enrol myself in the course "Software Testing 101" with the key "TEST101-key"
When I enrol myself in the course "TEST101" with the key "TEST101-key"
Pattern
When(/^I enrol myself in the course "([^"]*)" with the key "([^"]*)"$/, …)
Part of @webship-js/moodle-steps (github.com/webship/moodle-steps), a step pack for Webship-js 2.0.x.