'How to get forget password link using cypress-gmail-tester
I am able to check Gmail is sent to the user, but I want to get forget password link from the received email and visit it using cypress-Gmail-tester. I am working on an ongoing project and whenever a gmail-tester is implemented it will work as per the below code.
it('forget password', () => {
const startStr = 'x3IhzZ5YUFU3xRWkCJI4aLVPC-2BOoHahfDU-2BROGlySass0TTVgllosmDa-2FaVEbjjZN-2FuCMhKKtmBUzbdxwO9z-2F'
const endStr = '-3D'
cy.visit('https://app.dev.##########.co/');
cy.get('.login__forgotpass').click();
cy.get('.forgot-pass__input').clear();
cy.get('.forgot-pass__input').type('##########[email protected]')
cy.get('.forgot-pass__btn').click();
cy.get('.popUp__note').contains('Check');
cy.get('.notification-dismiss').click();
cy.task("gmail:get-messages", {
options: {
from: "info@########.co",
subject: "Reset your ######## account password",
include_body: true,
// before: new Date(2021, 9, 24, 12, 31, 13), // Before September 24rd, 2019 12:31:13
// after: new Date(2021, 7, 23) // After August 23, 2019
}
}).then(emails => {
assert.isAtLeast(
emails.length,
1,
"Expected to find at least one email, but none were found!"
);
const body = emails[0].body.html;
assert.isTrue(
body.indexOf(
"http://url3042.########.co/ls/click?upn=x3IhzZ5YUFU3xRWkCJI4aLVPC-2BOoHahfDU-2BROGlySass0TTVgllosmDa-2FaVEbjjZN-2FuCMhKKtmBUzbdxwO9z-2F"
) >= 0,
"Found reset link!"
);
var token = extractData(body, startStr, endStr);
cy.log(`http://url3042.#########.co/ls/click?upn=${token}-3D`)
cy.visit(`http://url3042.#########.co/ls/click?upn=${token}-3D`)
})
I have replaced ##########
to my project name because of some NDA
.
Now I have written the below code but it will show invalid token
when entering a new password and clicking on the button.
That means token it received from email.
cy.task("gmail:get-messages", {
options: {
from: "noreply@######.co",
subject: "Reset your ########## account password",
include_body: true,
}
}).then(emails => {
assert.isAtLeast(
emails.length,
1,
"Expected to find at least one email, but none were found!"
);
const body = emails[0].body.html;
assert.isTrue(
body.indexOf(
"token="
) >= 0,
"Found reset link!"
);
var token = extractData(body, startStr, endStr);
cy.log(`accept/reset-password?token=${token}-3D`)
cy.visit(`accept/reset-password?token=${token}-3D`)
cy.get(smokeTestPageSelector.signUpPassword).type(Cypress.env('password'))
cy.get(smokeTestPageSelector.confirmPasswordTextbox).type(Cypress.env('password'))
cy.get('.forgot-pass__btn').click()
cy.get(hubGroupPageSelector.popupNotes).should('have.text','Password successfully reset!')
But now it will not work because of many changes made to the project. I want to check my email and get the received link and then visit that link.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|