Array Generator DPL
To run a java code with array arguments in Appvance use Array generator DPL. In order to execute Java code with the main method in Scenario Builder, you need to select an Array Generator DPL type and String[] from the actions dropdown. Add argument name and pass a value by clicking on Add Val link.
The main method uses an array generator.
Using ArrayGenerator DPL you can send an array of values as a single parameter that has inside many entries String array: [ "string1", "string2", "string3" ].
So now you can provide an input parameter for a method that requires an array-like
public void myMethod(String[]) { }
You can also have Object arrays-Example:
[ { name: 'Honda', models: [ { name: 'Accord', features: ['2dr', '4dr'] }, { name: 'CRV', features: ['2dr', 'Hatchback'] }, { name: 'Pilot', features: ['base', 'superDuper'] }, { name: 'Toyota', models: [ { name: 'Prius', features: ['green', 'superGreen'] }, { name: 'Camry', features: ['sporty', 'square'] }, { name: 'Corolla', features: ['cheap', 'superFly'] }
Types for arrays available: Object, String, Integer, int, Byte, byte, Double, double, Short, short, Float, float, Character, Boolean, Boolean
Sample Java Code with int array[]:
package com.package1; import java.util.Arrays; public class Array { public void main(String args[]) throws Exception { } public void printArray(String message, int array[]) { Arrays.sort(array); System.out.println(message + ": [length: " + array.length + "]"); for (int i = 0; i < array.length; i++) { if(i != 0){ System.out.print(", "); } System.out.print(array[i]); } System.out.println(); int index = Arrays.binarySearch(array, 2); System.out.println("Found 2 @ " + index); } }
Create a jar file for the above java code. Goto Scenario builder and select a Functional test Test type. Add a test case with Java Test type and browse the above-created jar file. The above java code consists of two arguments first with a String argument and second with an int array argument. You need to pass the argument in the same order in Appvance to run the scenario successfully.
Two arguments using array generator
Enter 100% logs in the Options panel. Save and play the scenario in a controller window.
Output:
Two arguments using array generator