typescriptjasmineprotractorjasmine-node

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


enter image description here My data file looks like this. Only first set passes but second iteration, it fails at email address

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
        }
    }
};

Any help is greatly appreciated. Not sure why it is throwing error only for 2nd iteration. Ist iteration all the values are accepted and test is passed

My Spec File

import {browser} from 'protractor'; import {LoginPageEntities} from '../pageObjects/loginLogoutWorkflow/LoginPageEntities.po'; import {CustomLogger} from '../../utils/logging'; import {after} from 'jasmine-expect/dist/asymmetricMatchersByName'; import {LogoutPageEntitiesPo} from '../pageObjects/loginLogoutWorkflow/LogoutPageEntities.po'; import {main} from '@angular/compiler-cli/src/main'; import {ForgotPasswordPo} from '../pageObjects/loginLogoutWorkflow/ForgotPassword.po'; import {NewUserRegistrationPo} from '../pageObjects/loginLogoutWorkflow/NewUserRegistration.po'; import { using } from 'jasmine-data-provider'; import {userTestData} from '../globalData/userData';

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 method

 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);

        });
  }

Solution

  • Take a look at example how to use Data Provider from object in the npm description to the package

    You have to re-write your Data object as:

    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
            }
        }
    };