Skip to content

Commit 4b40471

Browse files
committed
Add comprehensive tests for waitForText timeout behavior
1 parent 404e1e4 commit 4b40471

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/helper/Playwright_test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,40 @@ describe('Playwright', function () {
800800
assert.ok(error.message.includes('was not found on page after'), `Expected error message about text not found, got: ${error.message}`)
801801
}
802802
})
803+
804+
it('should return quickly when text is found', async function () {
805+
this.timeout(5000)
806+
807+
const startTime = Date.now()
808+
809+
await I.amOnPage('/')
810+
await I.waitForText('TestEd', 10) // This text should exist on the test page
811+
812+
const elapsedTime = Date.now() - startTime
813+
// Should find text quickly, within 2 seconds
814+
assert.ok(elapsedTime < 2000, `Expected to find text quickly but took ${elapsedTime}ms`)
815+
})
816+
817+
it('should work correctly with context parameter and proper timeout', async function () {
818+
this.timeout(8000)
819+
820+
const startTime = Date.now()
821+
const timeoutSeconds = 2
822+
823+
try {
824+
await I.amOnPage('/')
825+
await I.waitForText('NonExistentTextInBody', timeoutSeconds, 'body')
826+
throw new Error('Should have thrown timeout error')
827+
} catch (error) {
828+
const elapsedTime = Date.now() - startTime
829+
const expectedTimeout = timeoutSeconds * 1000
830+
831+
// Verify proper timeout behavior with context
832+
assert.ok(elapsedTime >= expectedTimeout - 500, `Expected to wait at least ${expectedTimeout - 500}ms, but waited ${elapsedTime}ms`)
833+
assert.ok(elapsedTime <= expectedTimeout + 1000, `Expected to wait at most ${expectedTimeout + 1000}ms, but waited ${elapsedTime}ms`)
834+
assert.ok(error.message.includes('was not found on page after'), `Expected timeout error message, got: ${error.message}`)
835+
}
836+
})
803837
})
804838

805839
describe('#grabHTMLFrom', () => {

0 commit comments

Comments
 (0)