Skip to main content

Generate Email Address

client.genEmail(prefix, callback = () => {});

This custom command creates an email address based on a prefix string, which will be added to the beginning of the email address. The prefix is used to identify a specific participant within the test, such as their name or ID. The generated email address will have the format of {prefix}-{runID}@{domain}. The "runID" and "domain" parts of the email address will be automatically filled in.

caution

Manually formatting email address in this format is not recommended, as it may lead to errors in the test. Use this custom command instead.

The custom command will pass the generated email address to the callback function provided as its first argument. The email address will be accessible within the callback function as a string, allowing you to use it for further processing.

client => {
client.genEmail("test", addr => {
console.log(`Generated email address: ${addr}`);
});
}

To save the generated email address for later use, you can use the following code snippet:

client => {
let email;

// Generate the email address and save it on email variable
client.genEmail("test", addr => {
email = addr;
});

// Use the email address here
client.perform(() => {
console.log(`Generated email address: ${email}`);
});
}

Keep in mind, that taking into consideration the asynchronous nature of the Nightwatch, the email address will not be available immediately after calling the genEmail function, so it's recommended to use the saved value within aperform command. Otherwise you may encounter an error that the email variable is undefined.