Sorry, we didn't find any relevant articles for you.

Send us your queries using the form below and we will get back to you with a solution.

How do I use the MatchStringGen Generator?

Check a string for a value match using a contains, startsWith, or endsWith - use constant or referenced value

Description

The MatchStringGen Generator checks a string for a value match using a contains, startsWith, or endsWith matching function. You can check a constant or referenced value for a match and link one or more Generators to generate specific output based on the result.

Generator Parameters

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

  • matchType* - Defines the function to use for matching. The following functions are:
    • contains
    • startsWith
    • endsWith
  • string* - A string or reference to an Attribute whose string will be checked for a match.
  • value* - A string or reference to an Attribute whose string will be used by the matching function at the token to match.
  • matchCase* - Determines if the string and value are case sensitive when matching.
  • notResult* - Switches the Boolean result.
    • "not" of false = true
    • "not" of true = false

Example 1 - Email Address Validation

A tester must test an application that requires users to enter a valid email address. They want to check each email address based on the domain name (e.g., com, net, gov). When valid, the value will be 'true'; otherwise, it will be 'false'.

The MatchStringGen will be used to perform a validation check. If the email address has one of the following domain names, it is valid:

  • com
  • net
  • gov

This example will use two Attributes to validate the email address:

  • email - generates valid and invalid emails
  • validation - checks if the email is valid or invalid

The generated output is shown below:

ListGen (gen1)

Generates values to check for a valid email domain name (e.g., com, net, gov).

  • random - true, values are generated randomly
  • list - values that will be generated randomly

MatchStringGen (gen2)

Checks each email for the domain names in the referenced ListGen (gen1). If valid, generates 'true'; otherwise, generates 'false'.

  • matchType - endsWith, the string must end with the value
  • string - references the email Attribute
  • value - references the ListGen (gen1) for a list of valid domain names

Example 2 - Check if Account Type is Checking

A user wants to determine if an account is a checking account. They can then use the result to generate a desired outcome when it is a checking account. For this example, account numbers start with one of the following:

  • CHK - checking
  • SAV - savings

When the account number contains CHK, the generator should generate 'true'; otherwise, it should generate 'false'. This example uses two Attributes:

  • account - generates the account number
  • checkingValidation - checks the account number to see if it is a checking account

NOTE: You can also use Linked Generators to perform the check or to generate specific test data based on the result (true/false).

MatchStringGen (gen1) Configuration

The MatchStringGen will look for CHK in the account number and return 'true' when it is present.

  • matchType = startsWith, must be at the beginning of the string
  • string = #{Match.account}, references the account Attribute.
  • value = CHK, value it will look for

Example 3 - Check for Number 4 in a Randomly Generated Number String

For this example, two Generators have been linked to show the randomly generated number string and the MatchStringGen Generator output. 

gen1 = Randomly generated string
gen2 = Result based on generated string

For this example, each string containing a "4" will show true:

A RandomStringGen Generator generates a random number string. It is referenced by the string Parameter of the MatchStringGen Generator.

Here is the RandomStringGen Generator configuration:

  • length = 6, generates a string of six characters
  • stringType = numbers