Orion: A next-generation automation testing tool

Brenda L. Little
9 min readFeb 14, 2021

https://wesovilabs-tools.github.io/orion

Orion is born to help us to write and automate our acceptance tests. It provides a DSL inspired by Gherkin and based in HCL.

The goal of Orion, is to provide people without technical skills a tool to write acceptance tests.

In this article, we will go through some real scenarios to learn how to deal with Orion.

Setup Orion

https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona_0.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona01.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona03.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona04.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona05.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona06.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona07.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona08.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona09.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona09.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona12.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona13.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona14.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona15.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona16.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona17.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona18.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona19.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona20.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-Daytona21.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp43.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp44.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp45.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp46.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp47.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp48.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/V-ideo-daytona-v-jp49.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a01.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a02.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a03.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a04.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a05.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a06.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a07.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a09.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a11.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a12.html
https://www.unitedwaygcr.org/sites/ncsecc.org/files/webform/video-d-v-viv-a14.html

To follow the article I highly recommend you to get Orion installed on your computer. It will take you less than a minute

Installation

manually: Download the pre-compiled binaries from the releases page and copy to the desired location Latest version…

wesovilabs-tools.github.io

Showcase I : math operations

We will write acceptance tests to verify that operation add & subtract work correctly.

Initial approach

We will write a couple of scenarios to verify the below:

  • 10 + 5 = 15
  • 10 -5 = 5
# feature-math-operations.hcldescription = <<EOF
This feature is used to demonstrate that both add and subs
operations work as expected.
EOFscenario "operation add" {
given "the variables x and y" {
set x {
value = 10
}
set y{
value = 5
}
}
when "values are added" {
set result {
value = x + y
}
print {
msg = "${x} + ${y} is ${result}"
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==15
}
}
}scenario "operation substract" {
given "variables x and y" {
set x {
value = 10
}
set y{
value = 5
}
}
when "subtract y to x" {
set result {
value = x - y
}
print {
msg = "${x} - ${y} is ${result}"
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==5
}
}
}orion-cli run --input feature-math-operations.hcl

Hooks

Hooks allow us to write a reusable set of actions that can be executed before or after the scenarios. Visit the Hooks documentation

We’ll use the special hook after each to print the operation result. As a consequence, we can remove the action printin the section when from the scenarios. The hook will be executed after any scenario is completed.

# feature-math-operations.hcldescription = <<EOF
This feature is used to demonstrate that both add and subs
operations work as expected.
EOFafter each {
print {
msg = "the output of this operation is ${result}"
}
}scenario "operation add" {
given "the variables x and y" {
set x {
value = 10
}
set y{
value = 5
}
}
when "values are added" {
set result {
value = x + y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==15
}
}
}scenario "operation substract" {
given "variables x and y" {
set x {
value = 10
}
set y{
value = 5
}
}
when "subtract y to x" {
set result {
value = x - y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==5
}
}
}orion-cli run --input feature-math-operations.hcl

Input variables

A better approach is to execute the same scenarios with different data. We can do this with block input. Visit the Input Variables Documentation

# feature-math-operations.hcldescription = <<EOF
This feature is used to demonstrate that both add and subs
operations work as expected.
EOFinput {
arg x {
default = 10
}
arg y {
default = 5
}
arg sumResult {
default = 15
}
arg subResult {
default = 5
}
}after each {
print {
msg = "the output of this operation is ${result}"
}
}scenario "operation add" {
when "values are added" {
set result {
value = x + y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==sumResult
}
}
}scenario "operation substract" {
when "subtract y to x" {
set result {
value = x - y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==subResult
}
}
}

Since we defined default values for all the args we could just run the features as usual:

orion-cli run --input feature-math-operations.hcl

On the other hand, we can set values for variables, as It’s shown below

# variables-math-operations.hclx = 54
y = 46
sumResult = 100
subResult = 8

and the pass flag --vars

orion-cli run --input feature-math-operations.hcl --vars vars-math-operations.hcl

Skip scenarios

Attribute ignore permits us to skip the execution of a scenario. For example, we can establish that the second scenario is ignored when x>10.

# feature-math-operations.hcldescription = <<EOF
This feature is used to demonstrate that both add and subs
operations work as expected.
EOFinput {
arg x {
default = 10
}
arg y {
default = 5
}
arg sumResult {
default = 15
}
arg subResult {
default = 5
}
}after each {
print {
msg = "the output of this operation is ${result}"
}
}scenario "operation add" {
when "values are added" {
set result {
value = x + y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==sumResult
}
}
}scenario "operation substract" {
ignore = x > 10
when "subtract y to x" {
set result {
value = x - y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==subResult
}
}
}

If we don’t pass the variables file both scenarios will be executed because the default value of x is 10. On the other hand, if we pass the variables file, the second scenario won’t be executed because x is 54.

Includes

We can split the content of our file into several files, and reuse them for different features. Visit the Includes Documentation. For example, we will move the scenarios to separated files.

# scenario-sum.hcl
scenario "operation add" {
when "values are added" {
set result {
value = x + y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==sumResult
}
}
}# scenario-sub.hcl
scenario "operation substract" {
ignore = x > 10
when "subtract y to x" {
set result {
value = x - y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==subResult
}
}
}

and then, we just make use of attribute includes

# feature-math-operations.hcldescription = <<EOF
This feature is used to demonstrate that both add and subs
operations work as expected.
EOFinput {
arg x {
default = 10
}
arg y {
default = 5
}
arg sumResult {
default = 15
}
arg subResult {
default = 5
}
}after each {
print {
msg = "the output of this operation is ${result}"
}
}includes = [
"scenario-sum.hcl",
"scenario-sub.hcl"
]orion-cli run --input feature-math-operations.hcl

Conditional actions

The attribute when allows us to define if the action is executed or not. All the actions have this optional attribute. We make the following change in the second scenario: x-y when x>y, and y-x otherwise

# scenario-sub.hcl
scenario "operation substract" {
when "subtract y to x" {
set result {
value = x - y
when = x > y
}
set result {
value = y - x
when = x <= y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==subResult
}
}
}

if we swap the values of x and y in file vars-math-operations.hcl

# variables-math-operations.hclx = 46 
y = 54
sumResult = 100
subResult = 8

the execution of our scenarios will be successful

orion-cli run --input feature-math-operations.hcl --vars vars-math-operations.hcl

Multiple cases

If you’re experienced working with Cucumber, this will remember to the scenario outline. We just need to define a set of input data in attribute examples in the scenario. For example, we will provide examples for the second scenario.

# scenario-sub.hcl
scenario "operation substract" {
examples = [
{ x = 20, y = 10, subResult= 10},
{ x = 10, y = 20, subResult= 10},
{ x = 5, y = 5, subResult= 0},
]
when "subtract y to x" {
set result {
value = x - y
when = x > y
}
set result {
value = y - x
when = x <= y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==subResult
}
}
}

if we execute Orion, the above scenario will be executed three times.

orion-cli run --input feature-math-operations.hcl

Special action: block

Let’s implement a new scenario to demonstrate how multiplication works. Initially, we could go for something like this

# scenario-mult.hcl
scenario "operation multiplication" {
examples = [
{ x = 20, y = 10, multResult= 10},
{ x = -1, y = -2, multResult= 2},
{ x = 5, y = 5, multResult= 25},
{ x = 5, y = 0, multResult= 0},
]
when "multiply y by x" {
set result {
value = x * y
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==multResult
}
}
}

but I want to show you how the special action block (Documentation here) works. This action is used to group a set of actions. And additionally, we will make use of an attribute count that permits iterate from 0 to count-1.

# scenario-mult.hcl
scenario "operation multiplication" {
examples = [
{ x = 20, y = 10, multResult= 200},
{ x = -1, y = -2, multResult= 2},
{ x = 5, y = 5, multResult= 25},
{ x = 5, y = 0, multResult= 0},
]
given "initialie result" {
set result {
value = 0
}
}
when "multiply y by x" {
block {
set result {
value = result + x
}
print {
msg = "${x} * ${_.index+1} is ${result}"
}
count = y
when = x>0 && y>0
}
set result {
value = x * y
when = x<0 || y<0
}
}
then "the result of the operation is the expected" {
assert {
assertion = result==multResult
}
}
}

And of course, we need to add this file in the include block.

# feature-math-operations.hcldescription = <<EOF
This feature is used to demonstrate that both add and subs
operations work as expected.
EOFinput {
arg x {
default = 10
}
arg y {
default = 5
}
arg sumResult {
default = 15
}
arg subResult {
default = 5
}
}after each {
print {
msg = "the output of this operation is ${result}"
}
}includes = [
"scenario-sum.hcl",
"scenario-sub.hcl",
"scenario-mult.hcl"
]orion-cli run --input feature-math-operations.hcl --vars vars-math-operations.hcl

Beside of when and count there are other special attributes. See the full list here.

Orion is still in beta, hence your suggestions and feedback will be very appreciated!

--

--