【发布时间】:2018-07-27 07:59:53
【问题描述】:
有没有办法从eggPlant中的excel、文本文件等外部数据表中读取数据?
当为各种输入参数集运行相同的脚本时,这对我很有用,而不是对值进行硬编码..
-湿婆
【问题讨论】:
标签: eggplant
有没有办法从eggPlant中的excel、文本文件等外部数据表中读取数据?
当为各种输入参数集运行相同的脚本时,这对我很有用,而不是对值进行硬编码..
-湿婆
【问题讨论】:
标签: eggplant
由于这是观看次数最多的茄子问题,我将给出更可靠的答案。
是的!使用数据文件中的数据是一种无需硬编码即可参数化测试的绝妙方法!
为此,您必须将数据以 .csv 或 .txt 格式保存在套件的资源目录中。这使您可以在 Eggplant Functional 中打开它并与之交互。
在您的脚本中,您可以仅使用文件名引用这些数据文件,例如,
put ResourcePath("myData.txt") into FilePath
会将整个文件myData.txt从资源目录保存到变量FilePath中。
然后您可以像访问任何其他文件一样访问该文件的每一行。
put line 1 of file FilePath into Name
put line 2 of file FilePath into DOB
如果您将数据保存为 .csv,则可以指定特定数据的行和列。
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!
【讨论】:
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
【讨论】: