Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added secret support to append() and type() #3615

Merged
merged 1 commit into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ When executed it will be printed like this:
```
I fill field "password" "*****"
```
**Other Examples**
```js
I.fillField('password', secret('123456'));
I.append('password', secret('123456'));
I.type('password', secret('123456'));
```

For an object, which can be a payload to POST request, specify which fields should be masked:

Expand Down
2 changes: 2 additions & 0 deletions docs/webapi/appendField.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Field is located by name, label, CSS or XPath

```js
I.appendField('#myTextField', 'appended');
// typing secret
I.appendField('password', secret('123456'));
```
@param {CodeceptJS.LocatorOrString} field located by label|name|CSS|XPath|strict locator
@param {string} value text value to append.
Expand Down
3 changes: 3 additions & 0 deletions docs/webapi/type.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ I.type('4141555311111111', 100);

// passing in an array
I.type(['T', 'E', 'X', 'T']);

// passing a secret
I.type(secret('123456'));
```

@param {string|string[]} key or array of keys to type.
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/Nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ class Nightmare extends Helper {
async appendField(field, value) {
const el = await findField.call(this, field);
assertElementExists(el, field, 'Field');
return this.browser.enterText(el, value, false)
return this.browser.enterText(el, value.toString(), false)
.wait(this.options.waitForAction);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ class Playwright extends Helper {
*/
async type(keys, delay = null) {
if (!Array.isArray(keys)) {
keys = keys.toString();
keys = keys.split('');
}

Expand Down Expand Up @@ -1482,7 +1483,7 @@ class Playwright extends Helper {
const els = await findFields.call(this, field);
assertElementExists(els, field, 'Field');
await els[0].press('End');
await els[0].type(value, { delay: this.options.pressKeyDelay });
await els[0].type(value.toString(), { delay: this.options.pressKeyDelay });
return this._waitForAction();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/helper/Protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ class Protractor extends Helper {
async appendField(field, value) {
const els = await findFields(this.browser, field);
assertElementExists(els, field, 'Field');
return els[0].sendKeys(value);
return els[0].sendKeys(value.toString());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ class Puppeteer extends Helper {
*/
async type(keys, delay = null) {
if (!Array.isArray(keys)) {
keys = keys.toString();
keys = keys.split('');
}

Expand Down Expand Up @@ -1306,7 +1307,7 @@ class Puppeteer extends Helper {
const els = await findVisibleFields.call(this, field);
assertElementExists(els, field, 'Field');
await els[0].press('End');
await els[0].type(value, { delay: this.options.pressKeyDelay });
await els[0].type(value.toString(), { delay: this.options.pressKeyDelay });
return this._waitForAction();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/helper/TestCafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class TestCafe extends Helper {
const el = await els.nth(0);

return this.t
.typeText(el, value, { replace: false })
.typeText(el, value.toString(), { replace: false })
.catch(mapError);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ class WebDriver extends Helper {
const res = await findFields.call(this, field);
assertElementExists(res, field, 'Field');
const elem = usingFirstElement(res);
return elem.addValue(value);
return elem.addValue(value.toString());
}

/**
Expand Down Expand Up @@ -1879,6 +1879,7 @@ class WebDriver extends Helper {
*/
async type(keys, delay = null) {
if (!Array.isArray(keys)) {
keys = keys.toString();
keys = keys.split('');
}
if (delay) {
Expand Down