Skip to content

Commit 9f41152

Browse files
Add second sample: BrowserStack Local test (features/local.feature)
Mirrors the 2-sample pattern from cucumber-java-browserstack and junit-browserstack so customers get one public-site sample plus one BrowserStack Local sample. - features/local.feature — navigates http://bs-local.com:45454/ and asserts the page title contains "BrowserStack Local". - features/steps/local_steps.py — two steps. - features/local-html/index.html — title-matching page; start with `python3 -m http.server 45454 --directory features/local-html` before running the local feature. - browserstack.yml — browserstackLocal: true (matches cucumber-java-browserstack canonical so the SDK starts and stops the tunnel for every run). - README.md — repo layout updated; Running section split into "Sample test" and "Local test" subsections with explicit local-server start command. Live-verified end-to-end: build 03f2c770c3b15871829075c20f45ad4a826b56cf returns status=passed for all 6 sessions (2 scenarios x 3 Playwright engines: chromium 148, playwright-firefox 148, playwright-webkit 18.2).
1 parent 943aefd commit 9f41152

5 files changed

Lines changed: 65 additions & 6 deletions

File tree

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,39 @@ This repo shows how to run [behave](https://behave.readthedocs.io/) tests on Bro
1313
* Set `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` as environment variables, or replace `userName` and `accessKey` directly in `browserstack.yml` with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). Env vars take precedence.
1414

1515
### Running your tests
16-
Run the sample in parallel across the 3 Playwright browser engines (chromium / firefox / webkit) declared in `browserstack.yml`:
16+
There are two sample scenarios in `features/`:
17+
18+
* **`features/sample.feature`** — drives `https://www.bstackdemo.com` (a public site) and adds a product to the cart.
19+
* **`features/local.feature`** — drives `http://bs-local.com:45454/` through the BrowserStack Local tunnel; verifies the page title contains "BrowserStack Local".
20+
21+
`browserstack.yml` enables `browserstackLocal: true`, so the SDK starts and stops the BrowserStack Local tunnel for you on every run — no manual binary lifecycle.
22+
23+
#### Sample test (public site)
24+
Runs in parallel across the 3 Playwright browser engines (chromium / firefox / webkit) declared in `browserstack.yml`:
1725

1826
```sh
1927
browserstack-sdk behave features/sample.feature
2028
```
2129

30+
#### Local test (private / localhost host)
31+
Start a local HTTP server first — `features/local-html/` contains a tiny page titled "BrowserStack Local Test Page":
32+
33+
```sh
34+
python3 -m http.server 45454 --directory features/local-html
35+
```
36+
37+
Then in a separate terminal:
38+
39+
```sh
40+
browserstack-sdk behave features/local.feature
41+
```
42+
43+
`bs-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.
44+
2245
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github).
2346

2447
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.
2548

26-
### Testing a private host (BrowserStack Local)
27-
If your app lives on `localhost`, a staging host, or behind a firewall, set `browserstackLocal: true` in `browserstack.yml` and rerun the same command. The SDK starts and stops the BrowserStack Local tunnel for you — no manual binary download or lifecycle management. Then point your scenarios at `http://bs-local.com:<port>/` (a hostname BrowserStack Local resolves to your machine) instead of a public URL.
28-
2949
### How the SDK changes things
3050
- **One `browserstack.yml`** declares platforms; the SDK picks them up automatically.
3151
- **The SDK runs platforms in parallel for you** — no hand-rolled parallel runner; the SDK forks one behave run per `(platform × parallelsPerPlatform)` cell.
@@ -39,9 +59,13 @@ If your app lives on `localhost`, a staging host, or behind a firewall, set `bro
3959
├── requirements.txt
4060
└── features/
4161
├── sample.feature # bstackdemo add-to-cart scenario
62+
├── local.feature # BrowserStack Local tunnel scenario
63+
├── local-html/
64+
│ └── index.html # static page served on :45454 for local.feature
4265
├── environment.py # behave hooks: launch browser, hand to context.page
4366
└── steps/
44-
└── sample_steps.py
67+
├── sample_steps.py
68+
└── local_steps.py
4569
```
4670

4771
### Further Reading

browserstack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ parallelsPerPlatform: 1
6565
# ==========================================
6666
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
6767
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
68-
browserstackLocal: false # <boolean> (Default false)
68+
browserstackLocal: true # <boolean> (Default false)
6969

7070
# Options to be passed to BrowserStack local in-case of advanced configurations
7171
# browserStackLocalOptions:

features/local-html/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>BrowserStack Local Test Page</title>
6+
</head>
7+
<body>
8+
<h1>BrowserStack Local Test Page</h1>
9+
<p>
10+
Served on <code>http://localhost:45454/</code> for the
11+
<code>features/local.feature</code> scenario. The BrowserStack Local
12+
tunnel resolves <code>bs-local.com:45454</code> on the remote browser
13+
back to this page.
14+
</p>
15+
</body>
16+
</html>

features/local.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature: Verify BrowserStack Local
2+
3+
Scenario: Navigate to a page served on localhost through the BrowserStack Local tunnel
4+
Given I visit local app website
5+
Then the page title should contain "BrowserStack Local"

features/steps/local_steps.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from behave import given, then
2+
3+
4+
@given("I visit local app website")
5+
def visit_local_app(context):
6+
context.page.goto("http://bs-local.com:45454/")
7+
8+
9+
@then('the page title should contain "{expected}"')
10+
def verify_title_contains(context, expected):
11+
title = context.page.title()
12+
assert expected in title, (
13+
f"expected title to contain {expected!r}, got {title!r}"
14+
)

0 commit comments

Comments
 (0)