无法使用 Typescript 在量角器中解析 "Failed: each key must be a number of string; got undefined"

Unable to resolve "Failed: each key must be a number of string; got undefined" in protractor using Typescript

我的数据文件看起来像这样。只有第一组通过但第二次迭代,它在电子邮件地址

处失败
export const userTestData = {

    scenarios: {

        scenario1: {
            firstName: 'John',
            lastName: 'Doe',
            city: 'Indianapolis',
            password: 'MyApp@123',
            emailAddress: 'Test1@gmail.com',
            addressLine1: '52nd BroadRipple Street',
            zipCode: 43464
        },

        scenario2: {
            firstName: 'Mark',
            lastName: 'Baker',
            city: 'Westfield',
            password: 'Test@123',
            emailAdd: 'Test1@gmail.com',
            addressLine1: '12412 Ballantyne Street',
            zipCode: 23053
        }
    }
};

非常感谢任何帮助。不知道为什么它只在第二次迭代时抛出错误。 Ist 迭代接受所有值并通过测试

我的规范文件

从'protractor'导入{浏览器}; 从 '../pageObjects/loginLogoutWorkflow/LoginPageEntities.po' 导入 {LoginPageEntities}; 从 '../../utils/logging' 导入 {CustomLogger}; 从 'jasmine-expect/dist/asymmetricMatchersByName' 导入 {after}; 从 '../pageObjects/loginLogoutWorkflow/LogoutPageEntities.po' 导入 {LogoutPageEntitiesPo}; 从“@angular/compiler-cli/src/main”导入{main}; 从 '../pageObjects/loginLogoutWorkflow/ForgotPassword.po' 导入 {ForgotPasswordPo}; 从 '../pageObjects/loginLogoutWorkflow/NewUserRegistration.po' 导入 {NewUserRegistrationPo}; 从 'jasmine-data-provider' 导入 { 使用 }; 从 '../globalData/userData' 导入 {userTestData};

const using = require('jasmine-data-provider');

describe('Test OnlineApp', () => {
const logger = new CustomLogger('LoginLogoutFunctionality');
let mainPage: LoginPageEntities;
let userRegisterPage: NewUserRegistrationPo;
beforeAll(async() => {
    logger.debug('Before All');
});
afterAll(async () => {
    logger.debug('After All');
});

beforeEach(async () => {
    mainPage = new LoginPageEntities();
    userRegisterPage = new NewUserRegistrationPo();
});


afterEach(async () => logger.debug('After Each'));

describe('example test', () => {
    using(userTestData.scenarios, async (data) => {
        xit('data provider tests',  async () => {
            browser.waitForAngularEnabled(false);
            const expectedValue = 'New User';
            await mainPage.launchURL();
            await mainPage.getHomePageTitle();
            await mainPage.clickLoginMenu();
            await mainPage.clickSelectedLink('New User?', 'New User');
            await userRegisterPage.setFirstName(data.firstName);
            await userRegisterPage.setLastName(data.lastName);
            await userRegisterPage.setNewEmailAddress(data.emailAddress);
            await userRegisterPage.setConfirmEmailAddress(data.emailAddress);
            await userRegisterPage.setNewUserPassword(data.password);
            await userRegisterPage.setConfirmPassword(data.password);
            await userRegisterPage.setAddressLine1(data.addressLine1);
            await userRegisterPage.setCity(data.city);
            await userRegisterPage.setZipCode(data.zipCode);
        });
    });
});

});

sendKeys 方法

 public async setNewEmailAddress(username: any) {
        const expectedEmailText = 'email';
        const emailField = await element(by.css('input[aria-label*=\'enter an email address\']'));
        await browser.wait(until.presenceOf(emailField), TIMEOUT_MILLIS,
            'New email field never appeared.');
        await emailField.clear();
        await emailField.sendKeys(username);
       // const usernameText =  emailField.getAttribute('type');
        await emailField.getAttribute('type').then( (text) => {
            logger.info('Getting email text:' + text);
            expect(text).toEqual(expectedEmailText);

        });
  }

查看如何在 npm description to the package

中使用来自 object 的数据提供程序的示例

您必须将数据对象重写为:

export const userTestData = {

    scenarios: {

        'scenario1': {
            firstName: 'John',
            lastName: 'Doe',
            city: 'Indianapolis',
            password: 'MyApp@123',
            emailAddress: 'Test1@gmail.com',
            addressLine1: '52nd BroadRipple Street',
            zipCode: 43464
        },

        'scenario2': {
            firstName: 'Mark',
            lastName: 'Baker',
            city: 'Westfield',
            password: 'Test@123',
            emailAdd: 'Test1@gmail.com',
            addressLine1: '12412 Ballantyne Street',
            zipCode: 23053
        }
    }
};