refactor email step definitions

This commit is contained in:
mahula 2023-03-02 13:26:58 +01:00
parent 86286023fa
commit d66356c040
3 changed files with 30 additions and 55 deletions

View File

@ -13,8 +13,8 @@ Feature: User Authentication - reset password
And the user navigates to the forgot password page And the user navigates to the forgot password page
When the user enters the e-mail address "bibi@bloxberg.de" When the user enters the e-mail address "bibi@bloxberg.de"
And the user submits the e-mail form And the user submits the e-mail form
Then the user receives an e-mail containing the password reset link Then the user receives an e-mail containing the "password reset" link
When the user opens the password reset link in the browser When the user opens the "password reset" link in the browser
And the user enters the password "12345Aa_" And the user enters the password "12345Aa_"
And the user repeats the password "12345Aa_" And the user repeats the password "12345Aa_"
And the user submits the password form And the user submits the password form

View File

@ -7,8 +7,8 @@ Feature: User registration
When the user fills name and email "Regina" "Register" "regina@register.com" When the user fills name and email "Regina" "Register" "regina@register.com"
And the user agrees to the privacy policy And the user agrees to the privacy policy
And the user submits the registration form And the user submits the registration form
Then the user receives an e-mail containing the activation link Then the user receives an e-mail containing the "activation" link
When the user opens the activation link in the browser When the user opens the "activation" link in the browser
And the user enters the password "12345Aa_" And the user enters the password "12345Aa_"
And the user repeats the password "12345Aa_" And the user repeats the password "12345Aa_"
And the user submits the password form And the user submits the password form

View File

@ -5,57 +5,39 @@ import { UserEMailSite } from '../../e2e/models/UserEMailSite'
const userEMailSite = new UserEMailSite() const userEMailSite = new UserEMailSite()
const resetPasswordPage = new ResetPasswordPage() const resetPasswordPage = new ResetPasswordPage()
Then('the user receives an e-mail containing the password reset link', () => { Then('the user receives an e-mail containing the {string} link', (linkName: string) => {
let emailSubject: string
let linkPattern: RegExp
switch (linkName) {
case 'activation':
emailSubject = 'Email Verification'
linkPattern = /\/checkEmail\/[0-9]+\d/
break
case 'password reset':
emailSubject = 'asswor'
linkPattern = /\/reset-password\/[0-9]+\d/
break
default:
throw new Error(`Error in "Then the user receives an e-mail containing the {string} link" step: incorrect linkname string "${linkName}"`)
}
cy.origin( cy.origin(
Cypress.env('mailserverURL'), Cypress.env('mailserverURL'),
{ args: userEMailSite }, { args: { emailSubject, linkPattern, userEMailSite } },
(userEMailSite) => { ({ emailSubject, linkPattern, userEMailSite }) => {
const linkPattern = /\/reset-password\/[0-9]+\d/
cy.visit('/') // navigate to user's e-mail site (on fake mail server) cy.visit('/') // navigate to user's e-mail site (on fake mail server)
cy.get(userEMailSite.emailInbox).should('be.visible') cy.get(userEMailSite.emailInbox).should('be.visible')
cy.get(userEMailSite.emailList) cy.get(userEMailSite.emailList)
.find('.email-item') .find('.email-item')
.filter(':contains(asswor)') .filter(`:contains(${emailSubject})`)
.first() .first()
.click() .click()
cy.get(userEMailSite.emailMeta) cy.get(userEMailSite.emailMeta)
.find(userEMailSite.emailSubject) .find(userEMailSite.emailSubject)
.contains('asswor') .contains(emailSubject)
cy.get('.email-content')
.find('.plain-text', { timeout: 2000 })
.contains(linkPattern)
.invoke('text')
.then((text) => {
const resetPasswordLink = text.match(linkPattern)[0]
cy.task('setResetPasswordLink', resetPasswordLink)
})
}
)
})
Then('the user receives an e-mail containing the activation link', () => {
cy.origin(
Cypress.env('mailserverURL'),
{ args: userEMailSite },
(userEMailSite) => {
const linkPattern = /\/checkEmail\/[0-9]+\d/
cy.visit('/') // navigate to user's e-mail site (on fake mail server)
cy.get(userEMailSite.emailInbox).should('be.visible')
cy.get(userEMailSite.emailList)
.find('.email-item')
.filter(':contains(E-Mail Überprüfung)')
.first()
.click()
cy.get(userEMailSite.emailMeta)
.find(userEMailSite.emailSubject)
.contains('E-Mail Überprüfung')
cy.get('.email-content') cy.get('.email-content')
.wait(2000) .wait(2000)
@ -63,23 +45,16 @@ Then('the user receives an e-mail containing the activation link', () => {
.contains(linkPattern) .contains(linkPattern)
.invoke('text') .invoke('text')
.then((text) => { .then((text) => {
const activationLink = text.match(linkPattern)[0] const emailLink = text.match(linkPattern)[0]
cy.task('setActivationLink', activationLink) cy.task('setEmailLink', emailLink)
}) })
} }
) )
}) })
When('the user opens the password reset link in the browser', () => { When('the user opens the {string} link in the browser', (linkName: string) => {
cy.task('getResetPasswordLink').then((passwordResetLink) => { cy.task('getEmailLink').then((emailLink) => {
cy.visit(passwordResetLink) cy.visit(emailLink)
})
cy.get(resetPasswordPage.newPasswordInput).should('be.visible')
})
When('the user opens the activation link in the browser', () => {
cy.task('getActivationLink').then((activationLink) => {
cy.visit(activationLink)
}) })
cy.get(resetPasswordPage.newPasswordInput).should('be.visible') cy.get(resetPasswordPage.newPasswordInput).should('be.visible')
}) })