-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathprefer-locator.test.ts
99 lines (98 loc) · 2.04 KB
/
prefer-locator.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { runRuleTester, test } from '../utils/rule-tester.js'
import rule from './prefer-locator.js'
runRuleTester('prefer-locator', rule, {
invalid: [
{
code: test(`await page.fill('input[type="password"]', 'password')`),
errors: [
{
column: 34,
endColumn: 81,
endLine: 1,
line: 1,
messageId: 'preferLocator',
},
],
output: null,
},
{
code: test(`await page.dblclick('xpath=//button')`),
errors: [
{
column: 34,
endColumn: 65,
endLine: 1,
line: 1,
messageId: 'preferLocator',
},
],
output: null,
},
{
code: `page.click('xpath=//button')`,
errors: [
{
column: 1,
endColumn: 29,
endLine: 1,
line: 1,
messageId: 'preferLocator',
},
],
output: null,
},
{
code: test(`await page.frame('frame-name').click('css=button')`),
errors: [
{
column: 34,
endColumn: 78,
endLine: 1,
line: 1,
messageId: 'preferLocator',
},
],
output: null,
},
{
code: `page.frame('frame-name').click('css=button')`,
errors: [
{
column: 1,
endColumn: 45,
endLine: 1,
line: 1,
messageId: 'preferLocator',
},
],
output: null,
},
],
valid: [
{
code: `const locator = page.locator('input[type="password"]')`,
},
{
code: test(
`await page.locator('input[type="password"]').fill('password')`,
),
},
{
code: test(`await page.locator('xpath=//button').dblclick()`),
},
{
code: `page.locator('xpath=//button').click()`,
},
{
code: test(
`await page.frameLocator('#my-iframe').locator('css=button').click()`,
),
},
{
code: test(`await page.evaluate('1 + 2')`),
},
{
code: `page.frame('frame-name')`,
},
],
})