<!-- KeepSnappy docs for keepsnappy CLI 0.1.0-alpha.35 -->

# Real phones on BrowserStack

> Measure your app on real iOS or Android phones on BrowserStack.

This page is for teams that want results from real phones on BrowserStack, iOS or Android. During the pilot, the KeepSnappy team sets up BrowserStack runs with you. Ask the person who invited you.

## What you need

- A BrowserStack account.
- Maestro flows or an Appium suite. The BrowserStack package of e2e (e2e.com) doesn't work with KeepSnappy yet ([e2e](https://keepsnappy.com/docs/test-tools/e2e.md#other-setups)).
- A [measuring build](https://keepsnappy.com/docs/glossary.md#measuring-build) with the [SDK key](https://keepsnappy.com/docs/glossary.md#sdk-key) and the API address in it. On BrowserStack the app sends its own measurements ([The build switch](https://keepsnappy.com/docs/sdk.md#the-build-switch)).
- Two KeepSnappy keys: the CI key in your CI job, and the SDK key in the build ([Keys](https://keepsnappy.com/docs/keys.md#which-keys-your-setup-needs)).

## How it runs

A BrowserStack session uses the [`farm`](https://keepsnappy.com/docs/glossary.md#farm) command instead of `keepsnappy run`, because the `keepsnappy` command never touches the phone itself:

1. `farm open` starts a KeepSnappy session and writes a token for each run into a file that your flows read.
2. Your test tool runs your journeys on BrowserStack's phones. Before each run, the app is switched on with its token through the [activation link](https://keepsnappy.com/docs/glossary.md#activation), and then it sends its measurements to KeepSnappy itself.
3. `farm close` waits until the measurements stop arriving, then closes the session. With `--wait`, it also waits for the result and prints it.

The `run` subcommand of `farm` does all three in one command. Every flag is in the [CLI reference](https://keepsnappy.com/docs/reference/cli.md#farm).

An example workflow ships in the `@keepsnappy/agent` package, at `examples/farm/workflows/keepsnappy-measure.yml`. Its `KEEPSNAPPY_CLI` is `@keepsnappy/agent`, the latest release. A copy from an older CLI names a version there: change it to `@keepsnappy/agent` before you run it.

## Check a WebdriverIO suite before measuring

- Use the same orientation for the baseline and pull request. For a portrait journey, set `deviceOrientation` to `portrait` under `bstack:options` and check that the first screen has the expected layout.
- Run a short smoke test on each device and OS version you plan to measure. Inspect `browser.getPageSource()` on the first screen and confirm that it contains the elements your selectors need. On Android, a view may be visible on screen while Appium's accessibility tree omits its children. The smoke test should stop there if the first selector cannot work.
- Exercise any app activation, deep links and gestures your suite uses. BrowserStack's Appium server and drivers can differ from your local versions. If a command is unavailable, choose a supported server with `appiumVersion` under `bstack:options`, or use a command supported by the farm. Run the smoke test again with the same capabilities you will measure with. [BrowserStack capabilities](https://www.browserstack.com/app-automate/capabilities)
- If the BrowserStack service writes `log/` or `logs/` under your suite, ignore those directories in Git. For a `.gitignore` in the suite directory, add `/log/` and `/logs/`. The logs can contain session credentials.

## Time and cost

A session on BrowserStack uses BrowserStack minutes as well as your CI minutes ([Time and cost](https://keepsnappy.com/docs/cost.md)). BrowserStack keeps the phone reserved after a run fails, so a session with a failed run takes longer and uses more BrowserStack minutes.

If a session ends with no data, see [Troubleshooting](https://keepsnappy.com/docs/troubleshooting.md#fix-common-problems).

All KeepSnappy docs for agents: https://keepsnappy.com/llms.txt
