Skip to content
/ .. /
Extractor





Extractor

The Extractor is a file of the type .extractor which is used to extract text data from another source using predefined variable types or regular expressions.

Creating the Extractor File

First, create the Extractor file. It must have the extension .extractor and must be saved into the same project directory as its associated test case. If using intaQt Studio, the extension will automatically be created upon selecting New -> Extractor. intaQt Studio provides the following template, with completed fields that can be filled with the required text structure. The line breaks between each section are mandatory:

Syntax

1
2
3
4
5
6
Extractor: <extractor Name>
  Extractor description
  Text:
    Extractor pattern with ${<variableName Name>}
  Data:
    <variableName Name> = <VariableType variable>

Parameters

  • extractor - The Extractor's name

  • variableName - The name assigned to the variable in the Extractor's Text block

  • variableType - The variable's type which could be either one of a predefined variable type or a regular expression

    • The different variable types can not be used in conjunction with each other
    • Refer to the Defining The Data section for more information

Extracting the Text from a Feature File

After creating the Extractor and defining its parameters, it can be used in a Feature File:

Syntax

1
extract <result String> with <extractor Extractor> from <message String>

Parameters

  • result - The variable that holds the results that the extraction will be saved into

  • extractor - The Extractor's name

  • message - A String to extract the values from

The text structure defines the text and its arbitrary number of variables to match the first String available as shown in the example below. If there are no matches a *MISMATCH* error message will appear in the log.

Extractor Example

1
2
3
4
5
6
7
Extractor: ExampleExtractor
    Extract balance value of Text
    Text:
        balance: ${bal}, currency: ${curr}
    Data:
        bal = DECIMAL(,)
        curr = ALPHANUM

Feature File Example

1
2
3
4
5
Feature: ExtractorExample
  Scenario: ExtractorExample
  And extract data with ExampleExtractor from "The current balance: 12,34, currency: EUR; The current balance: 121,67, currency: USD"
  Then verifiy data.bal == 12.34
  Then verifiy data.curr == 'EUR'

In the example above, data holds the value extracted from the String using the ExampleExtractor Extractor. It searches for a sequence of characters after the String balance: appears. This amount is saved in the data variable and can be further used within the scenario context, i.e., by verifying its data.

Note: If the start of the String to extract from is unknown, .* can be used before to state that something else precedes text. For example, .*text: ${content}.

Note: If a Text block consists of several lines and the beginnings of these lines contain whitespace characters, the start of the line has to be stated with a quotation mark ('). ' is only treated as part of a regular expression if it occurs at the beginning of a line.

Example

1
2
3
:
    '^  This line has two whitespace characters at the beginning and
    '    this line has 4$

Predefined Variable Types

Predefined variable types cannot be used in combination with each other.

  • DIGIT - A digit from 0 to 9

    • For example, [0-9]
  • NUMBER - A whole number consisting of one or more digits with an optional - before the number

    • For example, -?DIGIT+
  • DECIMAL(x) - A decimal number with the character x as a separator

    • For example, NUMBER[$x]NUMBER
  • DECIMAL(,) - A decimal number with a , as a separator

    • For example, NUMBER[$,]NUMBER
  • PRICE(x) - A price with the character x as a separator

    • A price has either zero or two decimals
    • For example, NUMBER([$x]DIGIT{2,2})?
  • ALPHANUM - A string consisting of a-z, A-Z and 0-9 characters

    • For example, [a-zA-Z0-9]+
  • DATEDE - Date in German/Austrian format: DIGIT{2}\\.DIGIT{2}\\.(DIGIT{2}\DIGIT{4})

  • DATEEU - Date in official EU format: DIGIT{4}-DIGIT{2}-DIGIT{2}

  • DATEUS - Date in US format: DIGIT{2}/DIGIT{2}/(DIGIT{2}| DIGIT{4})

  • DATEFR - Date in French format: DIGIT{2}/DIGIT{2}/(DIGIT{2}|DIGIT{4})

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Extractor: bill
        An extractor for subscriber bill
        Text:
            The name: ${billName}, expiry date: ${expiryDate}
        Data:
            billName = ALPHANUM
            expiryDate = [0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}
            Extractor: ExampleExtractor
                Extract balance value of Text
                Text:
                    balance: ${bal}
                Data:
                    bal = DECIMAL(,)

The example above searches for the text balance, then filters the amount after this text and identifies it as bal. In the data section, bal is defined as a decimal number separated by a comma. The .* before and after the text indicates that 0 or more characters may be found before balance and after EUR.

Using Regular Expressions

The Extractor uses Java regular expressions (Regex) and can be customized. In the example below three customized sequences of digits and characters are extracted from a String value, and matches the first sequence of characters available.

Feature File Example

1
2
3
4
5
6
7
Feature: ExtractorExample
  Scenario: ExtractorExample
    # Prerequisites
    And extract data with ExampleExtractor from "334,66F44522xWord 789,55X42622 789,55X42622 "
    # The Extractor only matches the first appearing value to be matched.
    Then verify data.test == '334,66F44522xWord'
    Then verify data.test != '789,55X42622'

Extractor Example

1
2
3
4
5
6
7
Extractor: ExampleExtractor
    Get Value
    Text:
        .*Value: ${test}

    Data:
        test = \d+,\d{2}[X]\d{5}[$\\]\w+