Skip to content

Commit 3095ab4

Browse files
author
Mark Skelton
committed
feat: Add Lariat snippets
1 parent 811f085 commit 3095ab4

File tree

5 files changed

+102
-18
lines changed

5 files changed

+102
-18
lines changed

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,95 @@
1111

1212
The following snippets are provided by this package. If you have ideas of other snippets that would be helpful, please [open an issue](https://github.com/mskelton/vscode-playwright-test-snippets/issues/new).
1313

14-
### `pw-describe→`
14+
### Test blocks
15+
16+
#### `pw-describe`
1517

1618
```ts
1719
test.describe('$1', () => {
1820
$0
1921
})
2022
```
2123

22-
### `pw-test`
24+
#### `pw-test`
2325

2426
```ts
2527
test('$1', async ({ page }) => {
2628
$0
2729
})
2830
```
2931

30-
### `pw-beforeEach`
32+
#### `pw-beforeEach`
3133

3234
```ts
3335
test.beforeEach(async ({ page }) => {
3436
$0
3537
})
3638
```
3739

38-
### `pw-afterEach`
40+
#### `pw-afterEach`
3941

4042
```ts
4143
test.afterEach(async ({ page }) => {
4244
$0
4345
})
4446
```
4547

46-
### `pw-beforeAll`
48+
#### `pw-beforeAll`
4749

4850
```ts
4951
test.beforeAll(async ({ browser }) => {
5052
$0
5153
})
5254
```
5355

54-
### `pw-afterAll`
56+
#### `pw-afterAll`
5557

5658
```ts
5759
test.afterAll(async ({ browser }) => {
5860
$0
5961
})
6062
```
6163

62-
### `pw-step`
64+
#### `pw-step`
6365

6466
```ts
6567
await test.step('$1', async () => {
6668
$0
6769
})
6870
```
6971

70-
### `pw-use`
72+
#### `pw-use`
7173

7274
```ts
7375
test.use({ $0 })
7476
```
77+
78+
### Lariat
79+
80+
[Lariat](https://github.com/Widen/lariat) is a Playwright page object framework that simplifies page object construction. We've included some useful Lariat snippets as part of this extension.
81+
82+
#### `pw-collection`
83+
84+
```ts
85+
import Collection from 'lariat'
86+
87+
export class MyPage extends Collection {
88+
$0
89+
}
90+
```
91+
92+
#### `pw-page-object`
93+
94+
```ts
95+
import { Page } from '@playwright/test'
96+
import Collection from 'lariat'
97+
98+
export class MyPage extends Collection {
99+
constructor(page: Page) {
100+
super(page.locator('$1'))
101+
}
102+
103+
$0
104+
}
105+
```

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@
3030
"snippets": [
3131
{
3232
"language": "typescript",
33-
"path": "./snippets.json"
33+
"path": "./snippets/base.json"
3434
},
3535
{
3636
"language": "javascript",
37-
"path": "./snippets.json"
37+
"path": "./snippets/base.json"
38+
},
39+
{
40+
"language": "typescript",
41+
"path": "./snippets/ts.json"
42+
},
43+
{
44+
"language": "javascript",
45+
"path": "./snippets/js.json"
3846
}
3947
]
4048
},
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
{
2-
"Playwright describe": {
2+
"Playwright describe block": {
33
"prefix": "pw-describe",
44
"body": ["test.describe('$1', () => {", "\t$0", "})", ""]
55
},
6-
"Playwright test": {
6+
"Playwright test block": {
77
"prefix": "pw-test",
88
"body": ["test('$1', async ({ ${2:page} }) => {", "\t$0", "})", ""]
99
},
10-
"Playwright test.use": {
10+
"Playwright test.use block": {
1111
"prefix": "pw-use",
1212
"body": ["test.use({ $0 })", ""]
1313
},
14-
"Playwright test.step": {
14+
"Playwright test.step block": {
1515
"prefix": "pw-step",
1616
"body": ["await test.step('$1', async () => {", "\t$0", "})", ""]
1717
},
18-
"Playwright beforeEach": {
18+
"Playwright beforeEach block": {
1919
"prefix": "pw-beforeEach",
2020
"body": ["test.beforeEach(async ({ ${1:page} }) => {", "\t$0", "})", ""]
2121
},
22-
"Playwright afterEach": {
22+
"Playwright afterEach block": {
2323
"prefix": "pw-afterEach",
2424
"body": ["test.afterEach(async ({ ${1:page} }) => {", "\t$0", "})", ""]
2525
},
26-
"Playwright beforeAll": {
26+
"Playwright beforeAll block": {
2727
"prefix": "pw-beforeAll",
2828
"body": ["test.beforeAll(async ({ ${1:browser} }) => {", "\t$0", "})", ""]
2929
},
30-
"Playwright afterAll": {
30+
"Playwright afterAll block": {
3131
"prefix": "pw-afterAll",
3232
"body": ["test.afterAll(async ({ ${1:browser} }) => {", "\t$0", "})", ""]
33+
},
34+
"Lariat collection": {
35+
"prefix": "pw-collection",
36+
"body": [
37+
"import Collection from \"lariat\"",
38+
"",
39+
"export class ${TM_FILENAME_BASE/(^|-)([A-z0-9])/${2:/upcase}/g} extends Collection {",
40+
" $0",
41+
"}"
42+
]
3343
}
3444
}

snippets/js.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"Lariat page object": {
3+
"prefix": "pw-page-object",
4+
"description": "A top-level Lariat collection intended to be used in tests or fixtures.",
5+
"body": [
6+
"import Collection from \"lariat\"",
7+
"",
8+
"export class ${TM_FILENAME_BASE/(^|-)([A-z0-9])/${2:/upcase}/g} extends Collection {",
9+
" constructor(page) {",
10+
" super(page.locator(\"$1\"))",
11+
" }",
12+
"",
13+
" $0",
14+
"}"
15+
]
16+
}
17+
}

snippets/ts.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Lariat page object": {
3+
"prefix": "pw-page-object",
4+
"description": "A top-level Lariat collection intended to be used in tests or fixtures.",
5+
"body": [
6+
"import { Page } from \"@playwright/test\"",
7+
"import Collection from \"lariat\"",
8+
"",
9+
"export class ${TM_FILENAME_BASE/(^|-)([A-z0-9])/${2:/upcase}/g} extends Collection {",
10+
" constructor(page: Page) {",
11+
" super(page.locator(\"$1\"))",
12+
" }",
13+
"",
14+
" $0",
15+
"}"
16+
]
17+
}
18+
}

0 commit comments

Comments
 (0)