diff --git a/.github/workflows/automate-skills-check.yml b/.github/workflows/automate-skills-check.yml new file mode 100644 index 0000000..49b28ef --- /dev/null +++ b/.github/workflows/automate-skills-check.yml @@ -0,0 +1,22 @@ +# Fails if automate/*/SKILL.md or automate/README.md no longer match automate/_source. +# Fix locally with: python3 automate/_source/build.py +name: Automate skills up to date + +on: + pull_request: + branches: ["main"] + paths: ["automate/**", ".github/workflows/automate-skills-check.yml"] + push: + branches: ["main"] + paths: ["automate/**", ".github/workflows/automate-skills-check.yml"] + +permissions: + contents: read + +jobs: + check: + name: Generated skills match their source + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - run: python3 -I automate/_source/build.py --check diff --git a/README.md b/README.md index 870adb4..bbe0591 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ AI agent skills for BrowserStack products. Each skill teaches a coding agent (Cl | Product | Folder | | --- | --- | | App Automate | [`app-automate/`](app-automate/) | +| Automate | [`automate/`](automate/) | Each product folder has its own README listing its skills and the exact prompts to use. diff --git a/automate/README.md b/automate/README.md new file mode 100644 index 0000000..4338fe4 --- /dev/null +++ b/automate/README.md @@ -0,0 +1,117 @@ +# Automate skills + +Each skill takes a coding agent from one pasted prompt to a build on the BrowserStack Automate dashboard: BrowserStack's official sample build, or your own tests with no changes to your test logic. The agent checks your credentials, shows a plan, waits for your OK, runs the build and returns the dashboard link. + +| Framework | Language | Runs on | Sample repo | Docs | Skill | +| --- | --- | --- | --- | --- | --- | +| Selenium | Java | real desktop browsers and real mobile devices | [`junit-browserstack@master`](https://github.com/browserstack/junit-browserstack/tree/master) | [getting started](https://www.browserstack.com/docs/automate/selenium/getting-started/java) | [`selenium-java`](selenium-java/SKILL.md) | +| Selenium | Python | real desktop browsers and real mobile devices | [`python-selenium-browserstack@main`](https://github.com/browserstack/python-selenium-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/selenium/getting-started/python) | [`selenium-python`](selenium-python/SKILL.md) | +| Selenium | JavaScript | real desktop browsers and real mobile devices | [`jest-js-browserstack@main`](https://github.com/browserstack/jest-js-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/selenium/getting-started/nodejs) | [`selenium-javascript`](selenium-javascript/SKILL.md) | +| Selenium | C# | real desktop browsers and real mobile devices | [`xunit-browserstack@main`](https://github.com/browserstack/xunit-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/selenium/getting-started/c-sharp) | [`selenium-csharp`](selenium-csharp/SKILL.md) | +| Playwright | JavaScript | real desktop browsers, with real Android and iPhone on request | [`node-js-playwright-browserstack@main`](https://github.com/browserstack/node-js-playwright-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs) | [`playwright-javascript`](playwright-javascript/SKILL.md) | +| Playwright | Python | real desktop browsers, with a real iPhone on request | [`pytest-playwright-browserstack@main`](https://github.com/browserstack/pytest-playwright-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/playwright/getting-started/python) | [`playwright-python`](playwright-python/SKILL.md) | +| Playwright | Java | real desktop browsers, with a real iPhone on request | [`java-playwright-browserstack@main`](https://github.com/browserstack/java-playwright-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/playwright/getting-started/java) | [`playwright-java`](playwright-java/SKILL.md) | +| Playwright | C# | real desktop browsers, with a real iPhone on request | [`csharp-playwright-browserstack@main`](https://github.com/browserstack/csharp-playwright-browserstack/tree/main) | [getting started](https://www.browserstack.com/docs/automate/playwright/getting-started/c-sharp) | [`playwright-csharp`](playwright-csharp/SKILL.md) | + +## Prompts + +Set `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` as environment variables first; never paste the key into a prompt. + +**Selenium Java** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-java/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-java/SKILL.md, then follow that skill to run the Selenium Java sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-java/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-java/SKILL.md, then follow that skill to run my own Selenium Java tests on BrowserStack Automate. +``` + +**Selenium Python** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-python/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-python/SKILL.md, then follow that skill to run the Selenium Python sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-python/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-python/SKILL.md, then follow that skill to run my own Selenium Python tests on BrowserStack Automate. +``` + +**Selenium JavaScript** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-javascript/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-javascript/SKILL.md, then follow that skill to run the Selenium JavaScript sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-javascript/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-javascript/SKILL.md, then follow that skill to run my own Selenium JavaScript tests on BrowserStack Automate. +``` + +**Selenium C#** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-csharp/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-csharp/SKILL.md, then follow that skill to run the Selenium C# sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/selenium-csharp/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-selenium-csharp/SKILL.md, then follow that skill to run my own Selenium C# tests on BrowserStack Automate. +``` + +**Playwright JavaScript** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-javascript/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-javascript/SKILL.md, then follow that skill to run the Playwright JavaScript sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-javascript/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-javascript/SKILL.md, then follow that skill to run my own Playwright JavaScript tests on BrowserStack Automate. +``` + +**Playwright Python** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-python/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-python/SKILL.md, then follow that skill to run the Playwright Python sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-python/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-python/SKILL.md, then follow that skill to run my own Playwright Python tests on BrowserStack Automate. +``` + +**Playwright Java** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-java/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-java/SKILL.md, then follow that skill to run the Playwright Java sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-java/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-java/SKILL.md, then follow that skill to run my own Playwright Java tests on BrowserStack Automate. +``` + +**Playwright C#** + +Run the sample build: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-csharp/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-csharp/SKILL.md, then follow that skill to run the Playwright C# sample build on BrowserStack Automate. +``` +Run your own tests: +``` +Download https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/playwright-csharp/SKILL.md and save it permanently in this project's skills folder as browserstack-automate-playwright-csharp/SKILL.md, then follow that skill to run my own Playwright C# tests on BrowserStack Automate. +``` + +## Maintaining these skills + +The `SKILL.md` files are generated. Edit `_source/` (`template.md` for everything the skills share, `parts//` for language-specific sections, `skills.json` for names, sample repos and platforms), then run: + +```bash +python3 automate/_source/build.py # regenerate the skills and this README +python3 automate/_source/build.py --check # fail if anything is out of date +``` + +Prompts point at `main`, so a merge is live for new installs: test both prompts from your branch's raw URL before merging. diff --git a/automate/_source/build.py b/automate/_source/build.py new file mode 100644 index 0000000..041b896 --- /dev/null +++ b/automate/_source/build.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Generate every automate//SKILL.md from one shared template. + +Edit automate/_source/ (template.md, skills.json, parts/), never the generated SKILL.md files: +a fix made once in the template reaches every language. + + python3 automate/_source/build.py # regenerate all skills + python3 automate/_source/build.py --check # exit 1 if any SKILL.md is out of date +""" +import json +import pathlib +import re +import sys + +SRC = pathlib.Path(__file__).resolve().parent +AUTOMATE = SRC.parent +RAW = "https://raw.githubusercontent.com/browserstack/agent-skills/main/automate/{folder}/SKILL.md" + + +def prompt(skill, kind): + """The exact prompt a docs page shows: kind is 'sample' or 'own'.""" + what = (f"run the {skill['label']} sample build" if kind == "sample" + else f"run my own {skill['label']} tests") + return (f"Download {RAW.format(folder=skill['folder'])} and save it permanently in this " + f"project's skills folder as {skill['name']}/SKILL.md, then follow that skill to " + f"{what} on BrowserStack Automate.") + + +def prompts_table(skills, current): + """The other skills: how to recognise their projects, and the own-tests prompt to hand over.""" + lines = [] + for s in skills: + if s["folder"] == current["folder"]: + continue + lines.append(f" - **{s['label']}** ({s['project_signal']}):\n" + f" `{prompt(s, 'own')}`") + return "\n".join(lines) + + +def render(text, skill, skills): + def part(m): + path = SRC / "parts" / skill["folder"] / f"{m.group(1)}.md" + return path.read_text().rstrip("\n") + + text = re.sub(r"\{\{part:([a-z_]+)\}\}", part, text) + values = dict(skill) + values["raw_url"] = RAW.format(folder=skill["folder"]) + values["sample_yml_raw"] = (f"https://raw.githubusercontent.com/browserstack/{skill['sample_repo']}/" + f"{skill['sample_branch']}{skill['sample_subdir']}/browserstack.yml") + values["prompt_sample"] = prompt(skill, "sample") + values["prompt_own"] = prompt(skill, "own") + values["prompts_table"] = prompts_table(skills, skill) + for key, val in values.items(): + if isinstance(val, str): + text = text.replace("{{" + key + "}}", val) + left = re.findall(r"\{\{[^}]+\}\}", text) + if left: + sys.exit(f"{skill['folder']}: unresolved placeholders {sorted(set(left))}") + return text + + +def readme(skills): + """automate/README.md: the skill table and the two prompts per skill, from the same source.""" + out = ["# Automate skills", "", + "Each skill takes a coding agent from one pasted prompt to a build on the BrowserStack " + "Automate dashboard: BrowserStack's official sample build, or your own tests with no " + "changes to your test logic. The agent checks your credentials, shows a plan, waits for " + "your OK, runs the build and returns the dashboard link.", "", + "| Framework | Language | Runs on | Sample repo | Docs | Skill |", + "| --- | --- | --- | --- | --- | --- |"] + for s in skills: + out.append(f"| {s['framework']} | {s['language']} | {s['platform_kind']} | " + f"[`{s['sample_repo']}@{s['sample_branch']}`](https://github.com/browserstack/{s['sample_repo']}/tree/{s['sample_branch']}) | " + f"[getting started]({s['docs_url']}) | " + f"[`{s['folder']}`]({s['folder']}/SKILL.md) |") + out += ["", "## Prompts", "", + "Set `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` as environment variables first; " + "never paste the key into a prompt.", ""] + for s in skills: + out += [f"**{s['label']}**", "", "Run the sample build:", "```", prompt(s, "sample"), "```", + "Run your own tests:", "```", prompt(s, "own"), "```", ""] + out += ["## Maintaining these skills", "", + "The `SKILL.md` files are generated. Edit `_source/` (`template.md` for everything the " + "skills share, `parts//` for language-specific sections, `skills.json` for names, " + "sample repos and platforms), then run:", "", + "```bash", "python3 automate/_source/build.py # regenerate the skills and this README", + "python3 automate/_source/build.py --check # fail if anything is out of date", "```", "", + "Prompts point at `main`, so a merge is live for new installs: test both prompts from " + "your branch's raw URL before merging.", ""] + return "\n".join(out) + + +def main(): + check = "--check" in sys.argv + skills = json.loads((SRC / "skills.json").read_text()) + template = (SRC / "template.md").read_text() + stale = [] + outputs = [(AUTOMATE / s["folder"] / "SKILL.md", render(template, s, skills)) for s in skills] + outputs.append((AUTOMATE / "README.md", readme(skills))) + for out, text in outputs: + if check: + if not out.exists() or out.read_text() != text: + stale.append(str(out.relative_to(AUTOMATE.parent))) + else: + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(text) + print(f"wrote {out.relative_to(AUTOMATE.parent)} ({text.count(chr(10))} lines)") + if check: + if stale: + print("Out of date — run python3 automate/_source/build.py:\n " + "\n ".join(stale)) + sys.exit(1) + print(f"All {len(skills)} skills and the README are up to date.") + + +if __name__ == "__main__": + main() diff --git a/automate/_source/parts/playwright-csharp/next_offers.md b/automate/_source/parts/playwright-csharp/next_offers.md new file mode 100644 index 0000000..c2b0d6d --- /dev/null +++ b/automate/_source/parts/playwright-csharp/next_offers.md @@ -0,0 +1,7 @@ +- **Real iPhone:** add a real iPhone 15 (Safari) as its own build (B1 has the row and how). After + an iPhone-only run, offer the desktop build instead. Set expectations first: + Playwright on real iOS is a custom WebKit integration with limits (for example one browser + context per session, and some keyboard and multi-tab behaviour differs from desktop WebKit), so + a failure there doesn't change the desktop results. Real Android phones need BrowserStack's device API rather + than a normal browser launch, so this skill doesn't set them up: see https://www.browserstack.com/docs/automate/playwright/playwright-android/c-sharp. +- **Wider coverage:** add Edge, older browser versions or other operating systems. diff --git a/automate/_source/parts/playwright-csharp/own_assess.md b/automate/_source/parts/playwright-csharp/own_assess.md new file mode 100644 index 0000000..9127ff3 --- /dev/null +++ b/automate/_source/parts/playwright-csharp/own_assess.md @@ -0,0 +1,29 @@ +Note these in a short Assessment block at the top of your plan: + +- **Project:** the test `.csproj` (and the solution, if any), its `TargetFramework(s)`, and the test + framework: NUnit, MSTest or xUnit. +- **Playwright version:** `Microsoft.Playwright` (and `Microsoft.Playwright.NUnit` or `.MSTest`); + keep the user's version. +- **How the browser is created:** a `PageTest`/`BrowserTest` base class, or + `Playwright.CreateAsync()` with `Chromium`/`Firefox`/`Webkit.LaunchAsync()`, is routed by the SDK + to the platforms in `browserstack.yml`; confirm on the API after the run. `ExecutablePath`, + `LaunchPersistentContextAsync` or `ConnectAsync` to another endpoint runs on the local machine. +- **Target framework runtime:** if the project targets a .NET version whose runtime isn't + installed, plan to run with `DOTNET_ROLL_FORWARD=Major` (no file change). +- **Real iPhone (on request, as its own build):** for that run, use only this platform in + `browserstack.yml` with a new `buildName` (check it against the live catalog as in step A3), and + put the desktop rows back afterwards if the user wants both: + ```yaml + platforms: + - deviceName: iPhone 15 + osVersion: 17 + browserName: safari + ``` + The SDK opens one session per test, so `PageTest` and `LaunchAsync` tests stay within iOS's + one-context limit, and it names and marks each session. +- **Real Android:** needs BrowserStack's device API (`Android.ConnectAsync`), which is a code + change, so this skill doesn't set it up. Never add an Android row: device sessions still start + and stay `done` (see Troubleshooting). Point the user to https://www.browserstack.com/docs/automate/playwright/playwright-android/c-sharp. +- **Which tests to run:** the ones the user named (as a `dotnet test --filter`); otherwise all. If + they named a flow that has no test, pick the test whose name is the nearest step in that flow, + and if two are equally close, the first by file path. State the pick and why. diff --git a/automate/_source/parts/playwright-csharp/own_changes.md b/automate/_source/parts/playwright-csharp/own_changes.md new file mode 100644 index 0000000..d3aa1b3 --- /dev/null +++ b/automate/_source/parts/playwright-csharp/own_changes.md @@ -0,0 +1,19 @@ +1. **Add the BrowserStack SDK package, pinned to the current release** (the last entry of + `https://api.nuget.org/v3-flatcontainer/browserstack.testadapter/index.json`). An outdated + adapter can silently run 0 tests on newer .NET, so always use the current one; this changes the `.csproj`: + ```bash + dotnet add package BrowserStack.TestAdapter --version + ``` +2. **Put `browserstack.yml` next to the test `.csproj`** (the file below). The first build also + creates a `dotnet-tools.json` for the SDK's own `browserstack-sdk` tool, and the SDK writes its + logs to `log/` next to the `.csproj`: list both in the plan. +3. **Desktop macOS rows use `playwright-webkit`, never `Safari`.** On desktop, Playwright on + BrowserStack accepts only `chrome`, `edge`, `playwright-chromium`, `playwright-webkit` or + `playwright-firefox`: a `browserName: Safari` on an `os: OS X` row fails every test on that platform with `Invalid 'browser'`. If the + project's `browserstack.yml` has one, change it to `playwright-webkit` with `browserVersion: latest` + (a Safari version such as `15.6` is not a WebKit version) and show the diff. Keep + `safari` only on real iPhone rows (`deviceName: iPhone …`). +4. **`Microsoft.NET.Test.Sdk` new enough for the Playwright test package.** If the project floats + `Microsoft.Playwright.NUnit` (or `.MSTest`) and pins `Microsoft.NET.Test.Sdk` below 17.8, restore fails + with `NU1605: Detected package downgrade`: raise `Microsoft.NET.Test.Sdk` to 17.8 or newer in the plan + (show the diff). diff --git a/automate/_source/parts/playwright-csharp/own_run.md b/automate/_source/parts/playwright-csharp/own_run.md new file mode 100644 index 0000000..4776e1e --- /dev/null +++ b/automate/_source/parts/playwright-csharp/own_run.md @@ -0,0 +1,10 @@ +Build first: the SDK hooks into the test assembly at build time. + +```bash +dotnet build +dotnet test # add --filter "FullyQualifiedName~Cart" for a subset +``` + +If the project targets several frameworks, add `-f `; if its only target's +runtime isn't installed, prefix `DOTNET_ROLL_FORWARD=Major`. Don't run `playwright.ps1 install`: +the browsers run on BrowserStack. diff --git a/automate/_source/parts/playwright-csharp/own_yml_extra.md b/automate/_source/parts/playwright-csharp/own_yml_extra.md new file mode 100644 index 0000000..15a3a14 --- /dev/null +++ b/automate/_source/parts/playwright-csharp/own_yml_extra.md @@ -0,0 +1 @@ +# testObservability: true # optional: adds a test report link; check the build report the SDK prints diff --git a/automate/_source/parts/playwright-csharp/quickref.md b/automate/_source/parts/playwright-csharp/quickref.md new file mode 100644 index 0000000..a518872 --- /dev/null +++ b/automate/_source/parts/playwright-csharp/quickref.md @@ -0,0 +1,7 @@ +| Task | Command | +| --- | --- | +| Sample build | `git clone https://github.com/browserstack/csharp-playwright-browserstack.git && cd csharp-playwright-browserstack/CSharp-Playwright-BrowserStack && NoWarn=NU1605 DOTNET_ROLL_FORWARD=Major dotnet test --filter "Category=sample-test"` | +| Your tests | `dotnet build && dotnet test ` | +| Current SDK version | `curl -s https://api.nuget.org/v3-flatcontainer/browserstack.testadapter/index.json` (last entry) | +| Installed runtimes | `dotnet --list-runtimes` | +| Docs | https://www.browserstack.com/docs/automate/playwright/getting-started/c-sharp | diff --git a/automate/_source/parts/playwright-csharp/sample_prereq.md b/automate/_source/parts/playwright-csharp/sample_prereq.md new file mode 100644 index 0000000..bda0b3d --- /dev/null +++ b/automate/_source/parts/playwright-csharp/sample_prereq.md @@ -0,0 +1,6 @@ +```bash +dotnet --version # .NET SDK 6 or newer +dotnet --list-runtimes # no Microsoft.NETCore.App 6.0.x? fine: A4 runs on a newer one +git --version +``` +If `dotnet` or `git` is missing, tell the user what to install and stop. diff --git a/automate/_source/parts/playwright-csharp/sample_run.md b/automate/_source/parts/playwright-csharp/sample_run.md new file mode 100644 index 0000000..372c1e7 --- /dev/null +++ b/automate/_source/parts/playwright-csharp/sample_run.md @@ -0,0 +1,21 @@ +The sample floats `Microsoft.Playwright.NUnit` to the latest release but pins an older +`Microsoft.NET.Test.Sdk`, so restore stops with `NU1605: Detected package downgrade`; and it targets +`net6.0`. Both are handled with environment variables, without changing any file: + +```bash +NoWarn=NU1605 DOTNET_ROLL_FORWARD=Major dotnet test --filter "Category=sample-test" +``` + +`NoWarn` must be an environment variable, not `-p:NoWarn`, because the SDK runs its own restore. +With a 6.0 runtime installed, drop `DOTNET_ROLL_FORWARD=Major`. PowerShell: set +`$env:NoWarn="NU1605"` and `$env:DOTNET_ROLL_FORWARD="Major"` first. The BrowserStack SDK (the +`BrowserStack.TestAdapter` package already in the project) runs `SampleTest` (adds a product to +the cart on bstackdemo.com and checks the cart) on every platform in `browserstack.yml` (desktop +Chrome, WebKit and Firefox), in parallel. The build also adds the SDK's own `browserstack-sdk` tool +to a `dotnet-tools.json`: list it in the plan. Warnings that `net6.0` is out of support are harmless. +If a first attempt failed, delete `bin/` and `obj/` before running again (see Troubleshooting). + +When you read the sample's `browserstack.yml` for the plan, look for a `browserName: Safari` on a +desktop (`os:`) row. If there is one, list the change to `playwright-webkit` with +`browserVersion: latest` in the plan, and make it after cloning, before running (find it with +`grep -niB3 "browserName: *safari" browserstack.yml`); `safari` stays only on real iPhone rows. diff --git a/automate/_source/parts/playwright-csharp/status_marking.md b/automate/_source/parts/playwright-csharp/status_marking.md new file mode 100644 index 0000000..6ca1595 --- /dev/null +++ b/automate/_source/parts/playwright-csharp/status_marking.md @@ -0,0 +1,2 @@ + - If sessions show `done`, mark each from `dotnet test`'s results as shown below (session names + carry the test's full name when the SDK set them). diff --git a/automate/_source/parts/playwright-csharp/troubleshooting.md b/automate/_source/parts/playwright-csharp/troubleshooting.md new file mode 100644 index 0000000..474fbdf --- /dev/null +++ b/automate/_source/parts/playwright-csharp/troubleshooting.md @@ -0,0 +1,10 @@ +| `dotnet test` finishes with 0 tests run, or runs locally | An outdated `BrowserStack.TestAdapter`: update it to the current release (B2, step 1) | +| `You must install or update .NET to run this application` | The target framework's runtime isn't installed: prefix `DOTNET_ROLL_FORWARD=Major`, or use `-f ` | +| `NU1605: Detected package downgrade: Microsoft.NET.Test.Sdk` | A floating `Microsoft.Playwright.NUnit` needs a newer `Microsoft.NET.Test.Sdk` than the project pins. Sample build: run with the environment variable `NoWarn=NU1605` (A4). Your project: propose raising `Microsoft.NET.Test.Sdk` to 17.8 or newer | +| `Executable doesn't exist … playwright.ps1 install` | The launch wasn't routed: check `BrowserStack.TestAdapter` is in the `.csproj` and run `dotnet build` before `dotnet test`. After a failed build, delete `bin/` and `obj/` first: the SDK otherwise reuses the patch from the failed build and the browsers launch locally | +| Test host crashed with `JsonReaderException … AtomicFile`, or the output shows another project's tests | Another .NET SDK run is active on this machine (they share working files under `$TMPDIR/.browserstack/`): run one at a time, and trust the API | +| iOS: `Only one browser context is allowed` | Real iOS allows one context per session: one test per session, no multi-context tests | +| Real Android: every test fails with `KeyNotFoundException: The given key 'AndroidDevice' was not present in the dictionary`; sessions stay `done` with no name | Desktop-style tests can't drive real Android: remove the Android row (B1) | +| A WebKit session takes 3 minutes or more to start while the other platforms have finished | Slow device allocation, not a hang (seen on macOS Ventura WebKit): wait up to 10 minutes before treating it as stuck | +| `Invalid 'browser'. Use 'chrome', 'edge', 'playwright-chromium', 'playwright-webkit' or 'playwright-firefox' only` | A desktop row has `browserName: Safari`: change it to `playwright-webkit` with `browserVersion: latest`. Keep `safari` only on real iPhone rows | +| `browserType.connect: Error: Unsupported browser version` on a `playwright-webkit` row | The row kept a Safari version (for example `15.6`): set `browserVersion: latest` | diff --git a/automate/_source/parts/playwright-java/next_offers.md b/automate/_source/parts/playwright-java/next_offers.md new file mode 100644 index 0000000..448840c --- /dev/null +++ b/automate/_source/parts/playwright-java/next_offers.md @@ -0,0 +1,7 @@ +- **Real iPhone:** add a real iPhone 15 (Safari) as its own build (B1 has the row and how). After + an iPhone-only run, offer the desktop build instead. Set expectations first: + Playwright on real iOS is a custom WebKit integration with limits (for example one browser + context per session, and some keyboard and multi-tab behaviour differs from desktop WebKit), so + a failure there doesn't change the desktop results. Real Android phones need BrowserStack's device API rather + than a normal browser launch, so this skill doesn't set them up: see https://www.browserstack.com/docs/automate/playwright/playwright-android. +- **Wider coverage:** add Edge, older browser versions or other operating systems. diff --git a/automate/_source/parts/playwright-java/own_assess.md b/automate/_source/parts/playwright-java/own_assess.md new file mode 100644 index 0000000..c81865d --- /dev/null +++ b/automate/_source/parts/playwright-java/own_assess.md @@ -0,0 +1,31 @@ +Note these in a short Assessment block at the top of your plan: + +- **Build tool:** `pom.xml` → Maven; `build.gradle` / `build.gradle.kts` → Gradle (use `./gradlew` + if the repo has it). A Gradle project needs Gradle (the wrapper or `gradle`) on this machine: + if neither works, say what to install and stop. Never convert the build to Maven. In a + multi-module repo, wire only the module with the Playwright tests. +- **Test framework:** JUnit 5, TestNG or JUnit 4. +- **Playwright version:** `com.microsoft.playwright:playwright`; keep the user's version; if the pom says + `LATEST`, pin it to the version that resolves today and show the diff. +- **How the browser is created:** `Playwright.create()` with `chromium()`, `firefox()` or + `webkit()` and `.launch()` (or `.connect()` to a BrowserStack endpoint) is routed by the SDK to + the platforms in `browserstack.yml`; confirm on the API after the run. `executablePath`, + `launchPersistentContext` or `connect()` to another endpoint runs on the local machine. +- **Existing BrowserStack wiring or surefire ``** (for example JaCoCo): update in place, + and append the agent rather than replacing an existing `argLine`. +- **Real iPhone (on request, as its own build):** for that run, use only this platform in + `browserstack.yml` with a new `buildName` (check it against the live catalog as in step A3), and + put the desktop rows back afterwards if the user wants both: + ```yaml + platforms: + - deviceName: iPhone 15 + osVersion: 17 + browserName: safari + ``` + The SDK routes a standard `launch()` to it and names and marks the session. +- **Real Android:** needs BrowserStack's Playwright Android device API, which is a code change, so + this skill doesn't set it up. Never add an Android row: a device session still starts and ends + in `error` (see Troubleshooting). Point the user to https://www.browserstack.com/docs/automate/playwright/playwright-android. +- **Which tests to run:** the ones the user named; otherwise all. If they named a flow that has no + test, pick the test whose name is the nearest step in that flow, and if two are equally close, + the first by file path. State the pick and why. diff --git a/automate/_source/parts/playwright-java/own_changes.md b/automate/_source/parts/playwright-java/own_changes.md new file mode 100644 index 0000000..cdcc315 --- /dev/null +++ b/automate/_source/parts/playwright-java/own_changes.md @@ -0,0 +1,89 @@ +1. **BrowserStack Java SDK, pinned to the current release** (never `LATEST`). Get the version from + `https://repo1.maven.org/maven2/com/browserstack/browserstack-java-sdk/maven-metadata.xml` + (the `` tag; `search.maven.org` lags): + ```xml + + com.browserstack + browserstack-java-sdk + CURRENT_RELEASE + compile + + ``` +2. **Attach the SDK as a `-javaagent`**, exactly once: + - **Maven:** add `maven-dependency-plugin` (goal `properties`, which exposes the jar path) and the + agent on surefire. If the project already has an `argLine`, keep it and append: + ```xml + + org.apache.maven.plugins + maven-dependency-plugin + 3.8.1 + getClasspathFilenamesproperties + + + org.apache.maven.plugins + maven-surefire-plugin + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + + + ``` + - **Gradle (JUnit 5):** don't put the agent on the `test` task: inside Gradle's test worker the + SDK can run only one platform, and the others stop with `java.io.EOFException … GradleWorkerMain`. + Add a separate task that runs the same tests through the JUnit console launcher in a plain JVM, + and leave the `test` task as it is: + ```groovy + dependencies { + testImplementation 'com.browserstack:browserstack-java-sdk:CURRENT_RELEASE' + testRuntimeOnly 'org.junit.platform:junit-platform-console' // version comes from the JUnit BOM + } + // Runs the JUnit 5 tests on every platform in browserstack.yml: gradle browserstackTest + tasks.register('browserstackTest', JavaExec) { + dependsOn 'testClasses' + classpath = sourceSets.test.runtimeClasspath + mainClass = 'org.junit.platform.console.ConsoleLauncher' + args 'execute', '--scan-classpath', '--include-classname', '.*', '--disable-banner', '--details=tree' + doFirst { jvmArgs "-javaagent:${classpath.find { it.name.contains('browserstack-java-sdk') }.absolutePath}" } + } + ``` + `execute` needs JUnit 5.10 or newer; on an older JUnit 5, leave it out. For one class, replace + `'--scan-classpath', '--include-classname', '.*'` with `'--select-class', 'com.example.LoginTest'`. + Use this task rather than the `com.browserstack.gradle-sdk` plugin. It is written for the Groovy + DSL and tested on Gradle 9.9.2; for `build.gradle.kts`, write + the same task in Kotlin and say it is unverified. + - **Gradle (TestNG):** TestNG runs every platform inside the one test JVM, so the agent can go on + Gradle's own `test` task (tested on Gradle 9.9.2 with Selenium and Playwright; the SDK names and marks each + session): + ```groovy + dependencies { testImplementation 'com.browserstack:browserstack-java-sdk:CURRENT_RELEASE' } + test { + useTestNG() + doFirst { jvmArgs "-javaagent:${classpath.find { it.name.contains('browserstack-java-sdk') }.absolutePath}" } + } + ``` + Run it with `gradle test` and set `framework: testng` in `browserstack.yml`. + - **Gradle (JUnit 4):** don't put the agent on the `test` task: the SDK's per-platform JVMs fail + there and no build is created at all. Run the tests through `JUnitCore` in a separate task, and + leave `test` as it is: + ```groovy + dependencies { testImplementation 'com.browserstack:browserstack-java-sdk:CURRENT_RELEASE' } + // Runs the JUnit 4 tests on every platform in browserstack.yml: gradle browserstackTest + tasks.register('browserstackTest', JavaExec) { + dependsOn 'testClasses' + classpath = sourceSets.test.runtimeClasspath + mainClass = 'org.junit.runner.JUnitCore' + args 'com.example.LoginTest', 'com.example.CartTest' // every test class to run, fully qualified + doFirst { jvmArgs "-javaagent:${classpath.find { it.name.contains('browserstack-java-sdk') }.absolutePath}" } + } + ``` + `JUnitCore` doesn't scan for tests, so list each test class (or one `@RunWith(Suite.class)` + class). Set `framework: junit4` in `browserstack.yml`. Tested on Gradle 9.9.2 with Selenium; for Playwright with JUnit 4, say it is unverified. Neither TestNG nor JUnit 4 needs an extra dependency on Gradle 9. + - Never also run through `browserstack-sdk mvn test`: attaching the agent twice fails with + "agent already loaded". +3. **Set `framework`** in `browserstack.yml` to the test framework (`junit5`, `testng` or `junit4`). +4. **Desktop macOS rows use `playwright-webkit`, never `Safari`.** On desktop, Playwright on + BrowserStack accepts only `chrome`, `edge`, `playwright-chromium`, `playwright-webkit` or + `playwright-firefox`: a `browserName: Safari` on an `os: OS X` row fails every test on that platform with `Invalid 'browser'`. If the + project's `browserstack.yml` has one, change it to `playwright-webkit` with `browserVersion: latest` + (a Safari version such as `15.6` is not a WebKit version) and show the diff. Keep + `safari` only on real iPhone rows (`deviceName: iPhone …`). diff --git a/automate/_source/parts/playwright-java/own_run.md b/automate/_source/parts/playwright-java/own_run.md new file mode 100644 index 0000000..a878c2f --- /dev/null +++ b/automate/_source/parts/playwright-java/own_run.md @@ -0,0 +1,14 @@ +- **Maven:** `mvn test` (one class: `mvn test -Dtest=CartTest`; one module: `mvn -pl test`). +- **Gradle with TestNG:** `./gradlew test` (or `gradle test`), with the agent on `test` (B2). + Gradle prints no per-test lines on success: take the counts from + `build/test-results/test/TEST-*.xml`. +- **Gradle with JUnit 5 or JUnit 4:** `./gradlew browserstackTest` (or `gradle browserstackTest`), the task from B2. + JUnit 5's console launcher prints one test tree per platform: read its "tests successful" / + "tests failed" lines and `BUILD`. JUnit 4's `JUnitCore` prints `OK (N tests)`, or `FAILURES!!!` + with `Tests run: N, Failures: M`, once per platform. + +Don't add `-q`. If the output is long, save it to a file and read the `Tests run:` and `BUILD` +lines. Playwright may download its driver on the first run, and older surefire versions print +`[ERROR] Surefire is going to kill self fork JVM` (about 30 s); so is a `*** java.lang.instrument +ASSERTION FAILED ***: "!errorOutstanding"` line under Gradle. All are harmless when the build +succeeds and the API shows the sessions. diff --git a/automate/_source/parts/playwright-java/own_yml_extra.md b/automate/_source/parts/playwright-java/own_yml_extra.md new file mode 100644 index 0000000..55215ec --- /dev/null +++ b/automate/_source/parts/playwright-java/own_yml_extra.md @@ -0,0 +1 @@ +framework: junit5 # or testng / junit4: the project's test framework diff --git a/automate/_source/parts/playwright-java/quickref.md b/automate/_source/parts/playwright-java/quickref.md new file mode 100644 index 0000000..cee0cb8 --- /dev/null +++ b/automate/_source/parts/playwright-java/quickref.md @@ -0,0 +1,8 @@ +| Task | Command | +| --- | --- | +| Sample build | `git clone https://github.com/browserstack/java-playwright-browserstack.git && cd java-playwright-browserstack && mvn compile && mvn test -P sample-test` | +| Your tests (Maven) | `mvn test` with the agent on surefire's `argLine` | +| Your tests (Gradle, JUnit 5 or 4) | `./gradlew browserstackTest` (the task from B2) | +| Your tests (Gradle, TestNG) | `./gradlew test` with the agent on `test` (B2) | +| Current SDK version | `curl -s https://repo1.maven.org/maven2/com/browserstack/browserstack-java-sdk/maven-metadata.xml \| grep -o '[^<]*'` | +| Docs | https://www.browserstack.com/docs/automate/playwright/getting-started/java | diff --git a/automate/_source/parts/playwright-java/sample_prereq.md b/automate/_source/parts/playwright-java/sample_prereq.md new file mode 100644 index 0000000..b413a56 --- /dev/null +++ b/automate/_source/parts/playwright-java/sample_prereq.md @@ -0,0 +1,6 @@ +```bash +java -version # 11 or newer +mvn -version # Maven on PATH +git --version +``` +If any is missing, tell the user what to install and stop. diff --git a/automate/_source/parts/playwright-java/sample_run.md b/automate/_source/parts/playwright-java/sample_run.md new file mode 100644 index 0000000..b224d87 --- /dev/null +++ b/automate/_source/parts/playwright-java/sample_run.md @@ -0,0 +1,18 @@ +```bash +mvn compile +mvn test -P sample-test +``` + +The `sample-test` profile attaches the BrowserStack Java SDK as a `-javaagent` and runs +`SampleTest` (adds a product to the cart on bstackdemo.com and checks the cart) with JUnit 5 on +every platform in `browserstack.yml` (desktop Chrome, Firefox and WebKit), in parallel. Don't add +`-q`; if the output is long, read the `Tests run:` and `BUILD` lines. Warnings about the deprecated +`LATEST` versions in the sample's `pom.xml`, and the SDK's "Both Selenium and Playwright detected" +warning, are harmless. The sample test catches its own exceptions, so an `Exception: …` line in +the output means the sample is out of date even when the sessions show `passed`: report it as in +"When sessions failed". + +When you read the sample's `browserstack.yml` for the plan, look for a `browserName: Safari` on a +desktop (`os:`) row. If there is one, list the change to `playwright-webkit` with +`browserVersion: latest` in the plan, and make it after cloning, before running (find it with +`grep -niB3 "browserName: *safari" browserstack.yml`); `safari` stays only on real iPhone rows. diff --git a/automate/_source/parts/playwright-java/status_marking.md b/automate/_source/parts/playwright-java/status_marking.md new file mode 100644 index 0000000..72591b4 --- /dev/null +++ b/automate/_source/parts/playwright-java/status_marking.md @@ -0,0 +1,3 @@ + - If sessions show `done`, the SDK didn't report the result: mark each from the runner's result + as shown below (session names carry the test name when the SDK set them; otherwise one test per + platform maps one-to-one). diff --git a/automate/_source/parts/playwright-java/troubleshooting.md b/automate/_source/parts/playwright-java/troubleshooting.md new file mode 100644 index 0000000..e1d2176 --- /dev/null +++ b/automate/_source/parts/playwright-java/troubleshooting.md @@ -0,0 +1,12 @@ +| `agent already loaded` | The agent is attached twice: keep the surefire `argLine` or `browserstack-sdk mvn test`, not both | +| A browser opens on the user's machine; the API shows no build | The launch wasn't routed: check the agent is on surefire's `argLine` (Maven) or on the `browserstackTest` task (Gradle), and the test uses a standard `launch()` | +| iOS: `Only one browser context is allowed` | Real iOS allows one context per session: one test per session, no multi-context tests | +| Real Android: `PlaywrightException: Cannot find parent object android@… to create android-device@…` at `launch()` | A standard `launch()` can't drive real Android, though the device session still starts (`error` / `ABRUPT_CLOSE`): remove the Android row (B1) | +| Gradle: only one platform gets a session and the output shows `java.io.EOFException … GradleWorkerMain` | The agent is on Gradle's `test` task, where the SDK can drive one platform. Use the `browserstackTest` task from B2 | +| Gradle 9: `Failed to load JUnit Platform … including the JUnit Platform launcher` | Gradle 9 no longer adds the launcher; it is the project's build, not BrowserStack. `browserstackTest` brings it in through `junit-platform-console`. For `gradle test` the project needs `testRuntimeOnly 'org.junit.platform:junit-platform-launcher'` (show it as a diff and ask) | +| No output for several minutes, and the API shows no session yet for one platform | The browser connection is slow to start (it can take 3 to 5 minutes) or has hung. Wait up to 10 minutes; then press Ctrl-C once. Maven then exits 130 with no summary, and the build link is in `log/browserstack-javaagent.log` | +| `Tests run: 0` with `BUILD SUCCESS`, or an empty "View build" link | Nothing reached BrowserStack (for example the disk filled up during the run): fix the cause and re-run; never report it as a pass | +| `Invalid 'browser'. Use 'chrome', 'edge', 'playwright-chromium', 'playwright-webkit' or 'playwright-firefox' only` | A desktop row has `browserName: Safari`: change it to `playwright-webkit` with `browserVersion: latest`. Keep `safari` only on real iPhone rows | +| `browserType.connect: Error: Unsupported browser version` on a `playwright-webkit` row | The row kept a Safari version (for example `15.6`): set `browserVersion: latest` | +| Gradle with JUnit 4: `BUILD FAILED` with `java.io.EOFException` or `OutOfMemoryError` in `GradleWorkerMain`, and no build on the API | The agent is on Gradle's `test` task, where JUnit 4 can't run under the SDK. Use the `browserstackTest` JavaExec task from B2 | +| A Gradle daemon is still running after the build | The SDK runs `gradle dependencies` to write `log/dependency-tree.log`, which starts one. Harmless; stop it with `gradle --stop` | diff --git a/automate/_source/parts/playwright-javascript/next_offers.md b/automate/_source/parts/playwright-javascript/next_offers.md new file mode 100644 index 0000000..c237016 --- /dev/null +++ b/automate/_source/parts/playwright-javascript/next_offers.md @@ -0,0 +1,7 @@ +- **Real phones:** add a real Samsung Galaxy S23 (Chrome) and a real iPhone 15 (Safari) (B1 has the + rows and how). Run the iPhone as its own build and set expectations first: Playwright on real iOS is a custom WebKit + integration with limits (for example one browser context per session, and some keyboard and + multi-tab behaviour differs from desktop WebKit), so a failure there doesn't change the desktop + results. On real Android, pages wider than the phone screen can fail clicks with "intercepts + pointer events" (see Troubleshooting). +- **Wider coverage:** add Edge, older browser versions or other operating systems. diff --git a/automate/_source/parts/playwright-javascript/own_assess.md b/automate/_source/parts/playwright-javascript/own_assess.md new file mode 100644 index 0000000..c2f505d --- /dev/null +++ b/automate/_source/parts/playwright-javascript/own_assess.md @@ -0,0 +1,36 @@ +Note these in a short Assessment block at the top of your plan: + +- **Versions:** `@playwright/test` (and `playwright`) from `package.json`; keep the user's version. +- **Config:** `playwright.config.*`: projects, `baseURL`, `workers`, and `webServer` (an app the + config starts locally needs BrowserStack Local). +- **Not this skill:** Playwright with Python, Java or C# has its own skill, Cypress has none yet, + and a Selenium project needs a Selenium skill (see Step 1). +- **Browser launch the SDK can't wrap:** a helper that calls `chromium.launch()` with a hard-coded + `executablePath`, a `globalSetup` that builds its own browser, or `connect()` to a non-BrowserStack + endpoint runs on the local machine while the result still looks green. Propose routing it through + Playwright's standard fixtures. +- **Other SDK bindings** (for example Selenium) in the same `node_modules` can make the SDK patch + the wrong framework. +- **Real phones (on request):** + - **Galaxy S23:** add this row to `browserstack.yml` next to the desktop rows (check it against + the live catalog as in step A3): + ```yaml + - deviceName: Samsung Galaxy S23 + osVersion: 13.0 + browserName: chrome + ``` + - **iPhone 15, as its own build:** keep `browserstack.yml` and add a `browserstack-ios.yml` with + the same settings, a new `buildName` and only this platform: + ```yaml + platforms: + - deviceName: iPhone 15 + osVersion: 17 + browserName: safari + ``` + Run it with `npx browserstack-node-sdk playwright test --browserstack.config browserstack-ios.yml` + after the main run. Set expectations in the plan first (see the "Real phones" offer). + - On real Android, a page wider than the phone screen can make clicks below the fold time out + (see Troubleshooting); say so in the plan if the app isn't built for small screens. +- **Which tests to run:** the ones the user named; otherwise the whole suite. If they named a flow + that has no test, pick the spec whose name is the nearest step in that flow, and if two are + equally close, the first by file path. State the pick and why. diff --git a/automate/_source/parts/playwright-javascript/own_changes.md b/automate/_source/parts/playwright-javascript/own_changes.md new file mode 100644 index 0000000..c5d3aea --- /dev/null +++ b/automate/_source/parts/playwright-javascript/own_changes.md @@ -0,0 +1,18 @@ +1. **Add the BrowserStack Node SDK, pinned exactly** to the current release (`npm view + browserstack-node-sdk version`), and keep the user's Playwright version; this changes `package.json`: + ```bash + npm i -D -E browserstack-node-sdk@ + ``` +2. **Only if the SDK can't run their Playwright version** (it fails before any session with + `configLoader.js doesn't exist`, or BrowserStack rejects the client version): first update the + SDK; if that doesn't fix it, propose pinning `@playwright/test` and `playwright` to `1.64.1` + (tested with the SDK on desktop, Android and iPhone) with `npm i -D -E`. Never + downgrade further. +3. **`webServer` or localhost targets:** set `browserstackLocal: true` in `browserstack.yml` and say + so in the plan; the SDK starts the tunnel. +4. **Desktop macOS rows use `playwright-webkit`, never `Safari`.** On desktop, Playwright on + BrowserStack accepts only `chrome`, `edge`, `playwright-chromium`, `playwright-webkit` or + `playwright-firefox`: a `browserName: Safari` on an `os: OS X` row fails every test on that platform with `Invalid 'browser'`. If the + project's `browserstack.yml` has one, change it to `playwright-webkit` with `browserVersion: latest` + (a Safari version such as `15.6` is not a WebKit version) and show the diff. Keep + `safari` only on real iPhone rows (`deviceName: iPhone …`). diff --git a/automate/_source/parts/playwright-javascript/own_run.md b/automate/_source/parts/playwright-javascript/own_run.md new file mode 100644 index 0000000..6c1e3ec --- /dev/null +++ b/automate/_source/parts/playwright-javascript/own_run.md @@ -0,0 +1,8 @@ +```bash +npx browserstack-node-sdk playwright test +``` + +Add the user's usual arguments (a spec file, `--project`, `--config`). Never run bare +`npx playwright test`: it runs locally. These lines are harmless on a genuine BrowserStack run: +"Uh-oh! We detected some issues … SDK-GEN-004" about `GLOBAL_AGENT_HTTP_PROXY`, and Accessibility +"not a valid session" warnings, and `EBADENGINE` warnings on Node older than 20.16. diff --git a/automate/_source/parts/playwright-javascript/own_yml_extra.md b/automate/_source/parts/playwright-javascript/own_yml_extra.md new file mode 100644 index 0000000..cd131a5 --- /dev/null +++ b/automate/_source/parts/playwright-javascript/own_yml_extra.md @@ -0,0 +1,2 @@ +framework: playwright +testObservability: true diff --git a/automate/_source/parts/playwright-javascript/quickref.md b/automate/_source/parts/playwright-javascript/quickref.md new file mode 100644 index 0000000..4f627b5 --- /dev/null +++ b/automate/_source/parts/playwright-javascript/quickref.md @@ -0,0 +1,6 @@ +| Task | Command | +| --- | --- | +| Sample build | `git clone -b main https://github.com/browserstack/node-js-playwright-browserstack.git && cd node-js-playwright-browserstack`, add `exact: true` to the Dropdown locator (A4), then `npm install && npm run sample-test` | +| Your tests | `npx browserstack-node-sdk playwright test` | +| Current SDK version | `npm view browserstack-node-sdk version` | +| Docs | https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs | diff --git a/automate/_source/parts/playwright-javascript/sample_prereq.md b/automate/_source/parts/playwright-javascript/sample_prereq.md new file mode 100644 index 0000000..58af5ce --- /dev/null +++ b/automate/_source/parts/playwright-javascript/sample_prereq.md @@ -0,0 +1,6 @@ +```bash +node -v # 20 or newer +npm -v +git --version +``` +If any is missing, tell the user what to install and stop. diff --git a/automate/_source/parts/playwright-javascript/sample_run.md b/automate/_source/parts/playwright-javascript/sample_run.md new file mode 100644 index 0000000..03b344c --- /dev/null +++ b/automate/_source/parts/playwright-javascript/sample_run.md @@ -0,0 +1,36 @@ +Before installing, update one locator in the sample. It is the only change this skill makes to +the sample's code: list it in the plan, and show the diff once applied. `tests/bstack_test_demo.js` opens the +Dropdown page with `getByRole('link', { name: 'Dropdown' })`, and the demo site +(the-internet.herokuapp.com) now also lists "Custom Dropdown" and "Multiple Select Dropdown", so +without `exact: true` the test stops with `strict mode violation: … resolved to 3 elements` on +every platform: + +```bash +if grep -q "{ name: 'Dropdown' }" tests/bstack_test_demo.js; then + sed -i.bak "s/{ name: 'Dropdown' }/{ name: 'Dropdown', exact: true }/" tests/bstack_test_demo.js && rm -f tests/bstack_test_demo.js.bak +fi +git diff tests/ +``` + +If the diff is empty, BrowserStack has fixed the sample already: carry on without the change. Then: + +```bash +npm install +npm run sample-test +``` + +`npm run sample-test` runs `npx browserstack-node-sdk playwright test --config=./playwright.config.js`: +one test (open the-internet.herokuapp.com, tick and untick two checkboxes, pick an option from the +dropdown) on every platform in `browserstack.yml` (desktop Chrome, WebKit and Firefox), one session +each. `npm install` also updates the tracked `package-lock.json`, and its `postinstall` step updates +the SDK to the latest version: list both in the plan. These lines are harmless: "Uh-oh! We +detected some issues … SDK-GEN-004" about `GLOBAL_AGENT_HTTP_PROXY` or `GLOBAL_AGENT_NO_PROXY`, and +`[UNDICI-EHPA] Warning: EnvHttpProxyAgent is experimental` (even when printed as an `error:` line). + +This repo's `tra` branch is a demo of BrowserStack's test reporting whose tests fail on purpose; +this skill runs `main`, whose one test passes once the locator is fixed. + +When you read the sample's `browserstack.yml` for the plan, look for a `browserName: Safari` on a +desktop (`os:`) row. If there is one, list the change to `playwright-webkit` with +`browserVersion: latest` in the plan, and make it after cloning, before running (find it with +`grep -niB3 "browserName: *safari" browserstack.yml`); `safari` stays only on real iPhone rows. diff --git a/automate/_source/parts/playwright-javascript/status_marking.md b/automate/_source/parts/playwright-javascript/status_marking.md new file mode 100644 index 0000000..914d75a --- /dev/null +++ b/automate/_source/parts/playwright-javascript/status_marking.md @@ -0,0 +1,3 @@ + - The SDK marks desktop, Android and real iPhone sessions (iPhone tested with SDK 1.80.4); an iPhone build's own status can still read `done`, so report from the sessions. Every + session is left `done` when the SDK prints `Binary CLI failed to start — running in direct + flow`: re-run once in that case, then mark from the runner's result as shown below. diff --git a/automate/_source/parts/playwright-javascript/troubleshooting.md b/automate/_source/parts/playwright-javascript/troubleshooting.md new file mode 100644 index 0000000..63168fa --- /dev/null +++ b/automate/_source/parts/playwright-javascript/troubleshooting.md @@ -0,0 +1,9 @@ +| `configLoader.js doesn't exist` before any session | The SDK is older than the project's Playwright: update `browserstack-node-sdk`; if needed pin Playwright to `1.64.1` (B2, step 2) | +| `Binary CLI failed to start — running in direct flow` | The SDK's helper timed out; tests still run but sessions are left `done`. Re-run once, then mark from the runner's result | +| iOS: `Only one browser context is allowed` | Real iOS allows one context per session: one test per session, no multi-context tests | +| Tests pass but the API shows no build | Run through `npx browserstack-node-sdk playwright test`, and check for a custom `launch()` or `connect()` (B1) | +| Real Android Chrome: `click()` times out with " intercepts pointer events", and the intercepting element changes on every retry | The page is wider than the phone screen, so Chrome scrolls only the visible area and Playwright checks the wrong spot (seen on Galaxy S23 and Pixel 9; desktop and iPhone unaffected). Report it as Android-specific. With the user's OK, scroll the page to the element before the click (`await el.evaluate(e => window.scrollTo(0, e.getBoundingClientRect().top + scrollY - 120))`) or use `click({ force: true })` for that click on Android only; the lasting fix is removing the page's horizontal overflow | +| Output stops for 5 minutes or more and the API shows no new session for that platform | A browser connection hung (a slow start can also take 3 to 5 minutes). Press Ctrl-C once: the SDK still closes the build and prints the dashboard link. Report those tests as interrupted or not run | +| `Invalid 'browser'. Use 'chrome', 'edge', 'playwright-chromium', 'playwright-webkit' or 'playwright-firefox' only` | A desktop row has `browserName: Safari`: change it to `playwright-webkit` with `browserVersion: latest`. Keep `safari` only on real iPhone rows | +| `browserType.connect: Error: Unsupported browser version` on a `playwright-webkit` row | The row kept a Safari version (for example `15.6`): set `browserVersion: latest` | +| Sample build: `strict mode violation: getByRole('link', { name: 'Dropdown' }) resolved to 3 elements` on every platform | The locator fix in A4 wasn't applied: apply it and re-run with a new build name | diff --git a/automate/_source/parts/playwright-python/next_offers.md b/automate/_source/parts/playwright-python/next_offers.md new file mode 100644 index 0000000..3ce1cd6 --- /dev/null +++ b/automate/_source/parts/playwright-python/next_offers.md @@ -0,0 +1,7 @@ +- **Real iPhone:** add a real iPhone 15 (Safari) as its own build (B1 has the row and how). After + an iPhone-only run, offer the desktop build instead. Set expectations first: + Playwright on real iOS is a custom WebKit integration with limits (for example one browser + context per session, and some keyboard and multi-tab behaviour differs from desktop WebKit), so + a failure there doesn't change the desktop results. Real Android phones need BrowserStack's device API rather + than a normal browser launch, so this skill doesn't set them up: see https://www.browserstack.com/docs/automate/playwright/playwright-android/python. +- **Wider coverage:** add Edge, older browser versions or other operating systems. diff --git a/automate/_source/parts/playwright-python/own_assess.md b/automate/_source/parts/playwright-python/own_assess.md new file mode 100644 index 0000000..0221484 --- /dev/null +++ b/automate/_source/parts/playwright-python/own_assess.md @@ -0,0 +1,46 @@ +Note these in a short Assessment block at the top of your plan: + +- **Test runner:** pytest with `pytest-playwright` (the `page` and `browser` fixtures) or behave. + Plain scripts with `sync_playwright()` can run through `browserstack-sdk python