Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghoshasish99/playwright-k6
https://github.com/ghoshasish99/playwright-k6
functional-testing k6 performance-testing playwright
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ghoshasish99/playwright-k6
- Owner: ghoshasish99
- Created: 2024-06-05T20:33:39.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-17T14:59:37.000Z (8 months ago)
- Last Synced: 2024-11-15T06:42:34.566Z (3 months ago)
- Topics: functional-testing, k6, performance-testing, playwright
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nordic Testing Days Workshop
[![Functional-Performance Tests](https://github.com/ghoshasish99/ntd-workshop/actions/workflows/functional.yaml/badge.svg)](https://github.com/ghoshasish99/ntd-workshop/actions/workflows/functional.yaml)
## Playwright Commands
β Installation : `npm init playwright@latest`
π Run Tests : `npx playwright test`
π§ Run Tests headed : `npx playwright test --headed`
or configure your `playwright.config.js` to have the following :
```javascript
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], headless:false },
}
]
```π Show Report : `npx playwright show-report` --> this will open up the reports automatically on failure
βοΈ Parallel/Sequential execution : `npx playwright test --workers=1` --> change the value of `workers` as per the number of parrallel threads you want
π¨ You can mark tests as `test.only` to be able to run only those tests using `npx playwright test`
```javascript
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright1/);
});test.only('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.getByRole('link', { name: 'Get started' }).click();
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});```
π·οΈ Tagging :
You can tag tests by adding your relevant `tags` in the title.
```javascript
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright1/);
});test.only('get started link @smoke', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.getByRole('link', { name: 'Get started' }).click();
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});```
To be able to run only the tagged tests, you can use `npx playwright test --grep @smoke`
1οΈβ£ Running in a single browser : `npx playwright test --project=chromium`
π To collect evidences in the form of `traces` , `screenshots` or `videos`, you can configure the `playwright.config.js` like so :
```javascript
use: {
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: 'on',
}```
π₯οΈ Run in UI mode : `npx playwright test --ui`
βΊοΈ To open Playwright Recorder : `npx playwright codegen`
### To read more about Playwright, check [this.](https://playwright.dev/)
---------------------------------------------
## k6 Commands
β Installation :
* For Mac - `brew install k6`
* For Windows - `winget install k6`
β¨ Create a new Test File : `k6 new mytest.js`
π Run tests : `k6 run mytest.js`
πͺ Parameterized run : `k6 run --vus 10 --duration 30s mytest.js`
πΆ Ramp up/down set up :
```javascript
export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m30s', target: 10 },
{ duration: '20s', target: 0 },
],
};
```β How to use `Check`s :
```javascript
const res = http.get('https://httpbin.test.k6.io/');
check(res, { 'status was 200': (r) => r.status == 200 });```
π³ How to use `Group`s :
```javascript
group('Create User', function(){
let data = {
"name": "Ashish",
"job": "Testing",
}
const newUser = http.post('https://reqres.in/api/users',JSON.stringify(data));
check(newUser,{'Create Successful':(r)=>r.status==201})
console.log("Created User ID "+newUser.json().id)
sleep(3)
});```
π How to use HTML Report :
```javascript
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/2.4.0/dist/bundle.js";export function handleSummary(data) {
return {
'TestSummaryReport.html': htmlReport(data, { debug: true })
};
}```
π How to perform Browser Tests :
```javascript
import { browser } from 'k6/experimental/browser';executor: 'constant-vus',
const page = browser.newPage();
```To run these tests : `K6_BROWSER_HEADLESS=false k6 run browser.js`
### To read more about k6, check [this.](https://k6.io/)
--------------------------
## About the author
ποΈ Check out my profile : https://ashishghosh.carrd.co/
π€ Connect with me on : [![Linkedin](https://i.sstatic.net/gVE0j.png) LinkedIn](https://www.linkedin.com/in/ashish-ghosh/)
π οΈ View my work on [![GitHub](https://i.sstatic.net/tskMh.png) GitHub](https://github.com/ghoshasish99)