Skip to content

feat: Within() with begin/end pattern#5481

Open
DavertMik wants to merge 4 commits into4.xfrom
feat/focus-on
Open

feat: Within() with begin/end pattern#5481
DavertMik wants to merge 4 commits into4.xfrom
feat/focus-on

Conversation

@DavertMik
Copy link
Contributor

Summary

  • Refactors within() into Within() with three calling patterns:
    • Begin/end: Within('.ctx') ... Within() — new, no callback needed
    • Auto-end previous: calling Within('.new') auto-ends any active context
    • Callback: Within('.ctx', () => { ... }) — existing behavior preserved
  • Lowercase within() kept as deprecated global alias with one-time console warning
  • Within must be imported: import { Within } from 'codeceptjs/effects' (no global registration)
  • switchTo() in Playwright, Puppeteer, and WebDriver auto-ends any active Within context
  • New WithinContext class in lib/step/within.js (modeled on Section)
  • Full documentation at docs/within.md with examples for iframes, page objects, await usage

Files changed

File Change
lib/step/within.js NEWWithinContext class + WithinStep
lib/effects.js Within with 3 signatures, deprecated within alias
lib/index.js Export Within
lib/helper/Playwright.js Auto-disable within in switchTo()
lib/helper/Puppeteer.js Auto-disable within in switchTo()
lib/helper/WebDriver.js Auto-disable within in switchTo()
docs/within.md NEW — full Within documentation
docs/effects.md Updated Within section
test/acceptance/within_test.js 4 new test scenarios

Test plan

  • All 15 existing + new within acceptance tests pass with Playwright
  • Deprecated within() shows one-time warning and still works
  • Begin/end pattern works with CSS selectors and iframes
  • Auto-end previous context works correctly
  • Callback pattern works with uppercase Within
  • Verify nested iframe tests still pass
  • Verify WebDriver/Puppeteer helpers (switchTo auto-disable)

🤖 Generated with Claude Code

DavertMik and others added 4 commits March 7, 2026 16:54
Add optional context parameter to remaining form-filling methods
(appendField, clearField, attachFile) across Playwright, Puppeteer,
and WebDriver helpers for consistency with fillField, selectOption,
checkOption, and uncheckOption which already support it.

This allows scoping element search to a specific DOM container:
  I.appendField('Name', 'jon', '.form-container')
  I.clearField('Name', '.form-container')
  I.attachFile('Avatar', 'data/avatar.jpg', '.form-container')

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…achFile

Add shared webapi tests verifying that context scoping works for
appendField, clearField, and attachFile. Extended the context.php
test page with pre-filled values and file inputs to support the tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…pers

Remove unused `options` parameter from Playwright's clearField. The
options were accepted but never passed to the underlying clear() call.
Now all helpers have consistent `clearField(locator, context)` signature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add Within() function with three signatures:
- Within(locator) to begin scoped context
- Within() to end current context
- Within(locator, fn) callback pattern (existing behavior)

Lowercase within() kept as deprecated alias with one-time warning.
switchTo() in helpers auto-ends any active Within context.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DavertMik DavertMik changed the base branch from 3.x to 4.x March 8, 2026 01:59
if (this.withinLocator) {
await this._withinEnd()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithinContext.endCurrent() ? to properly clear the context.

if (this.withinLocator) {
await this._withinEnd()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithinContext.endCurrent() ? to properly clear the context.

if (this.withinLocator) {
await this._withinEnd()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithinContext.endCurrent() ? to properly clear the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants