Class DslCsvDataSet
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
-
- us.abstracta.jmeter.javadsl.core.configs.BaseConfigElement
-
- us.abstracta.jmeter.javadsl.core.configs.DslCsvDataSet
-
- All Implemented Interfaces:
DslConfig,DslTestElement,DslTestPlan.TestPlanChild,BaseSampler.SamplerChild,MultiLevelTestElement,BaseThreadGroup.ThreadGroupChild
public class DslCsvDataSet extends BaseConfigElement
Allows using a CSV file as input data for JMeter variables to use in test plan.This element reads a CSV file and uses each line to generate JMeter variables to be used in each iteration and thread of the test plan.
Is ideal to be able to easily create test plans that test with a lot of different of potential requests or flows.
By default, it consumes comma separated variables, which names are included in first line of CSV, automatically resets to the beginning of the file when the end is reached and the consumption of the file is shared by all threads and thread groups in the test plan (ie: any iteration on a thread will consume a line from the file, and advance to following line).
Additionally, this element sets by default the "quoted data" flag on JMeter CSV Data Set element.
- Since:
- 0.24
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslCsvDataSet.CodeBuilderstatic classDslCsvDataSet.SharingSpecifies the way the threads in a test plan consume the CSV.
-
Field Summary
-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
guiClass, name
-
-
Constructor Summary
Constructors Constructor Description DslCsvDataSet(String csvFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.jmeter.testelement.TestElementbuildTestElement()org.apache.jorphan.collections.HashTreebuildTreeUnder(org.apache.jorphan.collections.HashTree parent, BuildTreeContext context)Builds the JMeter HashTree for this TestElement under the provided tree node.DslCsvDataSetdelimiter(String delimiter)Specifies the delimiter used by the file to separate variable values.DslCsvDataSetencoding(String encoding)Specifies the file encoding used by the file.DslCsvDataSetencoding(Charset encoding)Specifies the file encoding used by the file.DslCsvDataSetignoreFirstLine()Specifies to ignore first line of the CSV.DslCsvDataSetignoreFirstLine(boolean enable)Same asignoreFirstLine()but allowing to enable or disable it.DslCsvDataSetrandomOrder()Specifies to get file lines in random order instead of sequentially iterating over them.DslCsvDataSetrandomOrder(boolean enable)Same asrandomOrder()but allowing to enable or disable it.DslCsvDataSetsharedIn(DslCsvDataSet.Sharing shareMode)Allows changing the way CSV file is consumed (shared) by threads.DslCsvDataSetstopThreadOnEOF()Specifies to stop threads when end of given CSV file is reached.DslCsvDataSetstopThreadOnEOF(boolean enable)Same asstopThreadOnEOF()but allowing to enable or disable it.DslCsvDataSetvariableNames(String... variableNames)Specifies variable names to be assigned to the parsed values.-
Methods inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
buildConfiguredTestElement, buildTestElementGui, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGui
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface us.abstracta.jmeter.javadsl.core.DslTestElement
showInGui
-
-
-
-
Constructor Detail
-
DslCsvDataSet
public DslCsvDataSet(String csvFile)
-
-
Method Detail
-
delimiter
public DslCsvDataSet delimiter(String delimiter)
Specifies the delimiter used by the file to separate variable values.- Parameters:
delimiter- specifies the delimiter. By default, it uses commas (,) as delimiters. If you need to use tabs, then specify "\\t".- Returns:
- the dataset for further configuration or usage.
-
encoding
public DslCsvDataSet encoding(String encoding)
Specifies the file encoding used by the file.This method is useful when specifying a dynamic encoding (through JMeter variable or function reference). Otherwise prefer using
encoding(Charset).- Parameters:
encoding- the file encoding of the file. By default, it will use UTF-8 (which differs from JMeter default, to have more consistent test plan execution). This might require to be changed but in general is good to have all files in same encoding (eg: UTF-8).- Returns:
- the dataset for further configuration or usage.
-
encoding
public DslCsvDataSet encoding(Charset encoding)
Specifies the file encoding used by the file.If you need to specify a dynamic encoding (through JMeter variable or function reference), then use
encoding(String)instead.- Parameters:
encoding- the file encoding of the file. By default, it will use UTF-8 (which differs from JMeter default, to have more consistent test plan execution). This might require to be changed but in general is good to have all files in same encoding (eg: UTF-8).- Returns:
- the dataset for further configuration or usage.
-
variableNames
public DslCsvDataSet variableNames(String... variableNames)
Specifies variable names to be assigned to the parsed values.If you have a CSV file with existing headers and want to overwrite the name of generated variables, then use
ignoreFirstLine()in conjunction with this method to specify the new variable names. If you have a CSV file without a headers line, then you will need to use this method to set proper names for the variables (otherwise first line of data will be used as headers, which will not be good).- Parameters:
variableNames- names of variables to be extracted from the CSV file.- Returns:
- the dataset for further configuration or usage.
-
ignoreFirstLine
public DslCsvDataSet ignoreFirstLine()
Specifies to ignore first line of the CSV.This should only be used in conjunction with
variableNames(String...)to overwrite existing CSV headers names.- Returns:
- the dataset for further configuration or usage.
-
ignoreFirstLine
public DslCsvDataSet ignoreFirstLine(boolean enable)
Same asignoreFirstLine()but allowing to enable or disable it.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the dataset for further configuration or usage.
- Since:
- 1.0
- See Also:
ignoreFirstLine()
-
stopThreadOnEOF
public DslCsvDataSet stopThreadOnEOF()
Specifies to stop threads when end of given CSV file is reached.This method will automatically internally set JMeter test element property "recycle on EOF", so you don't need to worry about such property.
- Returns:
- the dataset for further configuration or usage.
-
stopThreadOnEOF
public DslCsvDataSet stopThreadOnEOF(boolean enable)
Same asstopThreadOnEOF()but allowing to enable or disable it.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the dataset for further configuration or usage.
- Since:
- 1.0
- See Also:
stopThreadOnEOF()
-
sharedIn
public DslCsvDataSet sharedIn(DslCsvDataSet.Sharing shareMode)
Allows changing the way CSV file is consumed (shared) by threads.- Parameters:
shareMode- specifies the way threads consume information from the CSV file. By default, all threads share the CSV information, meaning that any thread iteration will advance the consumption of the file (the file is a singleton). WhenrandomOrder()is used, THREAD_GROUP shared mode is not supported.- Returns:
- the dataset for further configuration or usage.
- See Also:
DslCsvDataSet.Sharing
-
randomOrder
public DslCsvDataSet randomOrder()
Specifies to get file lines in random order instead of sequentially iterating over them.When this method is invoked Random CSV Data Set plugin is used.
Warning: Getting lines in random order has a performance penalty.
Warning: When random order is enabled, share mode THREAD_GROUP is not supported.
- Returns:
- the dataset for further configuration or usage.
- Since:
- 0.36
-
randomOrder
public DslCsvDataSet randomOrder(boolean enable)
Same asrandomOrder()but allowing to enable or disable it.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the dataset for further configuration or usage.
- Since:
- 1.0
- See Also:
randomOrder()
-
buildTreeUnder
public org.apache.jorphan.collections.HashTree buildTreeUnder(org.apache.jorphan.collections.HashTree parent, BuildTreeContext context)Description copied from interface:DslTestElementBuilds the JMeter HashTree for this TestElement under the provided tree node.- Specified by:
buildTreeUnderin interfaceDslTestElement- Overrides:
buildTreeUnderin classBaseTestElement- Parameters:
parent- the node which will be the parent for the created tree.context- context information which contains information shared by elements while building the test plan tree (eg: adding additional items to test plan when a particular protocol element is added).- Returns:
- The tree created under the parent node.
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
-