Skip to content
QiTASC.com / General Concepts /
Step Definitions and Parameters
/ .. /
Step Definitions and Parameters





Step Definitions and Parameters

A Step Definition is similar to a function definition. Custom Step Definitions can be created in UI Steps or Steps files. The Feature File calls the Step and passes optional parameters. In addition to describing Stepdef syntax, this section contains information on six different types of parameters that can be used within the Stepdefs:

  • Standard Parameters ({})

  • Identifier Parameters ({ident})

  • Phone Tag Parameters (phonetag)

  • List Parameters ({list})

  • Raw Parameters ({raw})

For specific instructions and examples of defining custom steps with intaQt languages, refer to the respective language section:

Step Definitions and Parameters
Step Definitions
Stepdef Parameters
Standard Parameters
Adding Annotations with Parameters for intaQt Steps Language
String Parameters
String Parameters - Identifiers {ident}
String Parameters - Raw ({rawparameters})
Phone Tags List Parameters {phoneTags}
Phone Tag Parameters {phonetag}
List Parameters {list}

Step Definitions

A Step Definition is defined in a Steps or UI Steps file and may also include Models and/or Functions. When using the associated step in a Feature File, the step must match its Stepdef in terms of wording and optional parameters.

Step Definitions Without Parameters

Syntax

1
2
3
stepdef <definitionOfAStep Identifier>
    BLOCK
end

Parameter

  • definitionOfAStep - The step's string representation that describes what the step does

Example

1
2
3
stepdef "print the number 123 to the protocol"
    println("123")
end

In order for the Feature File below to run successfully, the step must contain the exact wording of the Step Definition example from above:

1
  And print the number 123 to the protocol

Stepdef With Optional Parameters

Stepdefs may pass additional parameters.

Syntax

1
2
3
4
5
stepdef <definitionOfAStep Identifier {<parameter1 ParameterType>} ...
    {parameterN ParameterType}> /<parameterDescription1 Identifier>/, ... ,
    /<parameterDescriptionN Identifier> /
    BLOCK
end

Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameter - A parameter used to represent expected input data that is defined in the Feature File

    • May be one of {}, {ident}, {phoneTag}, {phoneTags} or {list}
  • parameterDescription - The parameter's identifier

Example

1
2
3
stepdef "print the country code of ip {} into the protocol" / ipAddress /
    println("country code of ip: "  + ipAdress)
end

If the example above is used in the following Feature File below, the Feature File's step calls a parameter called ipAddress and its value ("192.168.1.1") is entered in the Feature File:

1
And print the country code of ip "192.168.1.1" into the protocol

Stepdef Parameters

Stepdef Parameters' values are defined within the Feature File. This allows the Stepdefs to be used across multiple scenarios while only changing the parameter's value itself. The specified content or value is stored in the respective argument that follows the Step Definition.

The parameters' positions within a Stepdef are indicated by curly braces ({}) and may include optional tags. Six types of parameters are available:

  • Standard (Default) Parameters indicated with {}

  • Identifier Parameters indicated with {ident}

  • Phone Tag Parameters indicated with {phoneTag}

  • Phone Tag List Parameters indicated with {phoneTags}

  • List Parameters indicated with {list}

  • Raw Parameters indicated with {raw}

Important!

  • It is recommended to create a unique step identifier in order to prevent that a custom step conflicts with one of intaQt's Steps and Compound Steps or intaQt Built-ins.

  • Stepdef Parameters are currently an experimental feature and their names and functionality may change in the future.

Standard Parameters {}

Standard Parameters are evaluated before being passed on to the Stepdef code. They may include arbitrary expressions.

Syntax

1
2
3
4
stepdef <definitionOfAStep Identifier {},... /<parameter1 Identifier> /,... ,
    /<parameterN Identifier>/
    BLOCK
end

Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameterN - The parameter's identifier

Example

1
2
3
stepdef "output {}" / param /
    println("Parameter is " + param)
end

Feature File Example

1
And output x + 7

The example above assumes that the scenario execution context contains a variable called x which is added to 7 to yield the result that is passed with the name param to the Stepdef code. For example, If x = 12, the result 12+7=19 is passed as param to the Stepdef. Additionally, "Parameter is 19.0" will be printed to the log.

Note: When executing a Feature File, references to Variables or Context Objects are evaluated against the scenario execution context. If variable does not exist, a Stepdef invocation error will occur.

Adding Annotations with Parameters for intaQt Steps Language

Adding MetaData annotations enables the addition of additional information to the report during the test execution. The information is evaluated and only added when the correspondent step has been successfully executed.

Syntax

1
@MetaData(name : <String>, value : <String>[, level : <String>])

Parameters

  • name - The metadata's key

  • value - The metadata's value

    • The value is evaluated as an expression using Context Objects
  • level (Optional) - The metadata's level

    • Default value is set to Step
    • Must be on of: Step, Scenario or Feature

Example

1
2
3
4
5
6
@MetaData(name : "Test Data", value : "a: ${a}, b: ${b}", level : "Scenario")
@MetaData(name : "Test Result", value : "${result}")
stepdef "whatever {} else {}" / a, b /
    addContextObject("a", a)
    addContextObject("b", b)
end

In the example above, the custom Stepdef will create two metadata instances after its execution is finished:

  • The first will be appended to Scenario level metadata with key "Test Data" and value "a: a, b: b", because ${a} and ${b} evaluate to a and b correspondingly.

  • The second will be appended to Step-level metadata with key "Test Result" and a value that evaluated to a Context Object referenced by the key result.

String Parameters

String Parameters are treated like a standard Stepdef parameter argument marker, except that the values of the {ident} and {raw} arguments are not evaluated before passing them to the Stepdef body. An additional example is shown in Custom Compound Steps With Steps.

Two types of String Parameters exist: {ident} parameters, which only match Identifiers and {raw} parameters, which match everything.

String Parameters Identifiers {ident}

A parameter with the {ident} marker assumes an Identifier, such as a phone (for example, phoneA) or an event name (for example, MYCALL). The name assigned to the parameter must start with an alphabetic character (such as a-z, A-Z). All other characters must be alphanumeric. An underscore (_) may also be used, but should be avoided.

{ident} parameters may also be treated as {raw} parameters by activating Legacy Configurations.

Syntax

1
2
3
4
stepdef <definitionOfAStep Identifier {ident}, ... {ident}
    /<parameterDescription Identifier>/, ... /<parameterN Identifier> /
    BLOCK
end

Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameterN - The name assigned to the {ident} parameter

Example

1
2
3
stepdef "output {ident}" / param /
    println("Parameter is " + param)
end

Feature File Example

1
And output x + 7

The call And output x + 7 passes the string "x + 7" on to the Stepdef code. No evaluation is done, for example, the scenario execution context is not accessed by parameters carrying the {ident} marker. "Parameter is x + 7" will be printed to the log.

String Parameters Raw {raw}

A parameter with the {raw} marker matches anything. It may start with any character.

Note: In early intaQt versions, {ident} parameters were treated as {raw} and also matched everything. This behavior can be activated in Legacy Configurations.

Syntax

1
2
3
4
stepdef <definitionOfAStep Identifier {raw}, ... {raw}
    /<parameterDescription Identifier>/, ... /<parameterN Identifier> /
    BLOCK
end

Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameterN - The name assigned to the {raw} parameter

Example

1
2
3
stepdef "execute this with {raw}" / param /
    println("=====> " + param)
end

Phone Tags List Parameters {phoneTags}

A parameter with the {phoneTags} (plural) marker assumes a list of Phone Identifiers separated by commas (,) or the keyword and. For every Identifier, a VirtualPhone is implicitly created in the scenario execution context. Accessing virtual phones is further described within the examples below.

Syntax

1
2
3
4
stepdef <definitionOfAStep Identifier {phoneTags}:, ... {phoneTags}
    /<parameterDescription Identifier>/, ... /<parameterN Identifier> /
    BLOCK
end

Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameterN - The name assigned to the {phoneTags} parameter

Example

 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
27
stepdef "phones with phoneTags as {phoneTags}" / ids /
    println("ids= " + ids)

    for phoneId in ids
        virtualPhone := getContextObject(phoneId)
        println("virtual phone id= " + virtualPhone.id)
        virtualPhone.props["hello"] := "world"

        VirtualPhoneHelpers.showPropsOfVirtualPhone(virtualPhone)
    end

end

model VirtualPhoneHelpers
    func showPropsOfVirtualPhone(v)
        println("Properties of virtual phone " + v.id)
        printMap(v.props)
    end

    func printMap(map)
        for k, v in map
            if v != null then
                println(k + "= " + v)
            end
        end
    end
end

In this example, the first parameter of the Stepdef ids is a list of phone tags. If used in the Feature File below:

1
2
Given phones as A, B and C:
  * of type Android

When executed, three virtual phones A, B, C are created in the scenario execution context. These virtual phones can be reused in other custom telephony Stepdef implementations. The parameter ids passed to the Stepdef consists of a list of three strings, A, B, C.

Phone Tag Parameters {phoneTag}

The {phoneTag} (singular) parameters behave like {phoneTags} but instead of a list, only a single element is provided. A single virtual phone is implicitly created in the scenario execution context.

Syntax

1
2
3
4
stepdef <definitionOfAStep Identifier {phoneTag}:, ... {phoneTag}
    /<parameterDescription Identifier>/, ... /<parameterN Identifier> /
    BLOCK
end
Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameterN - The name assigned to the {phoneTag} parameter

Example

 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
stepdef "phones with phoneTag as {phoneTag}" / ids /
    println("ids= " + ids)
    for phoneId in ids
        virtualPhone := getContextObject(phoneId)
        println("virtual phone id= " + virtualPhone.id)
        virtualPhone.props["hello"] := "world"

        VirtualPhoneHelpers.showPropsOfVirtualPhone(virtualPhone)
    end
end

model VirtualPhoneHelpers
    func showPropsOfVirtualPhone(v)
        println("Properties of virtual phone " + v.id)
        printMap(v.props)
    end

    func printMap(map)
        for k, v in map
            if v != null then
                println(k + "= " + v)
            end
        end
    end
end

If used in the Feature File below:

1
2
Given a phone with phoneTag as A:
  * of type Android

A single element is created such as:

1
2
3
4
5
virtual phone id= A
Properties of virtual phone A
hello= world
virtual phone id= B
Properties of virtual phone B

List Parameters {list}

The {list} parameter type yields a List of objects that is passed as a single parameter to the Stepdef. Before being passed on, the List is evaluated. This means it can consist of arbitrary expressions referring to the scenario execution context.

The List elements can be separated by commas or the keyword and. If using and as a boolean operator, the corresponding element expression must be enclosed in parentheses.

Syntax

1
2
3
4
stepdef <definitionOfAStep Identifier {list}:, ... {list}
    /<parameterDescription Identifier>/, ... /<parameterN Identifier> /
    BLOCK
end
Parameters

  • definitionOfAStep - The step's string representation that describes what the step does

  • parameterN - The name assigned to the {list} parameter

Example

1
2
3
4
5
stepdef "print the list {list}" / param /
    for el in param
        println("" + el)
    end
end

Feature File With Parentheses around Boolean Expression Example

1
And print the list 1,  (true and false), "abc" and 23 +3, 22

The example above creates a list, [1, false, "abc", 26, 22], and passes it with the name param to the Stepdef.

Feature File Without Parentheses around Boolean Expression Example

1
And print the list 1,  (true and false), "abc" and 23 +3, 22

In the example above, the and between true and false is interpreted as a list element delimiter, so param is [1, true, false, "abc", 26, 22].