Forum Discussion

Lucian's avatar
Lucian
Community Hero
7 years ago

Sharing is caring - code for groovy datasource

As per Olga_T's suggestion here is a script that generates some identification codes like X00001, X00002 and so on...

 

// 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]
}

Cheers!

No RepliesBe the first to reply