Contents

shibapm/capriccio

Capriccio is a tool to generate UI Tests from gherkins `.feature` files.

Command line options

  • --excluded-tags - The list of excluded tags separated by a comma
  • --included-tags - The list of included tags separated by a comma
  • --class-type [default: XCTestCase] - The class type of the generated class
  • --single-file - Generates a single swift file with the content of all the feature files
  • --disable-swiflint - Disables swiftlint on the file
  • --template-file - Path to the stencil template file

Configuration file

Instead of CLI arguments you can use .capriccio.yml configuration file:

source: <source path>
output: <destination path>
template: <template path>
excludedTags:
    - <string value>
    - <string value>
includedTags:
    - <string value>
    - <string value>
classType: <string value>
singleFile: <bool value>
disableSwiftLint: <bool value>

Personalise setUp and tearDown

Your UI Tests will probably need to do something that is specific to your code base before and after every test. In order to allow Capriccio to support all this needs you can use the -c or --class-type option. This allows you to create a generic class that you can use as superclass for all the generated classes.

e.g.

class GherkinTestCase: XCTestCase {
    var mockedServer: MockedServer
    var stepDefinition: StepDefinitions!
    var application: App!

    override func setUp() {
        super.setUp()
        mockedServer = MockedServer()
        mockedServer.start()
        
        stepDefinition = StepDefinitions(testCase: self)

        application = App()
        application.launch()
    }

    override func tearDown() {
        mockedServer.stop()
        application.terminate()
        super.tearDown()
    }
}

Then if you run:

capriccio source destination -c GherkinTestCase

All the generated classes will be a subclass of GherkinTestCase instead of a subclass of XCTestCase

Scenario outline

Capriccio creates a different test for each example.

e.g.

Feature: Feature number one

Scenario Outline: Scenario I want to  test
Given I'm in a situation
When something happens <key1>
Then something else happens <key2>
Examples:
| key1 | key2 |
| value1 | value2 |
| value3 | value4 |

Generates:

import XCTest
import XCTest_Gherkin

final class FeatureNumberOne: XCTestCase {
    func testScenarioIWantToTestWithValue1AndValue2() {
        Given("I'm in a situation")
        When("Something happens value1")
        Then("Something else happens value2")
    }
        
    func testScenarioIWantToTestWithValue3AndValue4() {
        Given("I'm in a situation")
        When("Something happens value3")
        Then("Something else happens value4")
    }
}

Create your own template

Check our Model class to see which properties you can use on your Stencil template.

Package Metadata

Repository: shibapm/capriccio

Default branch: master

README: README.md