How to get a value from a promise and store it in a variable for further use.
I am expecting my method to return a passoword as string rather than a resolved promise object. I need passoword string so that I can pass it to httpAuth function given below. httpAuth() is from TestCafe automation framework
Test.js code:
let mypass=Utils.returnPwd(); //I am using returnPwd() from Utils.js file that's returning a password.
fixture`Automated Test1`
.meta('fixturepack', 'regression')
.page("http://intranetURL")
.beforeEach(async t => {
DriverManager.setDriver(t);
await DriverManager.maximize();
})
.httpAuth({
username: 'loginuser1',
password: mypass
})
Utils.js code:
async base64Decoding(encodedPassword) {
var decodedData = Buffer.from(encodedPassword, 'base64').toString('ascii');
var decodedPassword = decodedData.toString()
console.log(decodedPassword);
return decodedPassword;
}
async returnPwd(){
let mypass2= this.base64Decoding('A2dIOEhBfXYvfSNba');
return mypass2.then(function(){ })
}
Current error: credentials.password is expected to be a string, but it was object.
.httpAuth({ username: 'loginuser1', password: mypass })