siva r k
siva r k

Reputation: 29

Read data from External data sheet - eggPlant

Is there a way to read data from an external data sheet like excel, Text file etc. in eggPlant?

When running the same script for various set of Input parameters this would prove useful for me instead of hardcoding the values..

-Siva

Upvotes: 0

Views: 2810

Answers (2)

GetHacked
GetHacked

Reputation: 564

Since this is the most viewed Eggplant question, I'll give it a more robust answer.

Yes! Using data from a data file is a fantastic way to parameterize your test without hardcoding!

Saving Data

To do so, you have to save your data in .csv or .txt format, within the Suite's Resources directory. This allows you to open and interact it from within Eggplant Functional.

Importing Data

In your script, you can reference these data files with just their filename, for example,

put ResourcePath("myData.txt") into FilePath

will save the entire file myData.txt from the Resources directory into a variable FilePath.

Accessing Data

You can then access each row of that file like any other file.

put line 1 of file FilePath into Name
put line 2 of file FilePath into DOB

If you save your data as a .csv, you can specify a row and column of a specific piece of data.

put item 2 in line 1 of file FilePath into Last_Name

Read more about reading files in the Eggplant Documentation!

For more complicated resource files, read this page in the Eggplant Documentation!

Upvotes: 1

ChanGan
ChanGan

Reputation: 4318

1. Enter the data in the excel sheet and save it as a CSV file.

2. Piece of code:

repeat with theData= each line of file "D:\TestData.csv"
    log item 1 of theData 
end repeat

Upvotes: 0

Related Questions