Automate Fixturing
During the course of this tutorial you have:
- manually invoked a GitHub workflow to publish pre-canned results
- implemented and executed new test specs from scratch
- used branching when developing new test specs
- learned how to generate and manage GitHub issues in conjuction with a Project Board
This section of the tutorial will be demonstrating the power of automation, integrated into a manual test, using a Suite Fixture based on a Github Action.
This example highlights the built-in automated fixturing for "manual" tests.
Setup
To run a Github Action from Testspace a Github token is required that has "repo" scope
access. This one time only step is required to be added to your Testspace account services.
To run a GitHub automation in Testspace a one time only configuration needs to be done by your Testspace account owner. For details see this on how to enable automation.
Files Used
The following files and their content is used in this section of the tutorial
- Spec file -
use.setup.fixture.md
- GitHub workflow yaml file -
fixture.yml
- JavaScript file -
handler.js
The repo file structure:
root
└─ .github/workflows
└─ fixture.yml
└─ handler.js
└─ specs
└─ manual
└─ use.setup.fixture.md
Reference - https://github.com/testspace-com/testspace.getting-started
Spec
To enable manual automation a front matter block is used at the beginning of the spec
. The header section below defines a before
fixture, which requires successful execution before test cases can be manually executed.
A fixture, named "setup", is used to execute serverless automation, which sets the state of the suite before
manual test case execution begins.
The specs/manual/use.setup.fixture.md
file contains the following content:
---
testspace:
before:
name: github::setup
description: example input
input:
a: one
b: two
---
# Use Setup Fixture
This is a manual test.
## Test Case One
Some description here.
* check this
* check that
## Test Case Two
Some description here.
* check this
* check that
Notes:
- the
name
field is referencing thesetup.yml
workflow file contained in the same GitHub repo - input parameters are optional
- input can also contain files (i.e. json, binary, etc.)
Workflow
In this example, we are using a GitHub Workflow to run handler.js
, which implements the required setup.
The .github/workflows/setup.yml
file contains the following content:
name: Setup
on:
repository_dispatch:
types: [setup]
jobs:
fixture:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- name: Call Script implementing setup fixture
run: node ./.github/workflows/handler.js "$PAYLOAD"
env:
PAYLOAD: ${{ toJson(github.event.client_payload) }}
Notes:
- the
types: [name]
has to match thename
field in the spec front matter (i.e. "setup") - the
client_payload
contains all of the input from the test spec
Handler
In our example, a generic handler will be implemented in JavaScript, but the concept applies to all languages supported by GitHub Actions.
The generic handler being used simply logs the input
parameters.
The .github/workflows/handler.js
file contains the following content:
function handler(payload) {
var input = JSON.parse(payload);
console.log("Input: ", input.a, input.b);
}
handler(process.argv[2]);
Notes:
- The
payload
is converted to a JavaScript object - The
payload
is passed on the command line as the 2nd parameter
Execute
The current test specs listing reflects the status of previous sessions and the new Use Setup Fixture
suite (defined in specs/manual/use.setup.fixture.md
spec file).
To run the Use Setup Fixture
test spec a New Test Session
will need to be created.
Session
The next step is to create a new session using the New Test Session
button. The following dialog will be presented:
Run
To execute the Use Setup Fixture
click on it. There will be a Required automation bar presented asking to be performed before any test case can be executed.
Click on the blue ►
button to trigger the automation. While running a blue ○
spinning icon will appear, which should turn into a green √
icon to reflect success.
At this point, all test cases
can be executed. Once the selected cases have been executed, the session can be completed and any teardown fixures would execute as well.
Recap
Testspace supports integrating automation with manual testing. The following are some key benefits:
- Reduce manual execution time. Fixturing can leverage automation for tedious and redundant setup/teardown requirements versus human execution.
- Deploy "hybrid testing" leveraging automation and human observations.
- Minimize IT setup for Human testers. All testing, including automation, is executed in the context of a web browser.
- Maintain test specs and automation in the same repo.