# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: 'Testing browser automation with local Gradio app'

prompts:
  - 'Tell me about {{topic}}'

providers:
  - id: browser
    config:
      headless: false # set to false to see the browser in action
      steps:
        # Always start with a respectful delay
        - action: wait
          args:
            ms: 2000

        # Navigate to local Gradio app
        - action: navigate
          args:
            url: 'http://localhost:7860'

        # Wait for the page to load
        - action: wait
          args:
            ms: 2000

        # Type the message in the Gradio textbox
        - action: type
          args:
            selector: 'textarea[data-testid="textbox"]'
            text: '{{prompt}}'

        # Submit the message
        - action: click
          args:
            selector: 'button#submit-button'

        # Wait for the response with reasonable timeout
        - action: wait
          args:
            ms: 3000

        # Extract the bot's response from the chatbot - get the last message
        - action: extract
          args:
            selector: 'div[data-testid="bot"]:last-of-type .prose'
          name: response

      transformResponse: 'extracted.response'

tests:
  - vars:
      topic: testing browser automation
    assert:
      - type: contains
        value: 'Test successful'

  - vars:
      topic: how the system works
    assert:
      - type: contains
        value: 'simple demo response'

  - vars:
      topic: a simple greeting
    assert:
      - type: javascript
        value: output.length > 0
