---
title: Puppeteer Mark Test Status | TestingBot
description: Mark Puppeteer tests as passed or failed on TestingBot from inside your
  test using the testingbot_executor command, or via the REST API after the run. Set
  test status, name and build for the dashboard.
source_url:
  html: https://testingbot.com/support/web-automate/puppeteer/mark-test-status
  md: https://testingbot.com/support/web-automate/puppeteer/mark-test-status/index.md
---
# Mark test status with Puppeteer

The Puppeteer tests you run on TestingBot are using the `CDP` protocol to send commands to a remote browser. These commands instruct the remote browser what to do: click, type, resize, ...

Because the logic of your test cases is inside your test script, TestingBot has no way of knowing if a test failed or passed.   
 There is a way to send back the test status to TestingBot, by including a code snippet at the end of your test, where you know whether the test passed or failed.

Below we'll go over two methods to send back the test status to TestingBot, so that we can show the pass/failure state in the dashboard and in the [TestingBot analytics](https://testingbot.com/support/analytics/guide).

## Mark test status from within a test script

TestingBot has created a custom Puppeteer command which you can use in your Puppeteer scripts. You can pass in a `boolean` to indicate whether the test **passed** or **failed**.

    await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({action: 'setSessionStatus',arguments: { passed: false, reason: 'Title did not match' }})}`)

This command will set the test as failed, with a specific reason which will be visible on the TestingBot test detail page.

You can pass in the reason for a failure with the `reason` field.

This command will return a JSON object with the `sessionId` of the test, which can be used with our [REST-API](https://testingbot.com/support/api).

You would typically call this at the end of each test, where you know if the test failed or passed. For example, see the code snippet below where we use `chai's expect` to verify if the test passed or not.

    const puppeteer = require('puppeteer-core')
    const expect = require('chai').expect
    
    (async () => {
        const browser = await puppeteer.connect({
            browserWSEndpoint: 'wss://cloud.testingbot.com?key=API_KEY&secret=API_SECRET&browserName=chrome&browserVersion=latest&platform=WIN11'
        })
        const page = await browser.newPage()
    
        await page.goto('https://testingbot.com/')
        const title = await page.title()
    
        try {
            expect(title).to.equal("Cross Browser Testing and Mobile App Testing. Test on web browsers, mobile emulators, simulators and physical mobile devices.", 'Expected page title is incorrect!')
            // This is ok, so mark the test as passed
            await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({action: 'setSessionStatus',arguments: {passed: true, reason: 'Title matched'}})}`)
          } catch {
            // Test failed, mark the test as failed on TestingBot
            await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({action: 'setSessionStatus',arguments: {passed: false, reason: 'Title did not match'}})}`)
          }
        await browser.close()
    })()

## Mark test status with API

You can fetch the `sessionId` during an active Puppeteer test. This unique id can be used during or after the test to set the pass/fail state for the test.

Marking the test as passed or failed will show the success state in the TestingBot test dashboard, on the individual test detail page and in the [TestingBot analytics](https://testingbot.com/support/analytics/guide) pages.

To fetch the `sessionId`, please use the sample code below.

    const testingBotResponse = await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({action: 'getSessionDetails'})}`)

The `testingBotResponse` variable will contain a `sessionId` property which you can use:

    {
        "sessionId": "......"
    }

With the `sessionId`, you can now mark the test as passed or failed via the [TestingBot REST-API](https://testingbot.com/support/api):

    curl "https://api.testingbot.com/v1/tests/:sessionId" \
    -X PUT \
    -d "test[success]=1" \
    -u API_KEY:API_SECRET

Learn more about this API call and other API calls on the TestingBot [API documentation](https://testingbot.com/support/api).

Was this page helpful? Yes No 

## Looking for More Help?

Have questions or need more information?   
 You can reach us via the following channels:

- [Email us](https://testingbot.com/contact/new)
- [Join our Slack Channel](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
