|
1 | 1 | # playwright-browserstack
|
2 |
| -Sample repo for Playwright samples with BrowserStack. |
| 2 | +Sample Playwright tests to run on BrowserStack |
| 3 | + |
| 4 | +## Introduction |
| 5 | + |
| 6 | +You can now run your Playwright tests on the BrowserStack infrastructure. Porting your existing Playwright tests to run on BrowserStack, can be done in a matter of minutes. |
| 7 | + |
| 8 | +This guide walks you through running a sample Playwright test on BrowserStack and then goes on to run tests on privately hosted websites and also shows cross-browser tests run in parallel to speed up the build execution. |
| 9 | + |
| 10 | +## Pre-requisites |
| 11 | + |
| 12 | +You need BrowserStack credentials to be able to run Playwright tests and also you need to be included in the Beta group so that we can enable Playwright access for you in our infra while the integration is in closed-beta. |
| 13 | + |
| 14 | +If you have already been included in the beta group, proceed ahead. Else, you can [reach out to support](https://www.browserstack.com/contact#technical-support) to get included in the beta group. |
| 15 | + |
| 16 | +You have to replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` in the sample scripts in this repository with your BrowserStack credentials which can be found in your [Account Settings](https://www.browserstack.com/accounts/settings) page. |
| 17 | + |
| 18 | +**Alternatively, you can set the environment variables `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` with your credentials and all the scripts in this repository should work fine** |
| 19 | + |
| 20 | +## Run your first Playwright test on BrowserStack |
| 21 | + |
| 22 | +1. Clone this repository |
| 23 | +2. Install the dependencies using `npm install` |
| 24 | +3. Run the sample script using `node google_search.js` |
| 25 | + |
| 26 | +**Important Note**: When you try to run your Playwright tests on BrowserStack, you need to pass your locally installed client Playwright version in the capability `client.playwrightVersion`. This is required because it is often possible that your locally installed version might be different than the server version running on BrowserStack and the mismatch could lead to different request/response formats leading to socket errors. |
| 27 | + |
| 28 | +Playwright does not pass the client version information in the `connect` request yet and hence this capability is required to let BrowserStack know about your locally installed version, to avoid any error scenarios arising from this. **This has already been taken care in the sample scripts under this repository**. |
| 29 | + |
| 30 | +## Run cross-browser tests in parallel |
| 31 | + |
| 32 | +1. Clone this repository |
| 33 | +2. Install the dependencies using `npm install` |
| 34 | +3. Run the `parallel_test.js` script using `node parallel_test.js` |
| 35 | + |
| 36 | +## Run sample test on privately hosted websites |
| 37 | + |
| 38 | +1. You have to download the BrowserStack Local binary from the links below (depending on your environment): |
| 39 | + * [OS X (10.7 and above)](https://www.browserstack.com/browserstack-local/BrowserStackLocal-darwin-x64.zip) |
| 40 | + * [Linux 32-bit](https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-ia32.zip) |
| 41 | + * [Linux 64-bit](https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip) |
| 42 | + * [Windows (XP and above)](https://www.browserstack.com/browserstack-local/BrowserStackLocal-win32.zip) |
| 43 | +2. Once you have downloaded and unzipped the file, you can initiate the binary by running the command: `./BrowserStackLocal --key YOUR_ACCESS_KEY` |
| 44 | +3. Once you see the terminal say “\[SUCCESS\] You can now access your local server(s) in our remote browser”, your local testing connection is considered established. |
| 45 | +4. You can then run the sample Local test using `node local_test.js` |
| 46 | + |
| 47 | +## Supported Browsers and Playwright versions |
| 48 | + |
| 49 | +BrowserStack Playwright tests in beta supports the following browsers across the following OS versions: |
| 50 | + |
| 51 | +### Browsers supported |
| 52 | +1. Bundled Chromium with Playwright (`'browser': 'playwright-chromium'`) |
| 53 | +2. Bundled Firefox with Playwright (`'browser': 'playwright-firefox'`) |
| 54 | +3. Bundled Webkit with Playwright (`'browser': 'playwright-webkit'`) |
| 55 | +4. Branded Google Chrome (`'browser': 'chrome'`) |
| 56 | + * You can test on multiple versions of branded Google Chrome using another capability `'browser_version': 'latest'`. Supported options are `latest`, `latest-beta`, `latest-1` and so on. |
| 57 | + * We would be supporting Chrome v83 and above. You can also specify `browser_version` as `88` or `91` and so on. |
| 58 | +5. Branded Microsoft Edge (`'browser': 'edge'`) |
| 59 | + * You can test on multiple versions of branded Microsoft Edge using another capability `'browser_version': 'latest'`. Supported options are `latest`, `latest-beta`, `latest-1` and so on. |
| 60 | + * We would be supporting Edge v83 and above. You can also specify `browser_version` as `88` or `91` and so on. |
| 61 | + |
| 62 | +**The bundled browser version that will be used to run your test is the same that comes bundled with the Playwright version**. Supported Playwright versions and the option to specify them is given in a later section of this page. |
| 63 | + |
| 64 | +**Note**: You can also run your tests in any of the mobile `devices` that Playwright supports for emulation. You can find the [sample code for running in an iPhone emulator](https://github.com/sourav-kundu/playwright-browserstack/blob/master/sample_test_on_iPhone.js) and the [sample for running on Pixel](https://github.com/sourav-kundu/playwright-browserstack/blob/master/sample_test_on_Pixel.js). The complete list of `devices` supported by Playwright can be found [here](https://github.com/microsoft/playwright/blob/master/src/server/deviceDescriptors.js) |
| 65 | + |
| 66 | +### OS (with versions) supported |
| 67 | +1. Windows 10 (`'os': 'Windows', 'os_version': '10'`) |
| 68 | +2. macOS Big Sur (`'os': 'osx', 'os_version': 'Big Sur'`) |
| 69 | +3. macOS Catalina (`'os': 'osx', 'os_version': 'Catalina'`) |
| 70 | +4. macOS Mojave (`'os': 'osx', 'os_version': 'Mojave'`) |
| 71 | + |
| 72 | +### Playwright versions supported |
| 73 | + |
| 74 | +Currently, we are supporting 2 Playwright versions viz. `1.11.1` and `1.10.0`. |
| 75 | +Playwright version can be specified using a capability as: `'browserstack.playwrightVersion': '1.10.0'`. If you do not specify a value for this capability then your tests would run on the default version `1.11.1`. |
| 76 | + |
| 77 | +You can also pass the capability value as `'browserstack.playwrightVersion': '1.latest'` or `1.latest-1` to signify the 2 latest versions within the major version `1`. If you pass this capability, then you can be rest assured that whichever are the latest versions on BrowserStack, your tests would run on that without you needing to change your test code often. |
| 78 | + |
| 79 | +## Get Playwright session details |
| 80 | + |
| 81 | +While your Playwright session runs on BrowserStack, we generate a unique ID for the session, build and also generate URLs for the various types of logs which you can use to build your own reporting or for any other purpose that you might like. |
| 82 | + |
| 83 | +A sample script with the use of the API to fetch all the relevant session details is shown in the [sample_session_details_API.js](./sample_session_details_API.js). |
| 84 | + |
| 85 | +You can see the [documentation for marking test status using REST API](https://www.browserstack.com/docs/automate/api-reference/selenium/session#set-test-status) using the session ID for the session, any time even after the session has completed its execution. |
| 86 | + |
| 87 | +## Playwright with Jest |
| 88 | + |
| 89 | +If you are using Jest to run your Playwright tests, you can run all your playwright-jest tests on BrowserStack as well. Follow the steps below to run the sample tests in this repository: |
| 90 | + |
| 91 | +1. Clone this repository using `git clone https://github.com/sourav-kundu/playwright-browserstack.git` (if not already done). |
| 92 | +2. Go inside the directory playwright-jest using `cd playwright-jest` |
| 93 | +3. Install the dependencies using `npm install` |
| 94 | +4. Put in your credentials in the file `jest-playwright.config.js` in the capabilities part. |
| 95 | +5. If you are trying to run your own Jest tests on BrowserStack, then you need to ensure that you have configured the `connectOptions` and `browsers` as shown in the `module.exports` of the config file. |
| 96 | +6. Run the sample jest script using `npm test` which runs the test `google.test.js` across 3 browsers in BrowserStack serially. Your can also configure Jest to run your tests in parallel. |
| 97 | + |
| 98 | +## Facing issues? |
| 99 | + |
| 100 | +If you are facing any issue with any of the above or any other issue in trying to run your Playwright tests on BrowserStack, you can reach out to me directly at `[email protected]` and I will be happy to debug your issues or at the least ensure that your issue becomes our top priority to resolve. |
0 commit comments