Generating random data

In this scenario, we cannot hard-code a single email to test because it may lead to a 409 Conflict error because an account with that email already exists. Therefore, we need to generate a random email each time the test is run. We need to define a new step definition where the data is randomly generated each time:

When(/^user types in an? (in)?valid (\w+) in the (?:"|')([\.#\w-]+)(?:"|') element$/, async function (invalid, type, selector) {  const textToInput = generateSampleData(type, !invalid);  this.element = await this.driver.findElement(By.css(selector));  return this.element.sendKeys(textToInput);});

Here, we create a generic step definition and use the yet-to-be-defined generateSampleData function to provide the ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.