Create your own test specification
Now that you understand how to create and run a Gauge project, it is time to create your own test specifications. We’ll start by looking at what a sample test specification looks like in Gauge.
In this example, we’ll be using screenshots and examples from the VS Code interface. You can use the Gauge plugins for Intellij and Visual Studio or use any other editor to edit specifications.
Improve your authoring experience with VS Code
We recommend that you download and use the Gauge VS Code plugin. Using the plugin will enhance your authoring experience with Gauge.
The best way to do this, is to open your project gaugetest in VS Code. As soon as you do this, you’ll be prompted by VS Code to install recommendations. Choose to ‘Install All’ and you’re all set to start using the plugin to create specifications.
You can also install the VS Code plugin in the command line by following the instructions.
Understand the Gauge test specification
A test specification (spec) is a detailed statement of what will be tested. In Gauge, these are written in a .spec file.
The Gauge specification file is present under /specs/example.spec. Here’s what a typical specification looks like.
There are 3 basic concepts to keep in mind for writing a Gauge test.
- 1 Specification
- 2 Scenario
- 3 Step
A specification or spec must begin with a spec heading and a single specification file can contain only one spec heading. It is written in <H1> syntax of markdown.
Every spec contains one or more scenarios.
Each scenario represents a single business flow.
A specification can have multiple scenarios. The scenario heading is written in markdown <H2> syntax.
A scenario contains one or more steps under it.
Steps are the executable components of your specification.
They are written as markdown unordered list items (bulleted points). The values written in quotes are parameters which are passed into the underlying step implementation as a language specific structure.
You will also be able to see Run and Debug options on hovering over the Spec or Scenario heading with the Gauge plugin. If you’ve installed the plugin and do not see this option, try reloading the plugin and then reopening the project.
Every step has an underlying code implementation for the programming language used. To see the code behind the step, right click a step to ‘Go to Definition’.
This is possible with a single click using the Gauge plugin. If you don’t have the plugin installed, you’ll have to navigate to /tests/step_implementation.js to see the definition of the steps.
This is an example of the code implementation behind the step. We have used Taiko to create the scripts for this Gauge project. You can use Taiko or a web driver of your choice (Selenium, Sahi) to create your automation tests. To learn how to create scripts with Taiko, you can check out Taiko's getting started guide.
Once you’ve made edits, you can run your Gauge specs in VS Code by choosing the option to ‘Run Spec’ on hovering over the specification heading. If you don’t have the plugin, you can use this command
gauge run specs
Now you’re ready to start creating your own test specifications.
Want updates about Gauge releases?
Subscribe to the Gauge Release Bulletin for monthly email updates on the latest Gauge releases.