🐺

gaugeのtableで改行を含む文字列を渡す

2025/01/11に公開

はじめに

gaugeでtableを使う時に、文字列に含めた改行を評価させる方法を探した。

結論:csvファイルで対応する

# gaugeで文字列に含めた改行を評価する
## csvファイルを渡す
*結果が<table:target.csv>である

Special Parameter

Tables are used to pass table values into steps by using the values from an external CSV file. The syntax of this parameter is as follows: table:value [value] is the absolute or relative path to the file located at <project_root> (location at which the Gauge project is created).

https://docs.gauge.org/writing-specifications?os=macos&language=java&ide=vscode#special-parameter-csv

gaugeのTableは、Special Parameterに属するパラメータで、外部CSVファイルの値を使用でき、Table値をCSVの内容として渡すことが可能。

Id,Name
1,The Way to Go On
2,Ivo Jay Balbaert

file_pathはrootから見る
<project_root>/Users/john/work/users.csv

*結果が<table:Users/john/work/users.csv>である

Special Parameterのsyntax

prefix:valueの形式

prefix - defines the special type of parameter such as file or table
value - defines the value for the type of special parameter

Special Parameterの種類

投稿時点では、2種類用意されている

  • File
  • CSV

改行を含めたcsv

csvファイルは文字列中に改行を行うと、改行として評価されます。

Id,Name
1,山田
太郎
*結果が<table:/Users/john/work/users.csv>である

gauge_data_dir

csvを格納するディレクトリのroot_pathgauge_data_dirに指定することも可能なため
ファイルの階層が深くネストしているような場合に検討しても良いかもしれないです。
※本来は環境毎に実行対象のdirを返るために用意されているpropertyです。

gauge_data_dir = data/qa

https://docs.gauge.org/execution?os=macos&language=java&ide=vscode#configuring-table-data-per-environment

Discussion