Custom host aliases

Mobitru supports playwright browser session’s custom host aliases, which allows using custom hostname:IP pairs in tests.
This feature is available for all browsers.

Enable in tests

To start using the custom host aliases, it’s necessary to add the host parameter to a WebSocket endpoint.
The parameter should contain item(s) with hostname:IP pair like example.com:1.1.1.1:
Important note: the WebSocket endpoint should be encoded to avoid issues with processing of the parameters.
Below you can find an example for different programming languages:

const playwright = require('playwright-core');

const mobitruHost = "browserhub-us.mobitru.com";
const mobitruTeamCode = "<TEAM_CODE>";
const mobitruAccessToken = "mobitru_ak...";
const pwVersion = "1.55.0";
const mobitruLandingUrl = 'https://mobitru.com/';
const browserName = 'chrome';


    test.describe(`Demo test`, () => {
       ....

        test.beforeAll(async ({}, testInfo) => {
            const wsEndpoint = `wss://${mobitruTeamCode}:${mobitruAccessToken}@${mobitruHost}/playwright/${browserName}/playwright-${pwVersion}?env=DISPLAY%3D127.0.0.1:0&host=example.com:99.80.6.196`;
        
            ....
        });
        
       ....
private static final String PROJECT_NAME = "<TEAM_CODE>";
private static final String API_KEY = "mobitru_ak_...";
private static final String BROWSER_HUB = "browserhub-us.mobitru.com";
private static final String BROWSER_NAME = "chrome";
private static final String PW_VERSION = "1.54.0";

@Test
public void demoTest() {
        String wsEndpoint = String.format("wss://%s:%s@%s/playwright/%s/playwright-%s?env=DISPLAY%%3D127.0.0.1:0&host%%3Dexample.com%%3A99.80.6.196",
                PROJECT_NAME, API_KEY, BROWSER_HUB, BROWSER_NAME, PW_VERSION);

        ....
    }
import pytest

from playwright.sync_api import sync_playwright, Page, expect

BILLING_UNIT = '<TEAM_CODE>'
ACCESS_TOKEN = 'mobitru_ak_...'
MOBITRU_HOST = 'browserhub-us.mobitru.com'
BROWSER_NAME = 'chrome'
PW_VERSION = '1.55.0'


@pytest.fixture(scope="function")
def mobitru_page(request):
    with sync_playwright() as playwright:
        chromium = playwright.chromium
        ws_endpoint = f"wss://{BILLING_UNIT}:{ACCESS_TOKEN}@{MOBITRU_HOST}/playwright/{BROWSER_NAME}/playwright-{PW_VERSION}?host%3Dexample.com%3A99.80.6.196"
        ....        

private const string PROJECT_NAME = "<TEAM_CODE>";
private const string API_KEY = "mobitru_ak_....";
private const string BROWSER_HUB = "browserhub-us.mobitru.com";
private const string BROWSER_NAME = "chrome";
private const string PW_VERSION = "1.55.0";

[Test]
public void DemoTest()
{
    string wsEndpoint = $"wss://{PROJECT_NAME}:{API_KEY}@{BROWSER_HUB}/playwright/{BROWSER_NAME}/playwright-{PW_VERSION}?host%3Dexample.com%3A99.80.6.196";
    ....
}

Scroll to Top