Skip to content

Commit a2c7465

Browse files
DavertMikclaude
andcommitted
feat: add context parameter to seeInField and dontSeeInField
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8db6ac4 commit a2c7465

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
Checks that value of input field or textarea doesn't equal to given value
22
Opposite to `seeInField`.
33

4+
The third parameter is an optional context (CSS or XPath locator) to narrow the search.
5+
46
```js
57
I.dontSeeInField('email', 'user@user.com'); // field by name
68
I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
9+
// within a context
10+
I.dontSeeInField('Name', 'old_value', '.form-container');
711
```
812

913
@param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
1014
@param {CodeceptJS.StringOrSecret} value value to check.
15+
@param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS | XPath | strict locator.
1116
@returns {void} automatically synchronized promise through #recorder

docs/webapi/seeInField.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
Checks that the given input field or textarea equals to given value.
22
For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
33

4+
The third parameter is an optional context (CSS or XPath locator) to narrow the search.
5+
46
```js
57
I.seeInField('Username', 'davert');
68
I.seeInField({css: 'form textarea'},'Type your comment here');
79
I.seeInField('form input[type=hidden]','hidden_value');
810
I.seeInField('#searchform input','Search');
11+
// within a context
12+
I.seeInField('Name', 'John', '.form-container');
913
```
1014
@param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
1115
@param {CodeceptJS.StringOrSecret} value value to check.
16+
@param {?CodeceptJS.LocatorOrString} [context=null] (optional, `null` by default) element located by CSS | XPath | strict locator.
1217
@returns {void} automatically synchronized promise through #recorder

lib/helper/Playwright.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,17 +2310,17 @@ class Playwright extends Helper {
23102310
/**
23112311
* {{> seeInField }}
23122312
*/
2313-
async seeInField(field, value) {
2313+
async seeInField(field, value, context = null) {
23142314
const _value = typeof value === 'boolean' ? value : value.toString()
2315-
return proceedSeeInField.call(this, 'assert', field, _value)
2315+
return proceedSeeInField.call(this, 'assert', field, _value, context)
23162316
}
23172317

23182318
/**
23192319
* {{> dontSeeInField }}
23202320
*/
2321-
async dontSeeInField(field, value) {
2321+
async dontSeeInField(field, value, context = null) {
23222322
const _value = typeof value === 'boolean' ? value : value.toString()
2323-
return proceedSeeInField.call(this, 'negate', field, _value)
2323+
return proceedSeeInField.call(this, 'negate', field, _value, context)
23242324
}
23252325

23262326
/**
@@ -4473,8 +4473,8 @@ async function proceedSelect(context, el, option) {
44734473
return this._waitForAction()
44744474
}
44754475

4476-
async function proceedSeeInField(assertType, field, value) {
4477-
const els = await findFields.call(this, field)
4476+
async function proceedSeeInField(assertType, field, value, context) {
4477+
const els = await findFields.call(this, field, context)
44784478
assertElementExists(els, field, 'Field')
44794479
const el = els[0]
44804480
const tag = await el.evaluate(e => e.tagName)

lib/helper/Puppeteer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,17 +1601,17 @@ class Puppeteer extends Helper {
16011601
/**
16021602
* {{> seeInField }}
16031603
*/
1604-
async seeInField(field, value) {
1604+
async seeInField(field, value, context = null) {
16051605
const _value = typeof value === 'boolean' ? value : value.toString()
1606-
return proceedSeeInField.call(this, 'assert', field, _value)
1606+
return proceedSeeInField.call(this, 'assert', field, _value, context)
16071607
}
16081608

16091609
/**
16101610
* {{> dontSeeInField }}
16111611
*/
1612-
async dontSeeInField(field, value) {
1612+
async dontSeeInField(field, value, context = null) {
16131613
const _value = typeof value === 'boolean' ? value : value.toString()
1614-
return proceedSeeInField.call(this, 'negate', field, _value)
1614+
return proceedSeeInField.call(this, 'negate', field, _value, context)
16151615
}
16161616

16171617
/**
@@ -3286,8 +3286,8 @@ async function proceedDragAndDrop(sourceLocator, destinationLocator) {
32863286
await this._waitForAction()
32873287
}
32883288

3289-
async function proceedSeeInField(assertType, field, value) {
3290-
const els = await findVisibleFields.call(this, field)
3289+
async function proceedSeeInField(assertType, field, value, context) {
3290+
const els = await findVisibleFields.call(this, field, context)
32913291
assertElementExists(els, field, 'Field')
32923292
const el = els[0]
32933293
const tag = await el.getProperty('tagName').then(el => el.jsonValue())

lib/helper/WebDriver.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,18 +1598,18 @@ class WebDriver extends Helper {
15981598
* {{> seeInField }}
15991599
*
16001600
*/
1601-
async seeInField(field, value) {
1601+
async seeInField(field, value, context = null) {
16021602
const _value = typeof value === 'boolean' ? value : value.toString()
1603-
return proceedSeeField.call(this, 'assert', field, _value)
1603+
return proceedSeeField.call(this, 'assert', field, _value, context)
16041604
}
16051605

16061606
/**
16071607
* {{> dontSeeInField }}
16081608
*
16091609
*/
1610-
async dontSeeInField(field, value) {
1610+
async dontSeeInField(field, value, context = null) {
16111611
const _value = typeof value === 'boolean' ? value : value.toString()
1612-
return proceedSeeField.call(this, 'negate', field, _value)
1612+
return proceedSeeField.call(this, 'negate', field, _value, context)
16131613
}
16141614

16151615
/**
@@ -3075,8 +3075,9 @@ async function findFields(locator, context = null) {
30753075
return await locateFn(locator.value) // by css or xpath
30763076
}
30773077

3078-
async function proceedSeeField(assertType, field, value) {
3079-
const res = await findFields.call(this, field)
3078+
async function proceedSeeField(assertType, field, value, context) {
3079+
const locateFn = prepareLocateFn.call(this, context)
3080+
const res = await findFields.call(this, field, locateFn)
30803081
assertElementExists(res, field, 'Field')
30813082
const elem = usingFirstElement(res)
30823083
const elemId = getElementId(elem)

test/helper/webapi.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,18 @@ export function tests() {
659659
const val1 = await I.executeScript(() => document.getElementById('file1').files.length)
660660
assert.equal(val1, 0, 'file1 should have no files')
661661
})
662+
663+
it('should see in field within context', async () => {
664+
await I.amOnPage('/form/context')
665+
await I.seeInField('Name', 'old2', '#area2')
666+
await I.seeInField('Name', 'old1', '#area1')
667+
})
668+
669+
it('should not see in field within context', async () => {
670+
await I.amOnPage('/form/context')
671+
await I.dontSeeInField('Name', 'old1', '#area2')
672+
await I.dontSeeInField('Name', 'old2', '#area1')
673+
})
662674
})
663675

664676
describe('#shadow DOM', () => {

0 commit comments

Comments
 (0)