Skip to content

Commit 630201b

Browse files
committed
fix: Use browser.$() for element instead of $()
1 parent 24e4fdb commit 630201b

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/recording/code-generator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,25 @@ function generateStep(step: RecordedStep): string {
7878
case 'navigate':
7979
return `await browser.url('${escapeStr(p.url)}');`;
8080
case 'click_element':
81-
return `await $('${escapeStr(p.selector)}').click();`;
81+
return `await browser.$('${escapeStr(p.selector)}').click();`;
8282
case 'set_value':
83-
return `await $('${escapeStr(p.selector)}').setValue('${escapeStr(p.value)}');`;
83+
return `await browser.$('${escapeStr(p.selector)}').setValue('${escapeStr(p.value)}');`;
8484
case 'scroll': {
8585
const scrollAmount = (p.direction as string) === 'down' ? (p.pixels as number) : -(p.pixels as number);
8686
return `await browser.execute(() => window.scrollBy(0, ${scrollAmount}));`;
8787
}
8888
case 'tap_element':
8989
if (p.selector !== undefined) {
90-
return `await $('${escapeStr(p.selector)}').click();`;
90+
return `await browser.$('${escapeStr(p.selector)}').click();`;
9191
}
9292
return `await browser.tap({ x: ${p.x}, y: ${p.y} });`;
9393
case 'swipe':
9494
return `await browser.execute('mobile: swipe', { direction: '${escapeStr(p.direction)}' });`;
9595
case 'drag_and_drop':
9696
if (p.targetSelector !== undefined) {
97-
return `await $('${escapeStr(p.sourceSelector)}').dragAndDrop($('${escapeStr(p.targetSelector)}'));`;
97+
return `await browser.$('${escapeStr(p.sourceSelector)}').dragAndDrop(browser.$('${escapeStr(p.targetSelector)}'));`;
9898
}
99-
return `await $('${escapeStr(p.sourceSelector)}').dragAndDrop({ x: ${p.x}, y: ${p.y} });`;
99+
return `await browser.$('${escapeStr(p.sourceSelector)}').dragAndDrop({ x: ${p.x}, y: ${p.y} });`;
100100
default:
101101
return `// [unknown tool] ${step.tool}`;
102102
}

tests/recording/code-generator.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ describe('generateCode - tool mappings', () => {
9595

9696
it('click_element → $().click()', () => {
9797
const code = generateCode(makeHistory([{ tool: 'click_element', params: { selector: '#btn' } }]));
98-
expect(code).toContain("await $('#btn').click();");
98+
expect(code).toContain("await browser.$('#btn').click();");
9999
});
100100

101101
it('set_value → $().setValue()', () => {
102102
const code = generateCode(makeHistory([{ tool: 'set_value', params: { selector: '#input', value: 'hello' } }]));
103-
expect(code).toContain("await $('#input').setValue('hello');");
103+
expect(code).toContain("await browser.$('#input').setValue('hello');");
104104
});
105105

106106
it('scroll down → positive scrollBy', () => {
@@ -115,7 +115,7 @@ describe('generateCode - tool mappings', () => {
115115

116116
it('tap_element (selector form) → $().click()', () => {
117117
const code = generateCode(makeHistory([{ tool: 'tap_element', params: { selector: '~btn' } }]));
118-
expect(code).toContain("await $('~btn').click();");
118+
expect(code).toContain("await browser.$('~btn').click();");
119119
});
120120

121121
it('tap_element (coordinate form) → browser.tap()', () => {
@@ -133,15 +133,15 @@ describe('generateCode - tool mappings', () => {
133133
tool: 'drag_and_drop',
134134
params: { sourceSelector: '#from', targetSelector: '#to' },
135135
}]));
136-
expect(code).toContain("await $('#from').dragAndDrop($('#to'));");
136+
expect(code).toContain("await browser.$('#from').dragAndDrop(browser.$('#to'));");
137137
});
138138

139139
it('drag_and_drop (coordinate form) → $().dragAndDrop({ x, y })', () => {
140140
const code = generateCode(makeHistory([{
141141
tool: 'drag_and_drop',
142142
params: { sourceSelector: '#from', x: 50, y: 75 },
143143
}]));
144-
expect(code).toContain("await $('#from').dragAndDrop({ x: 50, y: 75 });");
144+
expect(code).toContain("await browser.$('#from').dragAndDrop({ x: 50, y: 75 });");
145145
});
146146
});
147147

0 commit comments

Comments
 (0)