Skip to content
QiTASC.com / intaQt Built-ins /
Extractor Built-ins
/ .. /
Extractor Built-ins





Extractor Built-ins

Extractor Built-ins enable using an Extractor from any sub-language. The Extractor is is passed as a string argument using the Extractor Built-ins Extract.get method.

Basic Example With Extractor Built-ins

Extractor Built-ins require an Extractor, a Feature File, and a Stepdef.

1. Basic Extractor Example

The Extractor below extracts the number and currency from a text:

1
2
3
4
5
6
7
8
9
Extractor: testExtractor
  finding the balance

  Text:
    ^your current balance is ${balance} ${currency}$

    Data:
      balance = NUMBER
      currency = [a-zA-Z0-9]+

2. Example Feature File

Data from the Feature File's string "your current balance is 3 dollars" will be extracted according:

1
2
3
Feature: valueExtraction
  Scenario: current balances
    And extract using builtin "your current balance is 3 dollars"

3. Example Stepdef Using Extractor Built-ins

The Stepdef below calls on the testExtractor, whose values are returned using the evaluate method. The println Built-in function is added on the second line to print the results to the log.

1
2
3
4
stepdef "extract using builtin {}" /balancetext/
    data := Extract.get("testExtractor").evaluate(balancetext)
    println(data.balance + " " + data.currency)
end

4. Example Output From Extractor Built-ins

After executing the test case, the following will appear in the intaQt Studio output window:

1
2
3
4
16:04:55.078 [INFO]: Scenario started: current balances
16:04:55.081 [INFO]: Step started: extract using builtin "your current balance is 3 dollars"
16:04:55.183 [INFO]: 3 dollars
16:04:55.184 [INFO]: Step ended with status: passed

Using Extractor Built-ins with LDAP Built-ins

In the example below, a string response from a LDAP search command is passed to the Extractor called MyLdapExtr whose evaluate method returns all extracted data.

Example

1
2
3
r := Ldap("svc").search().binddn("BDN").searchBase("BSE").arg("abc").execute()
extractor := Extract.get("MyLdapExtr")
result := extractor.evaluate(r)

In most use cases, extractors for LDAP responses will work on single lines instead of the entire LDAP response. In the example below, the evaluateOn method splits a given string in lines separated by \r\n (Windows User) or \n (Linux/Mac OS User). The extractor is then applied to every line in sequence and returns a list of matching results.

Example

1
2
3
4
5
6
matches := extractor.evaluateOn(ldapResponse)
for m in matches
    for key, value in m
        println(k + " = " + v)
    end
end

The example above uses evaluateOn and also loops through the matches. Every match is a map that contains the variables defined by the extractor as keys, and the extracted elements as values.

Example Stepdef with Extractor and LDAP Built-ins

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
stepdef "do a LDAP search for {}" / param /
    println("LDAP search: " + param)
    hashExtractor := Extract.get("hash")
    cmd := Ldap.server("myserver")
                .search()
                .arg("phoneid=" + param)
                .arg("groupid")
                .binddn("uid=qitasc,ou=applications,ou=admin,ou=mmo,c=de,o=mycompany")
                .searchBase("ou=subscriber,ou=MMO,c=de,o=mycompany")
    println("=== command ===")
    println(cmd.getCommandAsString())
    result := cmd.execute()
    println("=== result ===")
    println(result)
    matches := hashExtractor.evaluateOn(result)
    for m in matches
        for k,v in m
            println(k + " = " + v)
        end
    end
end

The Stepdef given above produces the following output:

Example Protocol Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2015.06.23 14:00:22.3 Scenario started: do a search
2015.06.23 14:00:22.3 Step started: do a LDAP search for "4912345678912"
2015.06.23 14:00:22.4 LDAP search: 4912345678912
2015.06.23 14:00:22.4 === command ===
2015.06.23 14:00:22.4 ldapsearch -h 192.168.1.1 -p 389 -w qitasc -P 3 -D
                      uid=qitasc,ou=applications,ou=admin,ou=mmo,c=de,o=mycompany
                      -b ou=subscriber,ou=MMO,c=de,o=mycompany phoneid=4912345678912
                      groupid
2015.06.23 14:00:22.9 === result ===
2015.06.23 14:00:22.9 # extended LDIF
#
# LDAPv3
# base <ou=subscriber,ou=MMO,c=de,o=mycompany> with scope subtree
# filter: phoneid=4912345678912
# requesting: groupid
#
# 4912345678912, subscriber, MMO, de, mycompany
dn: phoneid=4912345678912,ou=subscriber,ou=MMO,c=de,o=mycompany
groupid: 123456
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
2015.06.23 14:00:22.9 num = 1
2015.06.23 14:00:22.9 Step ended with status: passed