Skip to content

Commit 157c48a

Browse files
heitortsergentankur22
authored andcommitted
Style guide edits
1 parent 789a329 commit 157c48a

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

docs/sources/k6/v1.3.x/using-k6-browser/migrate-from-playwright-to-k6.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ weight: 325
66

77
# Migrate a Playwright script to k6
88

9-
Playwright is an end-to-end test framework for modern web apps. It can be used for web testing across browsers, mobile web testing, API testing, and general-purpose browser automation.
9+
Playwright is an end-to-end testing framework for modern web apps. You can use it for web testing across browsers, mobile web testing, API testing, and general-purpose browser automation.
1010

11-
You can convert your Playwright scripts to k6 browser scripts, and then use them in:
11+
You can convert your Playwright scripts to k6 browser scripts and use them in the following ways:
1212

13-
- k6 OSS or Grafana Cloud k6, to run performance tests and frontend testing at the same time, and see how your application behaves in a real-world scenario.
14-
- Synthetic Monitoring, and make sure your application is being monitored and working correctly on a consistent schedule.
13+
- Run performance tests and frontend testing simultaneously in k6 OSS or Grafana Cloud k6 to see how your application behaves in real-world scenarios.
14+
- Use Synthetic Monitoring to ensure your application is monitored and working correctly on a consistent schedule.
1515

1616
In this guide, you'll learn the key differences between Playwright and k6, and how to migrate your scripts.
1717

@@ -23,7 +23,7 @@ To run a k6 test, you'll need:
2323

2424
## Example migration
2525

26-
Here's an example Playwright script, and common steps you can take to migrate it to a k6 script:
26+
The following example shows a Playwright script and the common steps to migrate it to a k6 script:
2727

2828
```js
2929
import { test, expect } from '@playwright/test';
@@ -36,7 +36,7 @@ test('has title', async ({ page }) => {
3636
});
3737
```
3838

39-
Create a new file named `pw-migrated.js`. Copy this initial k6 script setup:
39+
Create a new file named `pw-migrated.js` and copy the following initial k6 script setup:
4040

4141
```js
4242
import { expect } from "https://jslib.k6.io/k6-testing/0.6.0/index.js";
@@ -56,11 +56,11 @@ export const options = {
5656
};
5757

5858
export default async function () {
59-
// paste here
59+
// Paste your test code here
6060
}
6161
```
6262

63-
k6 browser is a library that's part of k6. Any Playwright script that you migrate needs to include the `import { browser } from 'k6/browser';` line at the top.
63+
k6 browser is a library that's part of k6. Any Playwright script that you migrate must include the `import { browser } from 'k6/browser';` line at the top.
6464

6565
k6 browser doesn't implement a `test` framework. Instead, the logic of test is handled inside the `export default async function ()`.
6666

@@ -91,7 +91,7 @@ export default async function () {
9191
}
9292
```
9393

94-
k6 doesn't implement `fixtures` like Playwright does. Instead, you'll need to use the `browser` class to retrieve a `page` within its own context. After that, you can use the usual `page` methods such as `goto` or `click`:
94+
k6 doesn't implement fixtures like Playwright does. Instead, use the `browser` class to retrieve a `page` within its own context. After that, you can use the usual `page` methods such as `goto` or `click`:
9595

9696
```js
9797
import { expect } from "https://jslib.k6.io/k6-testing/0.6.0/index.js";
@@ -111,7 +111,7 @@ export const options = {
111111
};
112112

113113
export default async function () {
114-
const page = await browser.newPage(); // <- creating a new page in its own incognito context
114+
const page = await browser.newPage(); // Create a new page in its own incognito context
115115
await page.goto('https://playwright.dev/');
116116

117117
// Expect a title "to contain" a substring.
@@ -176,7 +176,7 @@ ui ✓ [======================================] 1 VUs 00m02.2s/10m0s 1/1 sha
176176
177177
## Migrate multiple tests
178178
179-
This example shows a Playwright test file containing two tests. To migrate multiple tests, use k6 scenarios to create equivalent test logic:
179+
The following example shows a Playwright test file that contains two tests. To migrate multiple tests, use k6 scenarios to create equivalent test logic:
180180
181181
```js
182182
import { test, expect } from '@playwright/test';
@@ -246,11 +246,11 @@ export const options = {
246246
};
247247

248248
export async function adminLogin() {
249-
// paste here
249+
// Paste admin test code here
250250
}
251251

252252
export async function userLogin() {
253-
// paste here
253+
// Paste user test code here
254254
}
255255
```
256256
@@ -383,11 +383,11 @@ user ✓ [======================================] 1 VUs 00m06.0s/10m0s 1/1 sh
383383
384384
### Test isolation patterns
385385
386-
In k6, [scenarios](https://grafana.com/docs/k6/latest/using-k6/scenarios/) let you configure and model diverse workloads and organize your tests. Playwright has a dedicated test framework. The difference stems from k6 being a performance testing tool.
386+
In k6, [scenarios](https://grafana.com/docs/k6/latest/using-k6/scenarios/) let you configure and model diverse workloads and organize your tests. Playwright has a dedicated testing framework. This difference stems from k6 being a performance testing tool.
387387
388388
{{< admonition type="note" >}}
389389
390-
There are plans to create a test framework in k6. You can refer to this [GitHub issue](https://github.com/grafana/k6-jslib-testing/issues/30) for more details, or if you'd like to contribute.
390+
There are plans to create a testing framework in k6. For more details or to contribute, refer to this [GitHub issue](https://github.com/grafana/k6-jslib-testing/issues/30).
391391
392392
{{< /admonition >}}
393393
@@ -399,35 +399,35 @@ Refer to [Built-in metrics](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/me
399399
400400
### k6 concepts
401401
402-
k6 was originally designed as a load testing tool, so there are concepts that are important to understand in order to use the tool:
402+
To effectively use k6 for browser testing, it's important to understand a few core concepts from its load testing foundation:
403403
404-
- **Virtual User**: A Virtual User (VU) is an independent thread of execution that runs concurrently with other VU threads. Often, scripts are designed so that one VU activity represents that of one real user.
405-
- **Iteration**: The number of times a single VU will run the test script.
406-
- **Thresholds and checks**: [Thresholds](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/thresholds/) are pass/fail criteria that you can configure for your test metrics. For example, you can configure a threshold for your test to fail if more than 1% of requests return an error. [Checks](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/checks/) validate a boolean condition in your test. For example, you can check if the status code for a response is equal to 200. The main difference between the two is that thresholds that are not met make a test finish with a failed status, while checks do not. k6 also provides a k6-testing library that behaves similarly to how assertions work in Playwright. Refer to the [k6-testing](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/) docs for more details.
404+
- **Virtual User**: A Virtual User (VU) is an independent thread of execution that runs concurrently with other VUs. Scripts are often designed so that one VU represents the activity of one real user.
405+
- **Iteration**: The number of times a single VU runs the test script.
406+
- **Thresholds and checks**: [Thresholds](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/thresholds/) are pass/fail criteria that you configure for your test metrics. For example, you can configure a threshold to fail if more than 1% of requests return an error. [Checks](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/checks/) validate a boolean condition in your test. For example, you can check whether the response status code equals 200. The main difference is that unmet thresholds cause a test to finish with a failed status, while checks don't. k6 also provides a k6-testing library that behaves similarly to assertions in Playwright. For more details, refer to the [k6-testing](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/) documentation.
407407
408408
### Browser context restrictions
409409
410-
Unlike in Playwright, k6 can only work with a single `browserContext` at a time. The following script fails when running it with k6:
410+
Unlike Playwright, k6 can only work with a single `browserContext` at a time. The following script fails when you run it with k6:
411411
412412
<!-- md-k6:skip -->
413413
414414
```js
415415
const bc1 = await browser.newContext();
416-
// This next call will result in an error "existing browser context must be closed before creating a new one"
416+
// This next call results in an error: "existing browser context must be closed before creating a new one"
417417
const bc2 = await browser.newContext();
418418
```
419419
420-
To fix it, you'll have to close the existing `browserContext` first, before creating a new one.
420+
To fix this, close the existing `browserContext` before creating a new one.
421421
422422
## Hybrid tests
423423
424-
Hybrid tests are performance tests that run browser-level and protocol-level requests at the same time. Hybrid tests are a great alternative to running resource-intensive browser-based load testing, while still measuring how an application performs under load by making requests to the frontend and backend.
424+
Hybrid tests are performance tests that run browser-level and protocol-level requests simultaneously. They're a great alternative to resource-intensive browser-based load testing, while still measuring application performance under load by making requests to both the frontend and backend.
425425
426426
Refer to [Hybrid performance with k6 browser](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/hybrid-approach-to-performance/) for more details.
427427
428428
## Run k6 tests in Grafana Cloud
429429
430-
In addition to running k6 scripts locally by installing k6 in your machine, you can also use Grafana Cloud for a seamless experience. Using Grafana Cloud means you don't have to worry about if your machine has the right resources to run a performance test, while also having pre-made Grafana dashboards to analyze test results, and being able to collaborate with other team members in debugging performance issues.
430+
In addition to running k6 scripts locally by installing k6 on your machine, you can use Grafana Cloud for a seamless experience. Using Grafana Cloud means you don't have to worry about whether your machine has the right resources to run a performance test. You also get pre-made Grafana dashboards to analyze test results and can collaborate with other team members to debug performance issues.
431431
432432
Refer to [Run a test using Grafana Cloud k6](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/run-k6-test-script/#run-a-test-using-grafana-cloud-k6) for more details.
433433

0 commit comments

Comments
 (0)