@@ -9,6 +9,14 @@ runRuleTester('no-raw-locators', rule, {
99 code : test ( 'await page.locator()' ) ,
1010 errors : [ { column : 34 , endColumn : 48 , line : 1 , messageId } ] ,
1111 } ,
12+ {
13+ code : test ( 'const locator = await page.locator()' ) ,
14+ errors : [ { column : 50 , endColumn : 64 , line : 1 , messageId } ] ,
15+ } ,
16+ {
17+ code : test ( 'let locator = await page.locator()' ) ,
18+ errors : [ { column : 48 , endColumn : 62 , line : 1 , messageId } ] ,
19+ } ,
1220 {
1321 code : test ( 'await this.page.locator()' ) ,
1422 errors : [ { column : 34 , endColumn : 53 , line : 1 , messageId } ] ,
@@ -37,7 +45,14 @@ runRuleTester('no-raw-locators', rule, {
3745 ) ,
3846 errors : [ { column : 77 , endColumn : 100 , line : 1 , messageId } ] ,
3947 } ,
40-
48+ {
49+ code : test ( 'const button = page.locator(); page.locator(button)' ) ,
50+ errors : [ { column : 43 , endColumn : 57 , line : 1 , messageId } ] ,
51+ } ,
52+ {
53+ code : test ( 'let button = page.locator(); page.locator(button)' ) ,
54+ errors : [ { column : 41 , endColumn : 55 , line : 1 , messageId } ] ,
55+ } ,
4156 // Allowed
4257 {
4358 code : test ( 'await page.locator("[aria-busy=false]")' ) ,
@@ -81,6 +96,14 @@ runRuleTester('no-raw-locators', rule, {
8196 'const section = page.getByRole("section"); section.getByRole("button")' ,
8297 ) ,
8398
99+ // Variable references with proper locators
100+ test (
101+ 'const button = page.getByRole("button", { name: "common button" }); page.locator(button)' ,
102+ ) ,
103+ test (
104+ 'const firstButton = page.getByRole("region", { name: "first" }).locator(button); const secondButton = page.getByRole("region", { name: "second" }).locator(button)' ,
105+ ) ,
106+
84107 // bare calls
85108 test ( '() => page.locator' ) ,
86109
0 commit comments