[CSV] Is there any way change the delimiter in sensetalk?

Hi, I’m new to eggplant and just asking for some help if there is any way to change the delimiter in sensetalk of a csv file.

I’ve read the documentation regarding the csv functions (e.g. CSVValue, CSVFormat) but I don’t know how to integrate it in my dataextract code since the content of my csv file has a comma and sensetalk reads it as a delimiter therefore reading it as one and not decoding it as a normal string.

This is the loginpage function which enters the username and password into the webform

(Purpose: Function to enter username and password)
on doLogin username, password
log “Start doLogin”
//typetext username, tabKey
//typetext decodetext(username),tabKey
typeencodedtext username
typetext tabkey
typeencodedtext password
click text:“Log In to Sandbox”, SearchRectangle:[153,345,528,665]
waitfor 200, text:“Sandbox:”

if imagefound(text:"Sandbox:", SearchRectangle:[0,101,1344,139])
	logsuccess "User is able to Login"
else
	logerror "User is not able to Login"
	capturescreen (Name: "Log in Error")
	
end if
wait 5
if imagefound("Common/showNotificationsPrompt")
	click text:"Block",searchrectangle:[337,140,420,194]
end if
if imagefound("Common/savePasswordPrompt")
	click text:"Never",searchrectangle:[1192,311,1285,361]
end if
log "End doLogin"

end doLogin

This the dataextract code block:

(Purpose: Function to enter generic login credentials)
on set_generic_admin_user dataPathFile, dataTCRow, dataFileType
log “start set_generic_admin_user”
if dataFileType equals “csv”
(put dataPathFile into userFileContents
set csvFile to file userFileContents
)
put dataTCRow + 1 into dataTCRow
set csvFile to file resourcepath(dataPathFile)
repeat with each line of line dataTCRow of csvFile
put item 1 of it into global uname
put item 2 of it into global pword
end repeat
end if
log “end set_generic_admin_user”
end set_generic_admin_user

Really do hope someone helps me with this. Thanks! BTW if anyone needs the csv file just dm me. Thanks!

Essentially no. But there are ways around the issue. I’m guessing you are exporting from some application that lets you pick a delimiter but isn’t Excel or else you would just work with the file as an Excel Workbook. If that is the case then you should be able to simply load the whole data file into a variable and then use the split command to make it a list. You’d have to get a bit fancier if you wanted to preserve your headers and make it a property list. There are ways to do that. If you want to send it to me I’ll take a crack at it. admin@logancraig.com

1 Like

Okay sir thanks. I’ll send it right away once I got out of my shift.

Hi bijang,
pls see the doc File and Folder Interaction again. Both functions have an delimiter-parameter, thus you can adapt it to your needs.
BR

I’m not really sure in how to implement the function of CSVValue or CSVFormat on the approach that I used in extracting data from an external csv file. If you would be so kind to help me I can send you via email my resources.

Came back here to correct myself, but GammaG already did:
https://docs.eggplantsoftware.com/ePF/SenseTalk/stk-file-folder-interaction.htm#csvvalue:~:text=the%20following%20parameters%3A-,delimiter%3A%20The%20delimiter%20parameter%20value%20represents%20a%20character%20to%20be%20used%20between%20the%20fields%20on%20each%20line.%20The%20default%20value%20is%20a%20comma.,-asLists%3A%20Setting

you can actually change the CSV delimiter when reading a CSV as a database. I am not sure if it is documented anywhere

set myDB to {file:ResourcePath("save copy.csv"), type:"CSV", writeable:"Yes", delimitor:";"}
log the records of myDB
put the records of myDB into mylist

Bijang, I manually changed your delimiters in your csv to bars (|) and added a comma to your encrypted password:

put file ResourcePath("testcreds.csv") into CredentialFile
put CSVValue(CredentialFile, delimiter:"|") into Credential
log Credential
Log Credential.Password
10/25/22, 12:18:59 PM	START		Running Untitled2.script
>>> 12:18:59 Start handler 1: untitled2
put file ResourcePath("testcreds.csv") into CredentialFile
put CSVValue(CredentialFile, delimiter:"|") into Credential
log Credential
10/25/22, 12:18:59 PM	Log		[{password:@"F5\\{'?`c&,r(H>^#Js", username:"redacted"}]
Log Credential.Password
10/25/22, 12:18:59 PM	Log		F5\{'?`c&,r(H>^#Js
<<< 12:18:59 End handler 1: untitled2 (normal exit)
10/25/22, 12:18:59 PM	EndTestCase		(Duration:"0.195", Errors:"0", Exceptions:"0", StartTime:"2022-10-25 12:18:59 -0600", Successes:"1", TestCase:"Untitled2.script", Warnings:"0")
10/25/22, 12:19:00 PM	SUCCESS		Execution Time 0:00:00 Untitled2.script

What are you referring to this?? You changed the comma “,” of the encrypted username string to bars “|” in the csv file itself? Or are you referring to the code that you posted?

Also I think I sent the wrong csv file. I’m gonna resend it again. Please take a look to it again and see if you can find a way to resolve.

LoganC’s answer shows the correct way to use the CSVValue function to read a CSV file that contains “|” characters rather than commas. The result in Credential will be a list of property lists, one for each line in the file after the header line.