Skip to content

Commit b05d90d

Browse files
DavertMikclaude
andcommitted
test: add acceptance tests for els module
- Add comprehensive acceptance tests for element(), eachElement(), expectElement(), expectAnyElement(), expectAllElements() - Update WebElement class to handle Playwright Locator objects: - type() uses fill() for Locator objects - $() and $$() use locator() and elementHandle() methods for Locator objects - Fix session_test.js import paths for ESM - 30 acceptance tests + 15 unit tests passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c2706a2 commit b05d90d

4 files changed

Lines changed: 389 additions & 4 deletions

File tree

lib/element/WebElement.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ class WebElement {
237237
async type(text, options = {}) {
238238
switch (this.helperType) {
239239
case 'playwright':
240+
// Playwright Locator objects use fill() instead of type()
241+
if (this.element.fill) {
242+
return this.element.fill(text, options)
243+
}
240244
return this.element.type(text, options)
241245
case 'webdriver':
242246
return this.element.setValue(text)
@@ -257,7 +261,18 @@ class WebElement {
257261

258262
switch (this.helperType) {
259263
case 'playwright':
260-
childElement = await this.element.$(this._normalizeLocator(locator))
264+
// Playwright Locator objects use locator() method
265+
if (this.element.locator) {
266+
const childLocator = this.element.locator(this._normalizeLocator(locator))
267+
// Get the element handle from the locator
268+
try {
269+
childElement = await childLocator.elementHandle()
270+
} catch (e) {
271+
return null
272+
}
273+
} else {
274+
childElement = await this.element.$(this._normalizeLocator(locator))
275+
}
261276
break
262277
case 'webdriver':
263278
try {
@@ -286,7 +301,14 @@ class WebElement {
286301

287302
switch (this.helperType) {
288303
case 'playwright':
289-
childElements = await this.element.$$(this._normalizeLocator(locator))
304+
// Playwright Locator objects use locator() method
305+
if (this.element.locator) {
306+
const childLocator = this.element.locator(this._normalizeLocator(locator))
307+
// Get all element handles from the locator
308+
childElements = await childLocator.elementHandles()
309+
} else {
310+
childElements = await this.element.$$(this._normalizeLocator(locator))
311+
}
290312
break
291313
case 'webdriver':
292314
childElements = await this.element.$$(this._normalizeLocator(locator))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import TestHelper from '../support/TestHelper.js'
2+
3+
export const config = {
4+
tests: './els_test.js',
5+
timeout: 10,
6+
output: './output',
7+
grep: '@Playwright',
8+
helpers: {
9+
Playwright: {
10+
url: TestHelper.siteUrl(),
11+
show: false,
12+
restart: process.env.BROWSER_RESTART || false,
13+
browser: process.env.BROWSER || 'chromium',
14+
ignoreHTTPSErrors: true,
15+
waitForTimeout: 5000,
16+
waitForAction: 500,
17+
chromium: {
18+
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
19+
},
20+
},
21+
},
22+
include: {},
23+
bootstrap: false,
24+
mocha: {},
25+
plugins: {
26+
screenshotOnFail: {
27+
enabled: true,
28+
},
29+
},
30+
name: 'acceptance',
31+
}

0 commit comments

Comments
 (0)