paragraph
'), + } + const mockHelper = { constructor: { name: 'Puppeteer' } } + const webElement = new WebElement(mockElement, mockHelper) + + const html = await webElement.getInnerHTML() + expect(html).to.equal('paragraph
') + }) + }) + + describe('exists()', () => { + it('should work with Playwright helper', async () => { + const mockElement = { + evaluate: fn => Promise.resolve(true), + } + const mockHelper = { constructor: { name: 'Playwright' } } + const webElement = new WebElement(mockElement, mockHelper) + + const exists = await webElement.exists() + expect(exists).to.equal(true) + }) + + it('should work with WebDriver helper', async () => { + const mockElement = {} + const mockHelper = { constructor: { name: 'WebDriver' } } + const webElement = new WebElement(mockElement, mockHelper) + + const exists = await webElement.exists() + expect(exists).to.equal(true) + }) + + it('should work with Puppeteer helper', async () => { + const mockElement = { + evaluate: fn => Promise.resolve(true), + } + const mockHelper = { constructor: { name: 'Puppeteer' } } + const webElement = new WebElement(mockElement, mockHelper) + + const exists = await webElement.exists() + expect(exists).to.equal(true) + }) + + it('should handle errors and return false', async () => { + const mockElement = { + evaluate: () => Promise.reject(new Error('Element not found')), + } + const mockHelper = { constructor: { name: 'Playwright' } } + const webElement = new WebElement(mockElement, mockHelper) + + const exists = await webElement.exists() + expect(exists).to.equal(false) + }) + }) +}) From 903e58883064a236cf2788b7d82dd5c0b5daf38f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+copilot@users.noreply.github.com> Date: 2025年8月22日 11:18:45 +0000 Subject: [PATCH 3/3] Fix helper tests to expect WebElement instances instead of native elements Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- test/helper/Playwright_test.js | 12 ++++++++---- test/helper/Puppeteer_test.js | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index f02e4a6ec..0e8432d5b 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -1707,7 +1707,8 @@ describe('Playwright - HAR', () => { await I.amOnPage('/form/focus_blur_elements') const webElements = await I.grabWebElements('#button') - assert.equal(webElements[0], "locator('#button').first()") + assert.equal(webElements[0].constructor.name, 'WebElement') + assert.equal(webElements[0].getNativeElement(), "locator('#button').first()") assert.isAbove(webElements.length, 0) }) @@ -1715,7 +1716,8 @@ describe('Playwright - HAR', () => { await I.amOnPage('/form/focus_blur_elements') const webElement = await I.grabWebElement('#button') - assert.equal(webElement, "locator('#button').first()") + assert.equal(webElement.constructor.name, 'WebElement') + assert.equal(webElement.getNativeElement(), "locator('#button').first()") }) }) }) @@ -1751,7 +1753,8 @@ describe('using data-testid attribute', () => { await I.amOnPage('/') const webElements = await I.grabWebElements({ pw: '[data-testid="welcome"]' }) - assert.equal(webElements[0]._selector, '[data-testid="welcome"]>> nth=0') + assert.equal(webElements[0].constructor.name, 'WebElement') + assert.equal(webElements[0].getNativeElement()._selector, '[data-testid="welcome"]>> nth=0') assert.equal(webElements.length, 1) }) @@ -1759,7 +1762,8 @@ describe('using data-testid attribute', () => { await I.amOnPage('/') const webElements = await I.grabWebElements('h1[data-testid="welcome"]') - assert.equal(webElements[0]._selector, 'h1[data-testid="welcome"]>> nth=0') + assert.equal(webElements[0].constructor.name, 'WebElement') + assert.equal(webElements[0].getNativeElement()._selector, 'h1[data-testid="welcome"]>> nth=0') assert.equal(webElements.length, 1) }) }) diff --git a/test/helper/Puppeteer_test.js b/test/helper/Puppeteer_test.js index 494b093cc..06ef40e05 100644 --- a/test/helper/Puppeteer_test.js +++ b/test/helper/Puppeteer_test.js @@ -1193,7 +1193,8 @@ describe('Puppeteer - Trace', () => { await I.amOnPage('/form/focus_blur_elements') const webElements = await I.grabWebElements('#button') - assert.include(webElements[0].constructor.name, 'CdpElementHandle') + assert.equal(webElements[0].constructor.name, 'WebElement') + assert.include(webElements[0].getNativeElement().constructor.name, 'CdpElementHandle') assert.isAbove(webElements.length, 0) }) })