Automating Profile Creation with Sessionbox using Selenium

Edited

We recommend using our official Node.js SDK for the best experience. Check out our examples and SDK documentation to get started.

SessionBox One offers a local API to automate your tasks. You can check the API documentation here: Local API Documentation

In this guide, we’ll discuss the process of creating new profiles with Sessionbox through Selenium automation, without using official SDK.

Overview

  1. Acquire an action token, which is a unique identifier used to create Sessionbox profiles.

  2. Convert this token into a usable URL

  3. Direct the Selenium driver to the newly generated URL

Before you begin:

  • Ensure that the Sessionbox One app is installed.

  • Confirm that the Sessionbox extension has been integrated with your Selenium webdriver instance. If you are not sure how to integrate the extension, please refer back to this article.

Step by step guide

To initiate profile creation, first, you will need to obtain an action token. Dispatch a POST request to the endpoint at  localhost:54789/local-api/v1/action-token. 

Ensure the following parameters are included in the request payload:

  • API key: To access your api key, navigate to ‘Settings’ Sessionbox One and locate your API key at the bottom. If you did not already, you can generate an API key here.

  • Session Type: either ‘temp’, ‘cloud’ or ‘local’

  • Target URL: the url intended for session initiation

Here is a practical example using Javascript:

const response = await fetch("http://localhost:54789/local-api/v1/action-token", {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`
    },
    body: JSON.stringify({
        action: 'temp', 
        url: 'www.google.com'
    })
});

Following this, extract the token from the received response and construct a URL using this token. Your constructed URL should have the following format:

https://open.sessionbox.dev?sbo_token={token}

Once you have the URL, direct your selenium webdriver - equipped with the Sessionbox extension - to this address. The webdriver will open the specified target URL within a fresh Sessionbox profile.