Description
This article provides a complete example for setting up a G-Data Table and using it to call GenRocket Components dynamically (e.g., Scenarios, Scenario Chains, Scenario Chain Sets, G-Cases) within a Cumber Test.
In This Article
- Sample Story
- Step 1: Create and Edit the Feature File
- Step 2: Download the Feature File and Step Definition File
- Step 3: Modify the Step Definition
- Appendix - QueryUtil Class
Sample Story
A tester wants to create a feature file and implement a step definition to perform a load test on the genrocket_bank.user table. The user has determined that 1000 rows of data will be needed to effectively test the user table load. Thus, the tester will utilize GenRocket's Feature File platform to take advantage of G-Data Tables. Then, the step definition will generate the 1000 rows of user data it needs dynamically.
Step 1: Creating and Editing the Feature File
In this 1st image, the userLoadTesting feature has been created, its steps defined and the feature file text is visible within the Gherkin tab.
In this 2nd image, for the userLoadTesting feature, the step definition text is visible with the Step Definition tab. Note, the Step Definition used in this example is Groovy as opposed to Java.
This 3rd image shows the advantages of using the G-Data Table Editor to easily create and modify a G-Data Table.
In this 4th image, The G-Data Table Editor allows the user to quickly search and select different self-serve components that will be assembled into a Data Table. The G-Data Table defined will is mimicking the following GenRocket commands.
- Standard Commandline Version
- genrocket -r UserScenario.grs -tdc BankTestCases.gtdc:Load.load1000
- G-Repository Commandline Version
- genrocket -grepo GenRocketBank -grs UserSceanrio -tdc BankTestCase.Load.load1000
- Step Definition Version
- GRFeatureFile.execute(arg1.asMaps(), false)
Step 2: Download the Feature File and Step Definition File
After setting up the Feature File, click on the Download (Cloud) icon to download the Feature File and Step Definition File. Users can download both files or use the checkboxes to select or deselect files.
The Feature File will appear as shown below once downloaded (or copied). The 'profileId' is automatically added to the feature file by GenRocket.
Step 3: Modify the Step Definition File
The example code defined below is written in Groovy and is merely one of an infinite number of ways this code could have been written to execute steps defined within the feature file.
Note: Line 20 uses GFeatureFile.execute to reference the G-Data Table and dynamically call the GenRocket runtime engine to launch and run the UserSceanario with the G-Case, BankTestCase.Load.load1000, which will insert 1000 users into the genrocket_bank.user table. The GFeatureFile class is located within the com.genRocket.engine jar.
Appendix
QueryUtil Class
The QueryUtil class contains helper methods that connect to a database and perform SQL operations. The QueryUtil thus allows step definition code to be clean, testable, free of database connection, execution concerns. The QueryUtil also enables step definitions to be unconcerned about the type of database it affects.