Are you sure you want to delete this access key?
A browser automation example demonstrating how to test web applications using Playwright.
You can run this example with:
npx promptfoo@latest init --example headless-browser
This example demonstrates how to:
Ensure you have Python 3 and Node.js installed on your system.
npm install playwright @playwright/browser-chromium playwright-extra puppeteer-extra-plugin-stealth
pip install -r requirements.txt
That's it! No additional setup scripts or configuration needed.
python gradio_demo.py
This starts a local server at http://localhost:7860
npx promptfoo@latest eval -c promptfooconfig.yaml
npx promptfoo@latest view
The main configuration (promptfooconfig.yaml
) tests a chatbot interface with a 100% pass rate:
┌─────────────────────────────────────────────────┬─────────────────────────────────────────────────┐
│ topic │ [browser-provider] Tell me about {{topic}} │
├─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ testing browser automation │ [PASS] Test successful! The browser automation │
│ │ is working correctly. │
├─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ how the system works │ [PASS] I received your message: 'Tell me about │
│ │ how the system works'. This is a simple demo │
│ │ response! │
├─────────────────────────────────────────────────┼─────────────────────────────────────────────────┤
│ a simple greeting │ [PASS] I received your message: 'Tell me about │
│ │ a simple greeting'. This is a simple demo │
│ │ response! │
└─────────────────────────────────────────────────┴─────────────────────────────────────────────────┘
The calculator-example.yaml
demonstrates form interactions with a 100% pass rate:
┌───────────────────┬───────────────────┬───────────────────┬───────────────────┬───────────────────┐
│ num1 │ num2 │ operation │ operationSelector │ [browser-provider]│
├───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 10 │ 5 │ Add │ #operation │ [PASS] Calculator │
│ │ │ │ label:nth-child(1)│ interaction │
│ │ │ │ │ successful │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 20 │ 4 │ Multiply │ #operation │ [PASS] Calculator │
│ │ │ │ label:nth-child(3)│ interaction │
│ │ │ │ │ successful │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┴───────────────────┘
This example demonstrates:
The example configurations demonstrate key concepts:
transformResponse
for data extractionThe Gradio application provides consistent selectors:
textarea[data-testid="textbox"]
- Message input fieldbutton#submit-button
- Submit buttondiv[data-testid="bot"]:last-of-type .prose
- Latest bot responsebutton[value="calculator"]
- Calculator tab buttoninput[type="radio"]
- Operation selectionurl
in the navigation stepFor single-page applications or AJAX content:
- action: waitForNewChildren
args:
parentSelector: '#results-container'
timeout: 10000
Chain multiple actions for sophisticated workflows:
steps:
- action: navigate
args:
url: 'http://localhost:3000'
- action: click
args:
selector: '#menu-button'
- action: wait
args:
ms: 1000
- action: click
args:
selector: '#dropdown-option-2'
Issue | Solution |
---|---|
Elements not found | Use browser DevTools to verify selectors |
Timing issues | Increase wait times or use waitForNewChildren |
Want to see the browser | Set headless: false in the configuration |
Need detailed logs | Run with npx promptfoo@latest eval --verbose |
Press p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?