Skip to content

Commit

Permalink
Added secret support to append() and type() (#3615)
Browse files Browse the repository at this point in the history
Co-authored-by: Sharma, Anil <[email protected]>
  • Loading branch information
anils92 and anilwk committed May 28, 2023
1 parent 5a549b6 commit de8e0d4
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 6 deletions.
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 @@ -1439,6 +1439,7 @@ class Playwright extends Helper {
*/
async type(keys, delay = null) {
if (!Array.isArray(keys)) {
keys = keys.toString();
keys = keys.split('');
}

Expand Down Expand Up @@ -1483,7 +1484,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

0 comments on commit de8e0d4

Please sign in to comment.