Behind the mask – SetValuePassword() to keep data secure
Superheroes wear a mask to protect family and friends. In test automation, we need to protect our sensitive data such as passwords. In this method, we take the extra step to be sure our passwords are not displayed in the console and report output by replacing most of the string with asterisks (Password" = "Pa****rd
). However, if the root cause of our issues is that a password expired, we might want to have a small clue. So, we need to mask just a part of our credentials:
function maskString(str: string): string { let maskedStr = ''; for (let charIndex = 0; charIndex < str.length; charIndex++) { if (charIndex > 1 && charIndex < str.length - 2) { maskedStr += '*'; } else { maskedStr += str[charIndex]; } ...