|
1 | 1 | # smartui-playwright-sample
|
2 |
| -Playwright sample for running visual regression tests using SmartUI |
| 2 | +# LambdaTest SmartUI Playwright Sample |
| 3 | + |
| 4 | +This project demonstrates how to use playwright and LambdaTest together to run automated tests on the LambdaTest platform. |
| 5 | + |
| 6 | +## Setup |
| 7 | + |
| 8 | +First, clone this repository to your local machine. |
| 9 | + |
| 10 | +```bash |
| 11 | +git clone https://github.com/LambdaTest/smartui-playwright-sample.git |
| 12 | +cd smartui-playwright-sample |
| 13 | +``` |
| 14 | + |
| 15 | +Next, install the necessary dependencies: |
| 16 | + |
| 17 | +```bash |
| 18 | +npm i |
| 19 | +``` |
| 20 | + |
| 21 | +You'll need to set your LambdaTest username and access key as environment variables. They can be found on your LambdaTest profile. |
| 22 | + |
| 23 | +```bash |
| 24 | +export LT_USERNAME="Your LambdaTest Username" |
| 25 | +export LT_ACCESS_KEY="Your LambdaTest Access Key" |
| 26 | +``` |
| 27 | + |
| 28 | +## About the Test |
| 29 | + |
| 30 | +The test navigates to the LambdaTest homepage and checks the page title. After the title check, it will take a full-page screenshot for visual regression testing. |
| 31 | + |
| 32 | +## About SmartUI Webhook |
| 33 | + |
| 34 | +LambdaTest's SmartUI uses a webhook to call the `smartui.takeScreenshot` function. This function captures a screenshot of the full page and uses it for visual regression testing. The function is called using the `page.evaluate` method with the `lambdatest_action` parameter. |
| 35 | + |
| 36 | +Here's an example of how to use the `smartui.takeScreenshot` function: |
| 37 | + |
| 38 | +```javascript |
| 39 | +await page.evaluate((_) => {}, |
| 40 | + `lambdatest_action: ${JSON.stringify({ action: 'smartui.takeScreenshot', arguments: { fullPage: true, screenshotName: '<Your_Screenshot_Name>' } |
| 41 | + })}`) |
| 42 | +``` |
| 43 | + |
| 44 | +Replace `<Your Screenshot Name>` with a relevant name for the screenshot. The screenshot will be saved with this name in the LambdaTest platform, and you can use it for comparing the UI changes over time. |
| 45 | + |
| 46 | +## Running Tests |
| 47 | + |
| 48 | +To run the test, execute: |
| 49 | + |
| 50 | +```bash |
| 51 | +node playwright-smartui.js |
| 52 | +``` |
0 commit comments