Writing Tests

January 22, 2023 ยท View on GitHub

Feature Files

Cytorus uses cucumon to parse feature file. It means you can write feature files Gherkin syntax with some additional features.

#!
Feature: I can order a Pizza

Rule: Explore available products

Scenario: Display Trendy Pizzas
    #> route: home page; story: US002
    Given I'm on home page
    Then I should see the top selling pizzas

@wip
Scenario: Display Side dishes
    #> route: home page; story: US001
    Given I'm on home page
    Then I should see the list of side dishes

Rule: Find relevant products

@skip
Scenario: Search for a pizza
    #> story: US003
    Given I'm on any page
    When I search for "cheese"
    Then it should result all pizzas
    When I search for "mushroom"
    Then it should result following pizzas
    #>[]
    | Farm House |
    | Deluxe Veggie |
    | Veg Extravaganza |

Rule: Create a cart

Scenario: Make an order from home page
    #> route: home page; story: US004
    Given I'm on home page
    #Save order detail in scenario context
    When I add following items in the cart
    #> {}
    | pizza | Farm House  |
    | extra_toppings   | onion,paneer |
    #Validate the cart from the order detail in scenario context
    Then I can see the cart with selected items
  • #! in the starting of the file to skip the file from processing
  • #> route: ... will help to run tests for a particular page or from a particular page.
  • #> story: ... will help to run tests for a particular user story
  • #>[] To transform a data table into and array for better readability and accessibility in the code. Followings are supported;
    • #>[]: To array
    • #>{}: To Object
    • #>[{}]: To list of objects

Step Definitions

You can write step definition in any js files inside cypress/integration folder. You can use string, cucumber expression or regular expression for a step definition.

/// <reference types="cypress" />

//import { Given, When, Then, And, But, step} from "cytorus/src/Globals"

Given("This is normal string", function () {
});

When("This is cucumber expression with {parameter}", function (parameter){
});

step(/you can also use regex "(.*)"/, (parameter) => {
});

For better performance

  • If possible, use string to create a step definitions.
step("This is a string", () => {})
  • If you're using regex, then use ^ in starting.
step(/^This is a (.*)/, () => {})

> Next : Scenario Context