flood-io / element

💦Load test your app using real web browsers
https://element.flood.io
Apache License 2.0
350 stars 43 forks source link

flood element fromCSV showing undefined for data column values #558

Open alanbqs opened 2 years ago

alanbqs commented 2 years ago

I'm trying to get flood-element to step through a number of csv records but I'm finding that some of the columns in the CSV are coming through as "undefined" and I can't see why. How do I fix this to get the City names out too?

The CSV data is:

City,Country,Id
Tokyo,Japan,1
Delhi,India,2
Shanghai,China,3
São Paulo,Brazil,4
Mexico City,Mexico,5

and the ts script reads:

import { step, TestSettings, TestData, By, beforeAll, afterAll } from '@flood/element'

export const settings: TestSettings = {
  userAgent: 'flood-chrome-test',
  loopCount: 10
  disableCache: true,
  clearCache: true,
  actionDelay: 0.1,
  stepDelay: 0.1,
}

export default () => {

    // Specify the shape of each record in your CSV data set
    interface AccountRow {
      City: string,
      Country: string,
      Id: int
    }

    TestData.fromCSV<AccountRow>("testdataA.csv");

    step("Create a new Account", async (browser: Browser, data:AccountRow) => {
        console.log('City:'+data.City+' Country='+data.Country+' Id='+data.Id);
    });

}

and the output is:

C:\elementflood\test1>element run test1.ts
Running test1.ts (1 of 1) with
- Element v2.0.4
- Node v15.4.0

√ Script Compiler
  Compiled successfully in 180.45ms

  √ Iteration 1 of 10
    √ Step 'Create a new Account' passed (1ms)
      City:undefined Country=Japan Id=1      <--------------- should be City:Tokyo
  Iteration 1 completed in 195ms (walltime) 1 passed
  --------------------------------------------
  √ Iteration 2 of 10
    √ Step 'Create a new Account' passed (0ms)
      City:undefined Country=India Id=2      <--------------- should be City:Delhi
  Iteration 2 completed in 155ms (walltime) 1 passed
  --------------------------------------------
  √ Iteration 3 of 10
    √ Step 'Create a new Account' passed (0ms)
      City:undefined Country=China Id=3      <--------------- should be City:Shanghai
  Iteration 3 completed in 146ms (walltime) 1 passed
  --------------------------------------------
  √ Iteration 4 of 10
    √ Step 'Create a new Account' passed (1ms)
      City:undefined Country=Brazil Id=4      <--------------- should be City:São Paulo
  Iteration 4 completed in 152ms (walltime) 1 passed
  --------------------------------------------
  √ Iteration 5 of 10
    √ Step 'Create a new Account' passed (1ms)
      City:undefined Country=Mexico Id=5      <--------------- should be City:Mexico City
  Iteration 5 completed in 152ms (walltime) 1 passed
novacoole commented 2 years ago

@alanbqs for whatever reason, having an extra comma on the end of each line of the CSV resolved this for me when i was having a similar issue.

Tokyo,Japan,1,
Delhi,India,2,
Shanghai,China,3,
São Paulo,Brazil,4,
Mexico City,Mexico,5,