Segments API

Get a list of reusable groups of test steps.

List Segments

Returns the segments in your account, including a step-by-step breakdown of each segment's definition.

Request

GET https://api.reflect.run/v1/segments

Query parameters:

  • type (string, required): filter by platform: 'web', 'native-mobile', or 'api'

  • limit (integer, optional)

  • offset (integer, optional)

Response

{
    "count": 42,
    "segments": [
      {
        "id": 12345,
        "name": "Login flow",
        "description": "Logs the test user into the staging environment",
        "steps": [
          {
            "type": "direct-navigation",
            "description": "Go to login page",
            "url": "https://staging.example.com/login"
          },
          {
            "type": "input",
            "selector": "#email",
            "inputText": "qa-user@example.com"
          },
          {
            "type": "input",
            "selector": "#password",
            "inputText": "${var(password)}"
          },
          {
            "type": "click",
            "selector": "button[type=submit]"
          }
        ],
        "parameters": [
          { "name": "password", "value": "${sec(QA_PASSWORD)}" }
        ]
      }
    ]
  }

Create a Segment

Creates a new segment

Request

POST https://api.reflect.run/v1/segments
Web Test segment example request body

{ 
    "name": "Comprehensive Web Test (docs)",  
    "type": "web",  
    "description": "A web test exercising every supported step type with all applicable fields.",  
    "deviceProfile": "desktop",  
    "steps": [    
        { "type": "browser-navigate", "description": "Go to the home page", "url": "https://example.com", "title": "Example Home" },    
        { "type": "segment", "id": 12345 },    
        { "type": "click", "description": "Click the login button", "selector": "#login", "tag": "button", "expectedText": "Log in" },    
        { "type": "visual-validation", "description": "Visually validate the hero section", "selector": ".hero", "tag": "section", "expectedText": "Welcome" },    
        { "type": "text-validation", "description": "Validate the status message text", "selector": ".msg", "tag": "span", "expectedText": "Success" },    
        { "type": "input", "description": "Enter the username", "selector": "#user", "tag": "input", "inputText": "alice", "expectedText": "Username" },    
        { "type": "rich-text-input", "description": "Enter the rich-text body", "selector": "#body", "tag": "div", "inputText": "hello world", "expectedText": "Body" },    
        { "type": "submit", "description": "Submit the form", "selector": "#form", "tag": "form", "expectedText": "Submit" },    
        { "type": "file-upload", "description": "Upload a file", "selector": "#file", "tag": "input", "expectedText": "Choose file" },   
        { "type": "scroll", "description": "Scroll the results list", "selector": ".list", "tag": "ul", "expectedText": "Results" },    
        { "type": "keyboard-shortcut", "description": "Send a keyboard shortcut", "selector": "body", "tag": "body", "inputText": "Ctrl+Shift+a", "expectedText": "Focused" },    
        { "type": "focus", "description": "Focus the email field", "selector": "#email", "tag": "input", "expectedText": "Email" },    
        { "type": "hover", "description": "Hover the menu", "selector": "#menu", "tag": "nav", "expectedText": "Menu" },    
        { "type": "alert", "description": "Accept the browser alert" }, 
        { "type": "drag-and-drop", "description": "Drag an item", "selector": "#item", "tag": "li", "expectedText": "Item" },    
        { "type": "text-highlight", "description": "Highlight a paragraph", "selector": "#para", "tag": "p", "expectedText": "Paragraph"},    
        { "type": "browser-url-changed", "description": "Follow a link", "url": "https://example.com/page3", "title": "Page 3" },    
        { "type": "browser-back", "description": "Navigate back", "title": "Example Home" },    
        { "type": "browser-forward", "description": "Navigate forward", "title": "Page 3" },    
        { "type": "browser-refresh", "description": "Refresh the page", "title": "Page 3" },    
        { "type": "api", "description": "Call an API", "url": "https://api.example.com/orders", "httpMethod": "POST", "requestBody": "{\"a\":1}", "requestHeaders": [ { "name": "Content-Type", "value": "application/json" }, { "name": "Authorization", "value": "Bearer ${var(token)}" } ], "followRedirects": false },    
        { "type": "javascript", "description": "Run a JavaScript snippet", "script": "return document.title;" },    
        { "type": "prompt", "description": "Verify the dashboard loaded", "promptType": "action" },    
        { "type": "prompt", "description": "Is the form valid?", "promptType": "assert", "expectedResponse": true },    
        { "type": "prompt", "description": "What is the order total?", "promptType": "query", "expectedResponse": "42" },    
        { "type": "file-download", "description": "Download the report" },    
        { "type": "update-parameters", "description": "Update run parameters" },    
        { "type": "wait", "description": "Wait for animations", "seconds": 5 },    
        { "type": "receive-email", "description": "Wait for the welcome email", "email": { "text": "Welcome", "filters": { "fromAddress": "noreply@example.com", "fromName": "Example", "subject": "Welcome", "toAddress": "alice@example.com" } } },    
        { "type": "receive-sms", "description": "Wait for the verification code", "sms": { "text": "Your code is 123456", "filters": {"fromNumber": "+15551230000", "toNumber": "+15559876543" } } }  ],  
    "parameters": [    
        { "name": "env", "value": "prod" },    
        { "name": "token", "value": "abc123" }  ]}

API Test segment example request body

{  
    "name": "Comprehensive API Test (docs)",  
    "type": "api",  "description": "An API test exercising every supported step type with all applicable fields.",  
    "steps": [    
        { "type": "segment", "id": 12345 },    
        { "type": "api", "description": "Call an API", "url": "https://api.example.com/orders", "httpMethod": "POST", "requestBody": "{\"a\":1}", "requestHeaders": [ { "name": "Content-Type", "value": "application/json" }, { "name": "Authorization", "value": "Bearer ${var(token)}" } ], "followRedirects": false },    
        { "type": "javascript", "description": "Run a JavaScript snippet", "script": "return 1 + 1;" },    
        { "type": "wait", "description": "Wait between calls", "seconds": 3 },    
        { "type": "update-parameters", "description": "Update run parameters" },    
        { "type": "receive-email", "description": "Wait for a notification email", "email": { "text": "Order created", "filters": { "fromAddress": "noreply@example.com", "fromName": "Example", "subject": "Order", "toAddress": "alice@example.com" } } },    
        { "type": "receive-sms", "description": "Wait for an SMS notification", "sms": { "text": "Order 123 created", "filters": { "fromNumber": "+15551230000", "toNumber": "+15559876543" } } }  ],  
    "parameters": [    
        { "name": "env", "value": "prod" },    
        { "name": "token", "value": "abc123" }  ]}

Native mobile Test segment example request body

{  
    "name": "Comprehensive Mobile Test (docs)",  
    "type": "native-mobile",  
    "description": "A native-mobile test exercising every supported steptype with all applicable fields.",  
    "steps": [    
        { "type": "segment", "id": 12345 },    
        { "type": "prompt", "description": "Tap the login button", "promptType": "action", "expectedResult": "The login screen is shown" },
        { "type": "prompt", "description": "Is the user logged in?", "promptType": "assert", "expectedResponse": true, "expectedResult": "The home screen is shown" },    
        { "type": "prompt", "description": "What is the account balance?", "promptType": "query", "expectedResponse": "100.00", "expectedResult": "The balance is displayed" },    
        { "type": "text-validation", "description": "Validate the greeting text", "expectedText": "Welcome back" },    { "type": "rotate-device", "description": "Rotate the device" },    
        { "type": "set-device-location", "description": "Set the GPS location", "latitude": 37.7749, "longitude": -122.4194 },    
        { "type": "reset-device", "description": "Reset the app state"},    
        { "type": "deeplink", "description": "Open a deeplink", "url": "myapp://home" },    
        { "type": "appium", "description": "Run an Appium command", "command": "scroll", "argument": "{\"direction\":\"down\"}" },    
        { "type": "api", "description": "Call a backend API", "url": "https://api.example.com/orders", "httpMethod": "GET", "requestHeaders":[ { "name": "Accept", "value": "application/json" } ], "followRedirects": true },    
        { "type": "wait", "description": "Wait for the screen", "seconds": 2 },    
        { "type": "update-parameters", "description": "Update run parameters" },    
        { "type": "receive-email", "description": "Wait for the confirmation email", "email": { "text": "Confirmed", "filters": { "fromAddress": "noreply@example.com", "fromName": "Example", "subject": "Confirmation", "toAddress": "alice@example.com" } } },    
        { "type": "receive-sms", "description": "Wait for the verification code", "sms": { "text": "Your code is 123456", "filters": {"fromNumber": "+15551230000", "toNumber": "+15559876543" } } }  ],  
    "parameters": [    
        { "name": "env", "value": "prod" },    
        { "name": "token", "value": "abc123" }  ]}

Request Fields

name (string, required): name of the segment

description (string, optional): segment description

type (string, required): Supported values: web, api, native-mobile

steps: an ordered list of steps

parameters: an optional set of parameters associated with the segment. Each parameter can optionally have a default value

Response

{"id":11}
Publication date: