-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from salmanlt/patch-2
Create migrate-playwright-tests.md
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Migrate Your Existing Playwright Tests | ||
* * * | ||
|
||
LambdaTest offers an online automation platform for test automation. Therefore you can easily migrate Playwright tests from your local grid to the LambdaTest platform. | ||
|
||
In this documentation, we look at how to migrate your existing Playwright test scripts (or test suites) from your local grid to LambdaTest. This lets you automate Playwright scripts across 40+ browsers and operating systems on LambdaTest cloud platform. | ||
|
||
## Sample Playwright Script Running On A Local Machine | ||
*** | ||
|
||
With just a few lines of code tweaks in your test script, you can migrate your Playwright tests running on a local grid to LambdaTest. A sample Playwright script below launches a browser on your local machine and runs the script. | ||
|
||
```js | ||
const { chromium } = require('playwright') | ||
const { expect } = require('@playwright/test'); | ||
|
||
(async () => { | ||
const browser = await chromium.launch({ | ||
headless: false | ||
}); | ||
|
||
const page = await browser.newPage() | ||
await page.goto('https://www.bing.com') | ||
const element = await page.$('[aria-label="Enter your search term"]') | ||
await element.click() | ||
await element.type('LambdaTest') | ||
await element.press('Enter') | ||
const title = await page.title() | ||
|
||
expect(title).toEqual('LambdaTest - Search') | ||
|
||
await browser.close() | ||
})() | ||
``` | ||
|
||
## Changes In Scripts To Run Playwright Tests On LambdaTest | ||
*** | ||
|
||
The above script shows that `playwright['chromium'].launch` runs in a Chromium browser window. To run the test scripts on LambdaTest platform, you will need to add the following instead of `playwright['chromium'].launch`. | ||
|
||
```js | ||
const { chromium } = require('playwright') | ||
const { expect } = require('@playwright/test'); | ||
|
||
(async () => { | ||
const capabilities = { | ||
'browserName': 'Chrome', // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit` | ||
'browserVersion': 'latest', | ||
'LT:Options': { | ||
'platform': 'Windows 10', | ||
'build': 'Playwright Sample Build', | ||
'name': 'Playwright Sample Test', | ||
'user': process.env.LT_USERNAME, | ||
'accessKey': process.env.LT_ACCESS_KEY, | ||
} | ||
} | ||
|
||
const browser = await chromium.connect({ | ||
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}` | ||
}) | ||
|
||
// Test code ... | ||
|
||
await browser.close() | ||
})() | ||
``` | ||
|
||
In the above code snippet, you need to connect to the CDP endpoint at LambdaTest using `chromium.connect` method. The `capabilities` variable contains additional parameters that enable a specific browser and OS combination to be assigned to your test on LambdaTest. | ||
|
||
## Selecting Browser-OS Combinations For Test Runs | ||
*** | ||
|
||
To run your script, you can choose any of the browsers and OS combinations. Just specify the browserName, browserVersion, platform in the capabilities JSON before calling the CDP endpoint. |