This repo shows how to run behave tests on BrowserStack using the BrowserStack Python SDK and Playwright Python. The SDK handles capability injection, BrowserStack routing for Playwright launches, parallelization, and BrowserStack Local for you — you describe platforms once in browserstack.yml and run the test command unchanged.
- Clone this repo
- Install dependencies (creates the BrowserStack SDK CLI on
PATHand downloads Playwright Chromium)pip install -r requirements.txt playwright install chromium
- Set
BROWSERSTACK_USERNAMEandBROWSERSTACK_ACCESS_KEYas environment variables, or replaceuserNameandaccessKeydirectly inbrowserstack.ymlwith your BrowserStack Username and Access Key. Env vars take precedence.
There are two sample scenarios in features/:
features/sample.feature— driveshttps://www.bstackdemo.com(a public site) and adds a product to the cart.features/local.feature— driveshttp://bs-local.com:45454/through the BrowserStack Local tunnel; verifies the page title contains "BrowserStack Local".
browserstack.yml enables browserstackLocal: true, so the SDK starts and stops the BrowserStack Local tunnel for you on every run — no manual binary lifecycle.
Runs in parallel across the 3 Playwright browser engines (chromium / firefox / webkit) declared in browserstack.yml:
browserstack-sdk behave features/sample.featureStart a local HTTP server first — features/local-html/ contains a tiny page titled "BrowserStack Local Test Page":
python3 -m http.server 45454 --directory features/local-htmlThen in a separate terminal:
browserstack-sdk behave features/local.featurebs-local.com is a hostname BrowserStack Local resolves to your machine inside the remote browser — for your own app, point your scenarios at http://bs-local.com:<port>/ instead of a public URL.
Understand how many parallel sessions you need by using our Parallel Test Calculator.
Alternatively the variables can be set in the environment using env or your CI framework (like GitHub Actions or Jenkins). See .github/workflows/build.yml for a GitHub Actions example — it runs on workflow_dispatch (manual trigger) with a commit SHA input and posts a status check back to that commit.
- One
browserstack.ymldeclares platforms; the SDK picks them up automatically. - The SDK runs platforms in parallel for you — no hand-rolled parallel runner; the SDK forks one behave run per
(platform × parallelsPerPlatform)cell. - The SDK monkeypatches Playwright's browser launches — the test code calls
chromium.launch()and the SDK transparently routes the launch to the per-platform browser configured inbrowserstack.yml(chromium, firefox, or webkit). Nochromium.connect(wss_url)plumbing is needed in customer code. - The CLI is
browserstack-sdk behave …— wrapsbehaveand injects the SDK at runtime.
.
├── browserstack.yml # SDK config: credentials, 3 parallel platforms, Local toggle, reporting
├── requirements.txt
└── features/
├── sample.feature # bstackdemo add-to-cart scenario
├── local.feature # BrowserStack Local tunnel scenario
├── local-html/
│ └── index.html # static page served on :45454 for local.feature
├── environment.py # behave hooks: launch browser, hand to context.page
└── steps/
├── sample_steps.py
└── local_steps.py
Happy Testing!