selenium cucumber javascript 使用 faker 在迭代中填充不同的值

selenium cucumber javascript use faker to fill different value on iteration

我是使用 javascript 的自动化硒的新手,我有如下简单的代码,我正在使用 faker 数据生成随机电子邮件,问题是我在场景大纲 2 中有数据 table类型,当我 运行 代码中关于第二个循环的电子邮件数据如何使用在第一个循环中生成的相同数据时,问题是如何为第二个循环获取不同的数据?

#feature 文件

@RegisterMerchant
Feature: Register new merchant
    Scenario Outline: As a new User, I want to create new merchant account
        Given User is on register page
        When User fill register form for "<businessChannel>" merchant
        And User click register
        Then User should see success pop up message
        Examples:
            | businessChannel |
            | offline         |
            | online          |

#数据文件

const faker = require('faker')

class registerData {
    email = faker.name.firstName().toLowerCase() + faker.name.lastName().toLowerCase() + "@mailinator.com"
}
module.exports = new registerData()

#步骤文件

const { Given, When, Then } = require('cucumber');
const registerPage = require('../PageObjects/registerMerchantPage')
Given(/^User is on register page$/, () => {
    registerPage.isOnRegisterPage()
});

When(/^User fill register form for "([^"]*)" merchant$/, (businessChannel) => {
    registerPage.inputRegisterForm(businessChannel) .. 
});

When(/^User click register$/, () => {
    registerPage.signUpButton.click()
});

Then(/^User should see success pop up message$/, () => {
    registerPage.showPopUpSuccess()
});

实际第 2 次迭代仍在使用第 1 个 faker 数据

#page 对象文件

inputRegisterForm(businessChannel) {
        this.emailAddressField.addValue(registerData.email)
        switch (businessChannel) {
            case "online":
                this.onlineRadBtn.click()
                break;

            case "offline":
                this.offlineRadBtn.click()
                break;
        }
    }

通过为此数据文件添加函数解决:

email = faker.name.firstName().toLowerCase() + faker.name.lastName().toLowerCase() + "@mailinator.com"

变成这样

#数据文件

    class registerData {
        generateRegisterData() {
            this.email = faker.name.firstName().toLowerCase() + faker.name.lastName().toLowerCase() + "@mailinator.com"
            console.log("Test")
        }

email = ""

#page 目标文件

inputRegisterForm(businessChannel) {
        registerData.generateRegisterData()
        this.emailAddressField.addValue(registerData.email)
        switch (businessChannel) {
            case "online":
                this.onlineRadBtn.click()
                break;

            case "offline":
                this.offlineRadBtn.click()
                break;
        }
    }