Assert that the site refuses to enrol the account in the browser in a course with a key: the dialog of the enrolment key stays, with the error it shows.
Examples
Then enrolling myself in the course "Software Testing 101" with the key "wrong-key" should be refused with "Incorrect enrolment key, please try again"
Then enrolling myself in the course "TEST101" with the key "nope" should be refused with "Incorrect enrolment key, please try again"
And enrolling myself in the course "Software Testing 101" with the key "" should be refused with "Incorrect enrolment key, please try again"
Then enrolling myself in the course "Software Testing 101" with the key "test101-key" should be refused with "Incorrect enrolment key, please try again"
But enrolling myself in the course "TEST101" with the key "wrong-key" should be refused with "Incorrect enrolment key"
Pattern
Then(/^enrolling myself in the course "([^"]*)" with the key "([^"]*)" should be refused with "([^"]*)"$/, …)
Part of @webship-js/moodle-steps (github.com/webship/moodle-steps), a step pack for Webship-js 2.0.x.