The issue where an encrypted password works in one login flow but not another is typically due to encryption context mismatches or incorrect decryption handling. Here’s how to resolve it:
1. Verify Encryption Scope
Katalon’s encryption is project-specific. If you’re reusing the same encrypted password across different projects or environments:
- Re-encrypt the password in the target environment using:
groovy
import com.kms.katalon.core.util.KeywordUtil
String encrypted = KeywordUtil.encrypt("your_password")
println encrypted // Use this in the problematic test case
2. Use Explicit Decryption
When the encrypted password isn’t auto-decrypted (e.g., in dynamic inputs):
groovy
import com.kms.katalon.core.util.KeywordUtil
String password = KeywordUtil.decrypt(GlobalVariable.encryptedPassword)
WebUI.setText(findTestObject('SecondLogin/PasswordField'), password)
3. Check Profile-Specific Encryption
If using execution profiles, ensure the encrypted password is stored in the correct profile:
- Go to Profiles > Your Profile.
- Confirm the password variable is encrypted under that profile.
4. Handle Dynamic XPath/Test Objects Properly
For dynamically located password fields, ensure the encryption isn’t broken by string interpolation:
groovy
// ❌ Wrong: Breaks encryption
String dynamicField = "input[@id='${passwordFieldId}']"
WebUI.setEncryptedText(dynamicField, GlobalVariable.encryptedPassword)
// ✅ Correct: Decrypt first
String password = KeywordUtil.decrypt(GlobalVariable.encryptedPassword)
WebUI.setText(findTestObject(dynamicField), password)
5. Debug Encryption Validity
Check if the encrypted value is corrupt:
groovy
try {
String decrypted = KeywordUtil.decrypt(GlobalVariable.encryptedPassword)
println "Decrypted: $decrypted" // Should match original password
} catch (Exception e) {
println "Encryption invalid: ${e.getMessage()}"
}
6. Re-encrypt with Latest Key
Rotate encryption keys if the project was copied/migrated:
- Delete the old encrypted value.
- Re-encrypt via 右键点击变量 > Encrypt.
Common Fixes
Scenario |
Solution |
Different Projects |
Re-encrypt in the target project. |
Manual Input |
Use KeywordUtil.decrypt() explicitly. |
Corrupted Encryption |
Re-encrypt and update all references. |
Example Workflow for Second Login:
groovy
// Decrypt manually
String password = KeywordUtil.decrypt(GlobalVariable.encryptedPassword)
// Use decrypted password
WebUI.setText(findTestObject('SecondLogin/PasswordField'), password)