Description

The CompareStringGen Generator returns ‘true’ or ‘false’ based on whether two string values are equal [EQ] or not equal [NE]. The compared strings can be referenced or a constant value. 


For example, you can use it to compare two strings and use the result (true/false) to generate a certain value:  

  • Setting a status based on country (e.g., USA = Domestic, Other = International)
  • Grant admin rights if the user role is 'Admin' (e.g., Admin = Enabled, Other = Disabled)
  • Tax application flag (e.g., CA = Apply, Other = DoNotApply)


In This Article


Generator Parameters

The following parameters may be configured for the CompareStringGen Generator. Items with an asterisk* are required. 

  • operator* – Defines the type of compare operation that will be taken on the two strings: Equal or Not Equal.
  • ignoreCase* – Determines if the comparison should be case sensitive.
  • value1* – Defines the first string to compare.
  • value2* – Defines the second string to compare.


Example 1 - Compare Strings to Determine if Country is Domestic or International

A tester wants to set a status based on the 3-digit country code (e.g., USA, DEU, ITA). If the code is "USA", the status should be "Domestic". For all other countries, it should be "International".


This example uses three linked Generators to accomplish the desired output for the Attribute: 

  • ListGen (country) - Generates the following 3-digit country codes: USA, FRA, DEU, ITA, POL, and CHN.
  • CompareStringGen (checkUSA) - References the ListGen (country) and checks for "USA" in the referenced string. 
  • SwitchGen (output) - Generates "Domestic" if the strings match and "International" if they do not. 



ListGen

Three-character country codes have been added to the ListGen.


CompareStringGen

Compares a referenced string value to determine if it is USA or another country. 

  • operator - EQ, checks two strings to see if they are equal.
  • value1 - references the ListGen (country) Generator.
  • value2 - USA, if value1 matches, it returns "true"; otherwise, it returns "false".


SwitchGen

Generates the actual output for the Attribute. The switch parameter references the CompareStringGen (checkUSA). The following values will be generated based on the value generated by the CompareStringGen. 

  • true = Domestic
  • false = International



Example 2 - Compare Random Colors in Two Lists

This example shows how to use the CompareStringGen Generator to compare random colors generated by two lists: 1st_list (gen1) and 2nd_list (gen2). As shown below, the generated result will be' true' when the random colors match in each of the two lists.



This example uses three Linked Generators:



For this example, the ListGen Generator is linked twice to the CompareStringGen Generator. The parameters are configured as follows: 

  • operator = EQ (Equal)
  • value1 = References ListGen Generator (gen1)
  • value2 = References ListGen Generator (gen2)



NOTE: To learn more about using the ListGen Generator, click here. To learn more about linking Generators, please see this knowledge base section: Linked Generators.


Below are the ListGen Generator Parameter configurations for each random list of colors: 


Value 1 (gen1): 



Value 2 (gen2):