Knowledge Base Article

Code for groovy datasource

Question

generates some identification codes like X00001, X00002 and so on...

Answer

// Get current row
def row = testRunner.testCase.testSteps["DataSource"].currentRow

// Declare an array that will contain the id codes
def codes = []

// Generate all id codes
for (int i = 1; i < 100000; i++) {
	codes.add( String.format('X%05d', i) )
}

// Make the values reachable from the datasource
if (row < codes.size()) {
    // Return the name to data source's "File" property
    result["Code"] = codes[row]
}
Published 3 years ago
Version 1.0

Was this article helpful?

No CommentsBe the first to comment