I need help wit my code. I'm trying to create test in playwright that will go on forgot password page, create new password and after that will try to log in with that new password, but I have issue with return value. Here is my code below and if someone knows how to fix it to work, it would be great.
async createNewPassword(email: string) {
const { faker } = await require("@faker-js/faker");
const password = faker.internet.password();
await this.forgot_password_email_field.fill(email);
const email_field = await this.forgot_password_email_field.inputValue();
await this.forgot_password_field.fill(password);
const new_password = await this.forgot_password_field.inputValue();
await this.forgot_password_confirm_field.fill(new_password);
await this.forgot_password_save_button.click();
console.log(new_password);
return new_password;
}
async loginNewPassword(email: string) {
let new_login_password = this.createNewPassword();
console.log(new_login_password);
await this.email_field.fill(email);
await this.password_field.fill(await new_login_password);
await this.login_button.click();
}
I don't know how to catch that new_password from "createNewPassword" function and to use it in "loginNewPassword" function.
I tried with this to catch up that return value, but no luck
let new_login_password = this.createNewPassword();
CodePudding user response:
In your loginNewPassword method, you are missing await
before this.createNewPassword()
.
async loginNewPassword(email: string) {
let new_login_password = await this.createNewPassword();
console.log(new_login_password);
await this.email_field.fill(email);
await this.password_field.fill(await new_login_password);
await this.login_button.click();
}
CodePudding user response:
you need to await value returned from it before continue to the next line of code