Skip to content

Insecure skip tls #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,26 @@ Clone the generated repository on your local machine, move to the project root f
$ npm i
```

### Install playwright

Execute command below to install playwright with browser engines (chromium, firefox, webkit)

```bash
$ npx playwright-core install
```

## Running k6 tests

To run a k6 test:

```bash
$ npm run k6 dist/k6/example-test.js
$ npm run k6 /dist/k6/example-test.js
```

This command does the following things:
* Transpiles the Typescript files from `./src` to Javascript test files in the `./dist` folder using `Babel` and `Webpack` (you can also do this separately using `npm run build`). [Learn more](https://k6.io/docs/using-k6/modules#bundling-node-modules)
* Runs the provided transpiled test with k6 using the Dockerfile and docker-compose, which will mount the `./dist` folder to `/dist`, making the tests in there available for the container.
* Runs executed with option `--insecure-skip-tls-verify` [insecure skip TLS verify](https://k6.io/docs/using-k6/k6-options/reference/#insecure-skip-tls-verify)

### Assumptions
- The tests need to have the "_test_" word in the name to distinguish them from auxiliary files. You can change the entry [here](./webpack.config.js#L8).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"scripts": {
"playwright": "npx playwright test",
"k6": "npm run build && docker-compose run -T xk6-browser run --",
"k6": "npm run build && docker-compose run -T xk6-browser run --insecure-skip-tls-verify --",
"build": "export NODE_OPTIONS=--openssl-legacy-provider && npx webpack"
}
}
13 changes: 13 additions & 0 deletions src/fixtures/pages.fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test as base } from '@playwright/test';
import { k6MainPage } from "@pages/k6MainPage";

type PageFixtures = {
mainPage: k6MainPage;
};

export const test = base.extend<PageFixtures>({
mainPage: async ({ page }, use) => {
await use(new k6MainPage(page));
},
});
export { expect } from '@playwright/test';
7 changes: 4 additions & 3 deletions src/k6/example-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { check } from 'k6';
import { Options } from 'k6/options';
// @ts-ignore k6 types for typescript does not contain chromium, we should ignore this error
import { chromium } from 'k6/experimental/browser';
import { clickCheckboxOnk6 } from '@pages/example-page';

import { k6MainPage } from '@pages/k6MainPage';

export let options: Options = {
vus: 1,
Expand All @@ -16,7 +16,8 @@ export default async function () {
const context = browser.newContext();
const page = context.newPage();
try {
await clickCheckboxOnk6(page);
let mainPage: k6MainPage = new k6MainPage(page);
await mainPage.clickCheckboxOnk6();
check(page, {
'checkbox is checked': (p) =>
p.locator('#checkbox-info-display').textContent() === 'Thanks for checking the box',
Expand Down
6 changes: 0 additions & 6 deletions src/pages/example-page.ts

This file was deleted.

24 changes: 24 additions & 0 deletions src/pages/k6MainPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Locator, Page, expect } from "@playwright/test";

export class k6MainPage {
constructor(
private page: Page,
private firstCheckBox: Locator = page.locator('#checkbox1'),
private checkBox: Locator = page.locator('#checkbox-info-display'),
){

}

async gotoTestK6() {
await this.page.goto('https://test.k6.io/browser.php', { waitUntil: 'networkidle' })
}

async clickCheckboxOnk6() {
this.gotoTestK6();
this.firstCheckBox.check();
}

async verifyCheckboxText(text: string) {
await expect(this.checkBox).toHaveText(text);
}
}
12 changes: 4 additions & 8 deletions src/playwright/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { test, expect } from '@playwright/test';
import { clickCheckboxOnk6 } from '../pages/example-page';
import { test } from '@fixtures/pages.fixtures';

test('checkbox should have been clicked', async ({ page }) => {
await clickCheckboxOnk6(page);

const checkBox = page.locator('#checkbox-info-display');

await expect(checkBox).toHaveText('Thanks for checking the box');
test('checkbox should have been clicked', async ({ mainPage }) => {
await mainPage.clickCheckboxOnk6();
await mainPage.verifyCheckboxText('Thanks for checking the box');
});
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@pages/*": [
"./pages/*"
]
"@pages/*": ["src/pages/*"],
"@fixtures/*": ["src/fixtures/*"]
}
}
}