Getting error The amount of data miss match the amount of column in data file when running a CSV File

I am trying to run a script with following:

  1. Create data.csv file through text editor
  2. Pass IDs from data.csv to pull different accounts (Succuess)
  3. Extract 4, 5 different parameters and store in Variables (Succuess)
  4. Use appendToCSV function to write the updated values to CSV.
    ${Id},${AppName},${AppStatus},${CustodianName},${EscalationName},${Mgr5},${Mgr4},${Mgr3}

CSV Header:
Id,AppName,AppStatus,CustodianName,EscalationName,Mgr5,Mgr4,Mgr3

When writing to the file using Katalon Recorder I am getting the error below even I verified the Columns manually.

[error] The amount of data miss match the amount of column in data file

Is there any other function or what is missing ?Please help.

Thanks,
Asad

@asad.hussain

How many CSV file(s) do you have? 1 file, or 2 files?

I guess, it is likely that KatalonRecorder implicitly assumes that you will use 1 input file and another 1 output file; it does not support the case where your test overwrites a single file.

Please try to use 2 files; read data.csv, write into another file output.csv.

1 Like

@asad.hussain The issue you have isn’t an issue to do with files being used for I/O purposes, the issue you have is a data structure one.

KAR it turns out is finicky about the structure of the data it expects to find in the destination CSV file. You mentioned that it has the required CSV headers… Turns out that this is not enough. You need the first row under the header also populated (e.g. with the same number of columns), without this, it’ll throw that error.

It feels like this is a bug, but at least there is this workaround.

This is the CSV structure when your operation should work:
"Id,AppName,AppStatus,CustodianName,EscalationName,Mgr5,Mgr4,Mgr3
X,Y,Z,A,B,C,D,E
"

Whereas, just using the following throws the error you’re expecting:
"Id,AppName,AppStatus,CustodianName,EscalationName,Mgr5,Mgr4,Mgr3
"

@vu.tran Do you know if what is described here (re behaviour) is expected / intentional, or a possible bug?

Hi folks, I am a test analyst trying out writing data from website to a csv file in the hopes of using it for a major project that requires a lot of data creation. I am using the Katalon Recorder version on Chrome browser. I am also facing the issue reported
I have followed the instructions: How to extract and write data in a test case with Katalon Recorder | Katalon Docs
But get the error “[error] The amount of data miss match the amount of column in the data file”
I have a feeling it is something basic that I am not aware of
Questions
1 - Should this work with basic Katalon recorder? I imagine so but do not know.
2 - Do I need to format columns e.g. for the pricing?
3 - Do I save it as standard .csv file (might be a dumb question but you never know)
4 - I saw @guy.mason gave a tip to add the first row under the header also populated. Don’t full understand how I should do this. I have in the Value column ${itemName},${itemPrice}. If I use your suggestion should I just have all on same line ${itemName},${itemPrice}, A, B ??

Any help or guidance would be much appreciated. Thanks - Shay

If you use a text editor (or even Excel / Pages) to create a CSV file, you can create what i’m describing.

In a text editor, it’s literally a case of having something like:
Line 1 in Editor: NameOfVariable1,NameOfVariable2, NameOfVariable3, etc…
Line 2 in Editor: Value1 for variable 1, Value 1 for variable 2, Value 1 for variable 3, etc…
Line 3 and later in Editor: Values 2 (and beyond) for each of the variables.

The commas are the way it ‘divides’ up the columns.

So, let’s take a practical example:
“CandidateNumber,Name,Gender,Country,FavouriteColour
01,Bobby,Male,England,Blue
02,Jane,Female,America,Pink
03,John,Male,Canada,Red”

If you copied and pasted the above (between the quotation marks) into a CSV file and saved it as CandidateData.csv, and then imported this into KAR, when your script calls ${CandidateNumber}, ${Name}, ${Gender},or ${FavouriteColour}, it will pull out the values from each of the columns, based upon which line its currently on.

You can encapsulate each value with quotation marks (Excel does this when creating CSVs), but it isn’t typically necessary (so commas are normally all you need as a ‘divider’, unless the data you’re using has a comma in it, then you’re likely to need quotation marks).

Hope that clarifies things a little more?

Hey Guy, greetings from sunny Sydney, Australia,
Thanks for responding. I am still struggling with this and I am sure it’s going to be something simple that I have not understood.

My issue is with capturing data from the website & writing data from Katalon Recorder to the .csv file
I have followed instructions to do this from here:
How to extract and write data in a test case with Katalon Recorder | Katalon Docs

I created csv file name-price.csv with 2 columns Price & Name as per the instructions and added it under Test-Data in Katalon Recorder

I created a script (write-to-csv)
In my script my I have these (plus the usual open etc.)
Command storeText
Target: xpath=//div[@id=‘root’]/div/div/div/div[2]/div/div[2]/div/div
Value Name

Command storeText
Target: xpath=//div[@id=‘root’]/div/div/div/div[2]/div/div[2]/div/div[3]
Value Price

Command appendToCSV
Target name-price.csv
Value ${Name},${Price}

I continue to get the error " [How to extract and write data in a test case with Katalon Recorder

Unfortunately I don’t seem to be able to add screenshots which would make explanation easier

Is there something really basic that I am missing.It is quote possible since I am very new to Katalon Recorder.

Thank you very much,
Shay

That syntax sems fine to me, simple question, but have you enabled file system access via Chrome?

(PS. I used copy and paste to ‘upload’ this screenshot)