Modules - Momentic

Documentation Index

Fetch the complete documentation index at: /docs/llms.txt

Use this file to discover all available pages before exploring further.

A module is a named sequence of steps you can call from any test. Use modules to share login flows, setup fixtures, or repeated user journeys.

Modules can’t call other modules.

Editing a module updates every test that uses it.

Example

A module is a YAML file that ends in .module.yaml. Call it from a test on the same platform with a Module step. This example uses a web module; mobile parameter declarations differ as shown under Parameters.

log-in.module.yaml

fileType: momentic/module/v2
id: misty-oak-bridge
name: Log in
parameters:
  - name: USERNAME
    default:
      string: test@example.com
  - name: PASSWORD
steps:
  - type:
      text: "{{ env.USERNAME }}"
      into: Username input
  - type:
      text: "{{ env.PASSWORD }}"
      into: Password input
  - click: Log in

checkout.test.yaml

fileType: momentic/test/v2
id: copper-meadow-kite
url: https://shop.example.com
steps:
  - module:
      path: ../modules/log-in.module.yaml
      inputs:
        USERNAME:
          string: test@example.com
        PASSWORD: env.TEST_PASSWORD
  - act: Add a "Gravity Blanket" to the cart and check out
  - assert: The order confirmation page is shown

Parameters

Parameters let a single module handle different inputs. Web modules declare a list under parameters, then reference the values inside steps via {{ env.PARAM_NAME }} (or env.PARAM_NAME in JavaScript steps).

log-in.module.yaml

fileType: momentic/module/v2
id: misty-oak-bridge
name: Log in
parameters:
  - name: USERNAME
    default:
      string: test@example.com # used when an invocation omits this input
  - name: ROLE
    enum: [admin, member] # restrict the input to a fixed set of values
  - name: PASSWORD # provide this input when calling the module
steps:
  - type:
      text: "{{ env.USERNAME }}"
      into: Email input

Mobile modules use a parameters object. parameterNames declares the inputs, defaultParameters maps names to JavaScript expressions, and parameterEnums maps names to allowed string values. Quote a literal string inside the expression:

log-in.module.yaml

fileType: momentic/mobile-module/v2
id: calm-sparrow-garden
name: Log in
platform: android
parameters:
  parameterNames: [USERNAME, PASSWORD, ROLE]
  defaultParameters:
    USERNAME: '"test@example.com"'
  parameterEnums:
    ROLE: [admin, member]
steps:
  - type:
      text: "{{ env.USERNAME }}"
      into: the Email field
  - type:
      text: "{{ env.PASSWORD }}"
      into: the Password field
  - tap: the Log in button

Defaults vs instance inputs

Each parameter can have a default value on the module and an instance input on a specific Module step. Instance inputs take precedence. Each input value is one of:

checkout.test.yaml

steps:
  - module:
      path: ../modules/log-in.module.yaml
      inputs:
        USERNAME:
          string: alice@example.com # literal, overrides default
        PASSWORD: env.TEST_PASSWORD # JS shorthand reads from the env map

Control flow

Default retries

For web modules, set Default retries under the module’s Control flow tab to retry every invocation of the module a fixed number of times on failure. Invocations that set their own retries value override the module default.Use this for flaky setup modules (e.g. a login module that sometimes fails on slow environments) instead of setting retries on every invocation.

Caching

Web modules are uncached by default and always execute. Enable caching to skip a module when its cache key and inputs are unchanged. Momentic also caches the module’s return value (the return value of its last step). Mobile module calls execute their steps; the module caching fields below apply to web modules.Configure caching with module-level fields:

log-in.module.yaml

fileType: momentic/module/v2
id: misty-oak-bridge
name: Log in
defaultCacheAllInvocations: true # cache every invocation of this module
defaultCacheKey: admin-user # invocations sharing a key reuse the same cache entry
defaultCacheTtl: 3600000 # expire the cache entry after 1 hour (milliseconds)
steps:
  - type:
      text: "{{ env.QA_EMAIL }}"
      into: Email input
  - type:
      text: "{{ env.QA_PASSWORD }}"
      into: Password input
  - click: Log in
  - checkElementVisible: Account menu

Override the key or expiry on a single Module step with cacheConfig:

checkout.test.yaml

steps:
  - module:
      path: ../modules/log-in.module.yaml
      cacheConfig:
        cacheKey: member-user
        cacheExpiryMs: 600000

Authentication modules

Set autoAuth: true (the editor’s Treat as auth module) to save and restore browser auth state between runs. This applies to web tests; mobile modules do not have autoAuth. Momentic persists:

log-in.module.yaml

fileType: momentic/module/v2
id: misty-oak-bridge
name: Log in
autoAuth: true
defaultCacheAllInvocations: true
defaultCacheKey: admin-user
defaultCacheTtl: 3600000
steps:
  - type:
      text: "{{ env.QA_EMAIL }}"
      into: Email input
  - type:
      text: "{{ env.QA_PASSWORD }}"
      into: Password input
  - click: Log in
  - checkElementVisible: Account menu

Set the cache expiry shorter than your session’s expiry. Add a final step that verifies the authenticated state so the cache only saves when login succeeded.

See Authentication strategies and Cache authenticated sessions for the full setup.