Skip to content

Commit

Permalink
fix: support secret value for some methods (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Aug 26, 2023
1 parent a320bb1 commit 39382f5
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docs/helpers/Appium.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][5] \| [object][10])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][5]** value to check.
- `value` **([string][5] \| [object][10])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSee
Expand Down Expand Up @@ -1171,7 +1171,7 @@ I.seeInField('#searchform input','Search');
#### Parameters

- `field` **([string][5] \| [object][10])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][5]** value to check.
- `value` **([string][5] \| [object][10])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### see
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/Nightmare.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][3]** value to check.
- `value` **([string][3] | [object][4])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSeeInSource
Expand Down Expand Up @@ -956,7 +956,7 @@ I.seeInField('#searchform input','Search');
#### Parameters
- `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][3]** value to check.
- `value` **([string][3] | [object][4])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder
### seeInSource
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/Playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][8] | [object][5])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][8]** value to check.
- `value` **([string][8] | [object][5])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSeeInSource
Expand Down Expand Up @@ -1835,7 +1835,7 @@ I.seeInField('#searchform input','Search');
#### Parameters

- `field` **([string][8] | [object][5])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][8]** value to check.
- `value` **([string][8] | [object][5])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### seeInPopup
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/Protractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][9] | [object][10])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][9]** value to check.
- `value` **([string][9] | [object][10])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSeeInSource
Expand Down Expand Up @@ -1225,7 +1225,7 @@ I.seeInField('#searchform input','Search');
#### Parameters
- `field` **([string][9] | [object][10])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][9]** value to check.
- `value` **([string][9] | [object][10])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder
### seeInPopup
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][6]** value to check.
- `value` **([string][6] | [object][4])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSeeInSource
Expand Down Expand Up @@ -1618,7 +1618,7 @@ I.seeInField('#searchform input','Search');
#### Parameters
- `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][6]** value to check.
- `value` **([string][6] | [object][4])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder
### seeInPopup
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/TestCafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][4] | [object][5])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][4]** value to check.
- `value` **([string][4] | [object][5])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSeeInSource
Expand Down Expand Up @@ -926,7 +926,7 @@ I.seeInField('#searchform input','Search');
#### Parameters

- `field` **([string][4] | [object][5])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][4]** value to check.
- `value` **([string][4] | [object][5])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### seeInSource
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/WebDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
#### Parameters

- `field` **([string][17] | [object][16])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][17]** value to check.
- `value` **([string][17] | [object][16])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder

### dontSeeInSource
Expand Down Expand Up @@ -1783,7 +1783,7 @@ I.seeInField('#searchform input','Search');
#### Parameters
- `field` **([string][17] | [object][16])** located by label|name|CSS|XPath|strict locator.
- `value` **[string][17]** value to check.
- `value` **([string][17] | [object][16])** value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder
### seeInPopup
Expand Down
2 changes: 1 addition & 1 deletion docs/webapi/dontSeeInField.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
```

@param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
@param {string} value value to check.
@param {CodeceptJS.StringOrSecret} value value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder
2 changes: 1 addition & 1 deletion docs/webapi/seeInField.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ I.seeInField('form input[type=hidden]','hidden_value');
I.seeInField('#searchform input','Search');
```
@param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator.
@param {string} value value to check.
@param {CodeceptJS.StringOrSecret} value value to check.
⚠️ returns a _promise_ which is synchronized internally by recorder
10 changes: 6 additions & 4 deletions lib/helper/Appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,9 @@ class Appium extends Webdriver {
*
*/
async dontSeeInField(field, value) {
if (this.isWeb) return super.dontSeeInField(field, value);
return super.dontSeeInField(parseLocator.call(this, field), value);
const _value = (typeof value === 'boolean') ? value : value.toString();
if (this.isWeb) return super.dontSeeInField(field, _value);
return super.dontSeeInField(parseLocator.call(this, field), _value);
}

/**
Expand Down Expand Up @@ -1565,8 +1566,9 @@ class Appium extends Webdriver {
*
*/
async seeInField(field, value) {
if (this.isWeb) return super.seeInField(field, value);
return super.seeInField(parseLocator.call(this, field), value);
const _value = (typeof value === 'boolean') ? value : value.toString();
if (this.isWeb) return super.seeInField(field, _value);
return super.seeInField(parseLocator.call(this, field), _value);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/helper/Nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,16 @@ class Nightmare extends Helper {
* {{> seeInField }}
*/
async seeInField(field, value) {
return proceedSeeInField.call(this, 'assert', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'assert', field, _value);
}

/**
* {{> dontSeeInField }}
*/
async dontSeeInField(field, value) {
return proceedSeeInField.call(this, 'negate', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'negate', field, _value);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -1633,14 +1633,16 @@ class Playwright extends Helper {
* {{> seeInField }}
*/
async seeInField(field, value) {
return proceedSeeInField.call(this, 'assert', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'assert', field, _value);
}

/**
* {{> dontSeeInField }}
*/
async dontSeeInField(field, value) {
return proceedSeeInField.call(this, 'negate', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'negate', field, _value);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/helper/Protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,16 @@ class Protractor extends Helper {
* {{> seeInField }}
*/
async seeInField(field, value) {
return proceedSeeInField.call(this, 'assert', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'assert', field, _value);
}

/**
* {{> dontSeeInField }}
*/
async dontSeeInField(field, value) {
return proceedSeeInField.call(this, 'negate', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'negate', field, _value);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,14 +1353,16 @@ class Puppeteer extends Helper {
* {{> seeInField }}
*/
async seeInField(field, value) {
return proceedSeeInField.call(this, 'assert', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'assert', field, _value);
}

/**
* {{> dontSeeInField }}
*/
async dontSeeInField(field, value) {
return proceedSeeInField.call(this, 'negate', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeInField.call(this, 'negate', field, _value);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/helper/TestCafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,27 +727,29 @@ class TestCafe extends Helper {
* {{> seeInField }}
*/
async seeInField(field, value) {
const _value = (typeof value === 'boolean') ? value : value.toString();
// const expectedValue = findElements.call(this, this.context, field).value;
const els = await findFields.call(this, field);
assertElementExists(els, field, 'Field');
const el = await els.nth(0);

return this.t
.expect(await el.value).eql(value)
.expect(await el.value).eql(_value)
.catch(mapError);
}

/**
* {{> dontSeeInField }}
*/
async dontSeeInField(field, value) {
const _value = (typeof value === 'boolean') ? value : value.toString();
// const expectedValue = findElements.call(this, this.context, field).value;
const els = await findFields.call(this, field);
assertElementExists(els, field, 'Field');
const el = await els.nth(0);

return this.t
.expect(el.value).notEql(value)
.expect(el.value).notEql(_value)
.catch(mapError);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,15 +1348,17 @@ class WebDriver extends Helper {
*
*/
async seeInField(field, value) {
return proceedSeeField.call(this, 'assert', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeField.call(this, 'assert', field, _value);
}

/**
* {{> dontSeeInField }}
*
*/
async dontSeeInField(field, value) {
return proceedSeeField.call(this, 'negate', field, value);
const _value = (typeof value === 'boolean') ? value : value.toString();
return proceedSeeField.call(this, 'negate', field, _value);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const AssertionFailedError = require('../../lib/assert/error');
const webApiTests = require('./webapi');
const FileSystem = require('../../lib/helper/FileSystem');
const { deleteDir } = require('../../lib/utils');
const Secret = require('../../lib/secret');
global.codeceptjs = require('../../lib');

let I;
Expand Down Expand Up @@ -414,6 +415,16 @@ describe('Playwright', function () {
await I.seeInField('checkbox[]', 'see test three');
});

it('should check values are the secret type in checkboxes', async () => {
await I.amOnPage('/form/field_values');
await I.dontSeeInField('checkbox[]', Secret.secret('not seen one'));
await I.seeInField('checkbox[]', Secret.secret('see test one'));
await I.dontSeeInField('checkbox[]', Secret.secret('not seen two'));
await I.seeInField('checkbox[]', Secret.secret('see test two'));
await I.dontSeeInField('checkbox[]', Secret.secret('not seen three'));
await I.seeInField('checkbox[]', Secret.secret('see test three'));
});

it('should check values with boolean', async () => {
await I.amOnPage('/form/field_values');
await I.seeInField('checkbox1', true);
Expand Down
11 changes: 11 additions & 0 deletions test/helper/Puppeteer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Puppeteer = require('../../lib/helper/Puppeteer');
const AssertionFailedError = require('../../lib/assert/error');
const webApiTests = require('./webapi');
const FileSystem = require('../../lib/helper/FileSystem');
const Secret = require('../../lib/secret');
global.codeceptjs = require('../../lib');

let I;
Expand Down Expand Up @@ -447,6 +448,16 @@ describe('Puppeteer', function () {
await I.seeInField('checkbox[]', 'see test three');
});

it('should check values are the secret type in checkboxes', async () => {
await I.amOnPage('/form/field_values');
await I.dontSeeInField('checkbox[]', Secret.secret('not seen one'));
await I.seeInField('checkbox[]', Secret.secret('see test one'));
await I.dontSeeInField('checkbox[]', Secret.secret('not seen two'));
await I.seeInField('checkbox[]', Secret.secret('see test two'));
await I.dontSeeInField('checkbox[]', Secret.secret('not seen three'));
await I.seeInField('checkbox[]', Secret.secret('see test three'));
});

it('should check values with boolean', async () => {
await I.amOnPage('/form/field_values');
await I.seeInField('checkbox1', true);
Expand Down
11 changes: 11 additions & 0 deletions test/helper/WebDriver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const TestHelper = require('../support/TestHelper');
const WebDriver = require('../../lib/helper/WebDriver');
const AssertionFailedError = require('../../lib/assert/error');
const webApiTests = require('./webapi');
const Secret = require('../../lib/secret');
global.codeceptjs = require('../../lib');

const siteUrl = TestHelper.siteUrl();
Expand Down Expand Up @@ -143,6 +144,16 @@ describe('WebDriver', function () {
await wd.seeInField('checkbox[]', 'see test three');
});

it('should check values are the secret type in checkboxes', async () => {
await wd.amOnPage('/form/field_values');
await wd.dontSeeInField('checkbox[]', Secret.secret('not seen one'));
await wd.seeInField('checkbox[]', Secret.secret('see test one'));
await wd.dontSeeInField('checkbox[]', Secret.secret('not seen two'));
await wd.seeInField('checkbox[]', Secret.secret('see test two'));
await wd.dontSeeInField('checkbox[]', Secret.secret('not seen three'));
await wd.seeInField('checkbox[]', Secret.secret('see test three'));
});

it('should check values with boolean', async () => {
await wd.amOnPage('/form/field_values');
await wd.seeInField('checkbox1', true);
Expand Down

0 comments on commit 39382f5

Please sign in to comment.